/* This file was generated by the Hex-Rays decompiler version 8.3.0.230608.
   Copyright (c) 2007-2021 Hex-Rays <info@hex-rays.com>

   Detected compiler: GNU C++
*/

#include <defs.h>


//-------------------------------------------------------------------------
// Function declarations

void (*init_proc())(void);
int sub_80483D0();
// ssize_t read(int fd, void *buf, size_t nbytes);
// int printf(const char *format, ...);
// __gid_t getegid(void);
// int puts(const char *s);
// int system(const char *command);
// int __gmon_start__(void); weak
// int __cdecl __libc_start_main(int (__cdecl *main)(int, char **, char **), int argc, char **ubp_av, void (*init)(void), void (*fini)(void), void (*rtld_fini)(void), void *stack_end);
// int __cdecl setresgid(_DWORD, _DWORD, _DWORD); weak
// void __usercall __noreturn start(int a1@<eax>, void (*a2)(void)@<edx>);
void _do_global_dtors_aux();
int frame_dummy();
int be_nice_to_people();
int __cdecl main(int argc, const char **argv, const char **envp);
void _libc_csu_fini(void); // idb
void (*_do_global_ctors_aux())(void);
void term_proc();

//-------------------------------------------------------------------------
// Data declarations

_UNKNOWN _libc_csu_init;
int _CTOR_LIST__[] = { -1 }; // weak
int _DTOR_LIST__[] = { -1 }; // weak
int _DTOR_END__ = 0; // weak
int _JCR_LIST__ = 0; // weak
Elf32_Dyn *GLOBAL_OFFSET_TABLE_ = &DYNAMIC; // weak
int (*dword_8049FFC)(void) = NULL; // weak
int x = 3; // weak
char completed_6159; // weak
int dtor_idx_6161; // weak
// extern _UNKNOWN _gmon_start__; weak


//----- (0804839C) --------------------------------------------------------
void (*init_proc())(void)
{
  if ( &_gmon_start__ )
    __gmon_start__();
  frame_dummy();
  return _do_global_ctors_aux();
}
// 8048440: using guessed type int __gmon_start__(void);

//----- (080483D0) --------------------------------------------------------
int sub_80483D0()
{
  return dword_8049FFC();
}
// 8049FFC: using guessed type int (*dword_8049FFC)(void);

//----- (08048470) --------------------------------------------------------
// positive sp value has been detected, the output may be wrong!
void __usercall __noreturn start(int a1@<eax>, void (*a2)(void)@<edx>)
{
  int v2; // esi
  int v3; // [esp-4h] [ebp-4h] BYREF
  char *retaddr; // [esp+0h] [ebp+0h] BYREF

  v2 = v3;
  v3 = a1;
  __libc_start_main(
    (int (__cdecl *)(int, char **, char **))main,
    v2,
    &retaddr,
    (void (*)(void))_libc_csu_init,
    _libc_csu_fini,
    a2,
    &v3);
  __halt();
}
// 8048473: positive sp value 4 has been found

//----- (080484A0) --------------------------------------------------------
void _do_global_dtors_aux()
{
  int v0; // eax
  unsigned int i; // ebx

  if ( !completed_6159 )
  {
    v0 = dtor_idx_6161;
    for ( i = &_DTOR_END__ - _DTOR_LIST__ - 1; dtor_idx_6161 < i; v0 = dtor_idx_6161 )
    {
      dtor_idx_6161 = v0 + 1;
      ((void (*)(void))_DTOR_LIST__[v0 + 1])();
    }
    completed_6159 = 1;
  }
}
// 8049F1C: using guessed type int _DTOR_LIST__[];
// 8049F20: using guessed type int _DTOR_END__;
// 804A030: using guessed type char completed_6159;
// 804A034: using guessed type int dtor_idx_6161;

//----- (08048500) --------------------------------------------------------
int frame_dummy()
{
  int result; // eax

  result = _JCR_LIST__;
  if ( _JCR_LIST__ )
    return 0;
  return result;
}
// 8049F24: using guessed type int _JCR_LIST__;

//----- (08048524) --------------------------------------------------------
int be_nice_to_people()
{
  __gid_t v1; // [esp+1Ch] [ebp-Ch]

  v1 = getegid();
  return setresgid(v1, v1, v1);
}
// 8048460: using guessed type int __cdecl setresgid(_DWORD, _DWORD, _DWORD);

//----- (0804854D) --------------------------------------------------------
int __cdecl main(int argc, const char **argv, const char **envp)
{
  char buf[80]; // [esp+2Ch] [ebp-5Ch] BYREF
  unsigned int v5; // [esp+7Ch] [ebp-Ch]

  v5 = __readgsdword(0x14u);
  be_nice_to_people();
  memset(buf, 0, sizeof(buf));
  read(0, buf, 0x50u);
  printf(buf);
  printf("%d!\n", x);
  if ( x == 4 )
  {
    puts("running sh...");
    system("/bin/sh");
  }
  return 0;
}
// 8048524: using guessed type int be_nice_to_people(void);
// 804A02C: using guessed type int x;

//----- (08048610) --------------------------------------------------------
void __cdecl _libc_csu_init(int a1, int a2, int a3)
{
  int v3; // edi
  int i; // esi

  init_proc();
  v3 = (134520820 - (int)&GLOBAL_OFFSET_TABLE_) >> 2;
  if ( v3 )
  {
    for ( i = 0; i != v3; ++i )
      ((void (__cdecl *)(int, int, int))_CTOR_LIST__[i])(a1, a2, a3);
  }
}
// 8049F14: using guessed type int _CTOR_LIST__[];
// 8049FF4: using guessed type Elf32_Dyn *GLOBAL_OFFSET_TABLE_;

//----- (08048690) --------------------------------------------------------
void (*_do_global_ctors_aux())(void)
{
  void (*result)(void); // eax
  void (**v1)(void); // ebx

  result = (void (*)(void))_CTOR_LIST__;
  if ( _CTOR_LIST__ != -1 )
  {
    v1 = (void (**)(void))&_CTOR_LIST__;
    do
    {
      --v1;
      result();
      result = *v1;
    }
    while ( *v1 != (void (*)(void))-1 );
  }
  return result;
}
// 8049F14: using guessed type int _CTOR_LIST__;

//----- (080486BC) --------------------------------------------------------
void term_proc()
{
  _do_global_dtors_aux();
}

// nfuncs=30 queued=10 decompiled=10 lumina nreq=0 worse=0 better=0
// ALL OK, 10 function(s) have been successfully decompiled
