/* 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

__int64 (**init_proc())(void);
__int64 sub_401020(void); // weak
__int64 sub_401030(); // weak
__int64 sub_401040(); // weak
__int64 sub_401050(); // weak
__int64 sub_401060(); // weak
// int puts(const char *s);
// void setbuf(FILE *stream, char *buf);
// int system(const char *command);
// ssize_t read(int fd, void *buf, size_t nbytes);
void __fastcall __noreturn start(__int64 a1, __int64 a2, void (*a3)(void));
void dl_relocate_static_pie();
void *deregister_tm_clones();
__int64 register_tm_clones(void); // weak
void *_do_global_dtors_aux();
__int64 frame_dummy(); // weak
__int64 __fastcall write_str(char a1, char a2, char a3, char a4, char a5, unsigned int a6);
int __fastcall shell(const char *a1);
void initial();
void gadgets();
int __fastcall main(int argc, const char **argv, const char **envp);
void term_proc();
// int __fastcall _libc_start_main(int (__fastcall *main)(int, char **, char **), int argc, char **ubp_av, void (*init)(void), void (*fini)(void), void (*rtld_fini)(void), void *stack_end);
// __int64 _gmon_start__(void); weak

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

__int64 (*qword_404010)(void) = NULL; // weak
_UNKNOWN _bss_start; // weak
FILE *stdout; // idb
FILE *stdin; // idb
FILE *stderr; // idb
char completed_0; // weak
char str; // weak
char byte_404091; // weak
char byte_404092; // weak
char byte_404093; // weak
char byte_404094; // weak
char byte_404095; // weak


//----- (0000000000401000) ----------------------------------------------------
__int64 (**init_proc())(void)
{
  __int64 (**result)(void); // rax

  result = &_gmon_start__;
  if ( &_gmon_start__ )
    return (__int64 (**)(void))_gmon_start__();
  return result;
}
// 4040D0: using guessed type __int64 _gmon_start__(void);

//----- (0000000000401020) ----------------------------------------------------
__int64 sub_401020()
{
  return qword_404010();
}
// 401020: using guessed type __int64 sub_401020();
// 404010: using guessed type __int64 (*qword_404010)(void);

//----- (0000000000401030) ----------------------------------------------------
__int64 sub_401030()
{
  return sub_401020();
}
// 401020: using guessed type __int64 sub_401020(void);
// 401030: using guessed type __int64 sub_401030();

//----- (0000000000401040) ----------------------------------------------------
__int64 sub_401040()
{
  return sub_401020();
}
// 401020: using guessed type __int64 sub_401020(void);
// 401040: using guessed type __int64 sub_401040();

//----- (0000000000401050) ----------------------------------------------------
__int64 sub_401050()
{
  return sub_401020();
}
// 401020: using guessed type __int64 sub_401020(void);
// 401050: using guessed type __int64 sub_401050();

//----- (0000000000401060) ----------------------------------------------------
__int64 sub_401060()
{
  return sub_401020();
}
// 401020: using guessed type __int64 sub_401020(void);
// 401060: using guessed type __int64 sub_401060();

//----- (00000000004010B0) ----------------------------------------------------
// positive sp value has been detected, the output may be wrong!
void __fastcall __noreturn start(__int64 a1, __int64 a2, void (*a3)(void))
{
  __int64 v3; // rax
  int v4; // esi
  __int64 v5; // [rsp-8h] [rbp-8h] BYREF
  char *retaddr; // [rsp+0h] [rbp+0h] BYREF

  v4 = v5;
  v5 = v3;
  _libc_start_main((int (__fastcall *)(int, char **, char **))main, v4, &retaddr, 0LL, 0LL, a3, &v5);
  __halt();
}
// 4010BA: positive sp value 8 has been found
// 4010C1: variable 'v3' is possibly undefined

//----- (00000000004010E0) ----------------------------------------------------
void dl_relocate_static_pie()
{
  ;
}

//----- (00000000004010F0) ----------------------------------------------------
void *deregister_tm_clones()
{
  return &_bss_start;
}

//----- (0000000000401120) ----------------------------------------------------
__int64 register_tm_clones()
{
  return 0LL;
}
// 401120: using guessed type __int64 register_tm_clones();

//----- (0000000000401160) ----------------------------------------------------
void *_do_global_dtors_aux()
{
  void *result; // rax

  if ( !completed_0 )
  {
    result = deregister_tm_clones();
    completed_0 = 1;
  }
  return result;
}
// 404088: using guessed type char completed_0;

//----- (0000000000401190) ----------------------------------------------------
__int64 frame_dummy()
{
  return register_tm_clones();
}
// 401120: using guessed type __int64 register_tm_clones(void);
// 401190: using guessed type __int64 frame_dummy();

//----- (0000000000401196) ----------------------------------------------------
__int64 __fastcall write_str(char a1, char a2, char a3, char a4, char a5, unsigned int a6)
{
  __int64 result; // rax

  str = a1;
  byte_404091 = a2;
  byte_404092 = a3;
  byte_404093 = a4;
  byte_404094 = a5;
  result = a6;
  byte_404095 = a6;
  return result;
}
// 404090: using guessed type char str;
// 404091: using guessed type char byte_404091;
// 404092: using guessed type char byte_404092;
// 404093: using guessed type char byte_404093;
// 404094: using guessed type char byte_404094;
// 404095: using guessed type char byte_404095;

//----- (00000000004011EB) ----------------------------------------------------
int __fastcall shell(const char *a1)
{
  return system(a1);
}

//----- (000000000040120A) ----------------------------------------------------
void initial()
{
  setbuf(stdin, 0LL);
  setbuf(stdout, 0LL);
  setbuf(stderr, 0LL);
}

//----- (0000000000401251) ----------------------------------------------------
void gadgets()
{
  ;
}

//----- (000000000040126D) ----------------------------------------------------
int __fastcall main(int argc, const char **argv, const char **envp)
{
  char buf[16]; // [rsp+10h] [rbp-10h] BYREF

  initial();
  puts("welcome to ROP");
  puts("input your name plz");
  read(0, buf, 0x200uLL);
  puts("bye!");
  return 0;
}
// 40126D: using guessed type char buf[16];

//----- (00000000004012D4) ----------------------------------------------------
void term_proc()
{
  ;
}

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