/* 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_4004D0(); // weak
// int puts(const char *s);
// int printf(const char *format, ...);
// ssize_t read(int fd, void *buf, size_t nbytes);
// int setvbuf(FILE *stream, char *buf, int modes, size_t n);
void __fastcall __noreturn start(__int64 a1, __int64 a2, void (*a3)(void));
FILE **deregister_tm_clones();
__int64 register_tm_clones(void); // weak
FILE **_do_global_dtors_aux();
__int64 __fastcall frame_dummy(_QWORD, _QWORD, _QWORD); // weak
int __fastcall main(int argc, const char **argv, const char **envp);
void _libc_csu_fini(void); // idb
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

_UNKNOWN _libc_csu_init;
__int64 (__fastcall *_frame_dummy_init_array_entry)() = &frame_dummy; // weak
__int64 (__fastcall *_do_global_dtors_aux_fini_array_entry)() = &_do_global_dtors_aux; // weak
__int64 (*qword_601010)(void) = NULL; // weak
FILE *_bss_start; // idb
char completed_7698; // weak


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

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

//----- (00000000004004D0) ----------------------------------------------------
__int64 sub_4004D0()
{
  return qword_601010();
}
// 4004D0: using guessed type __int64 sub_4004D0();
// 601010: using guessed type __int64 (*qword_601010)(void);

//----- (0000000000400520) ----------------------------------------------------
// 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,
    (void (*)(void))_libc_csu_init,
    _libc_csu_fini,
    a3,
    &v5);
  __halt();
}
// 400526: positive sp value 8 has been found
// 40052D: variable 'v3' is possibly undefined

//----- (0000000000400560) ----------------------------------------------------
FILE **deregister_tm_clones()
{
  return &_bss_start;
}

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

//----- (00000000004005D0) ----------------------------------------------------
FILE **_do_global_dtors_aux()
{
  FILE **result; // rax

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

//----- (0000000000400600) ----------------------------------------------------
__int64 frame_dummy()
{
  return register_tm_clones();
}
// 400590: using guessed type __int64 register_tm_clones(void);
// 400600: using guessed type __int64 frame_dummy();

//----- (0000000000400607) ----------------------------------------------------
int __fastcall main(int argc, const char **argv, const char **envp)
{
  __int64 buf[2]; // [rsp+0h] [rbp-10h] BYREF

  buf[0] = 0LL;
  buf[1] = 0LL;
  setvbuf(_bss_start, 0LL, 1, 0LL);
  puts("Welcome to CTFHub ret2shellcode!");
  printf("What is it : [%p] ?\n", buf);
  puts("Input someting : ");
  read(0, buf, 0x400uLL);
  return 0;
}

//----- (0000000000400690) ----------------------------------------------------
void __fastcall _libc_csu_init(unsigned int a1, __int64 a2, __int64 a3)
{
  signed __int64 v4; // rbp
  __int64 i; // rbx

  v4 = &_do_global_dtors_aux_fini_array_entry - &_frame_dummy_init_array_entry;
  init_proc();
  if ( v4 )
  {
    for ( i = 0LL; i != v4; ++i )
      ((void (__fastcall *)(_QWORD, __int64, __int64))*(&_frame_dummy_init_array_entry + i))(a1, a2, a3);
  }
}
// 400600: using guessed type __int64 __fastcall frame_dummy(_QWORD, _QWORD, _QWORD);
// 600E10: using guessed type __int64 (__fastcall *_frame_dummy_init_array_entry)();
// 600E18: using guessed type __int64 (__fastcall *_do_global_dtors_aux_fini_array_entry)();

//----- (0000000000400704) ----------------------------------------------------
void term_proc()
{
  ;
}

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