// File: /workspace/github_c_makefile_star2_O0/mabdi[P]bunney/bunny-exec.c
// Function: main
int main(int argc,char** argv) {

  _u8* t, keep_alive;
  _u32 run_cnt = 0;
  
  if (close(dup(99)) || argc == 1   ||
      !(t=getenv("BUNNY_MAXTIME"))  || sscanf(t,"%u",&time_limit) != 1 ||
      !(t=getenv("BUNNY_MAXSTUCK")) || sscanf(t,"%u",&stuck_limit) != 1 ||
      !(t=getenv("BUNNY_MAXFUNC"))  || sscanf(t,"%u",&func_limit) != 1)
    fatal("not a standalone program");

#ifdef DEBUG_TRACE
  setbuffer(stdout,0,0);
#endif /* DEBUG_TRACE */

  keep_alive = (getenv("BUNNY_KEEPALIVE") != 0);

  unsetenv("BUNNY_KEEPALIVE");
  unsetenv("BUNNY_MAXFUNC");
  unsetenv("BUNNY_MAXTIME");
  unsetenv("BUNNY_MAXSTUCK");

#ifdef DEBUG_TRACE
  printf("[bunny-exec] Starting up (keepalive=%u).\n", keep_alive);
#endif /* DEBUG_TRACE */

  prepare_shm();

#ifdef DEBUG_TRACE
  printf("[bunny-exec] SHM setup complete.\n");
#endif /* DEBUG_TRACE */

  do {

    gettimeofday(&start_time,0);
    memcpy(&last_time,&start_time,sizeof(struct timeval));
  
    setup_signals();

#ifdef DEBUG_TRACE
    printf("[bunny-exec] Launching '%s'...\n",argv[1]);
#endif /* DEBUG_TRACE */

    handle_process(argv[1],(_u8**)argv+1);

    disable_timers();

    if (!((++run_cnt) % TRUNC_FREQ)) {
      /* Every TRUNC_FREQ execs, truncate stdin/stdout if possible, ignore errors. */
      lseek(1,0,SEEK_SET);
      lseek(2,0,SEEK_SET);
      ftruncate(1,0);
      ftruncate(2,0);
    }

  } while (keep_alive && reset_wait_keepalive());

  fclose(outfile);

  shmctl(shmid, IPC_RMID, 0);  

#ifdef DEBUG_TRACE
  printf("[bunny-exec] Shutdown OK.\n");
#endif /* DEBUG_TRACE */


  exit(0);
  
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x63, %edi
callq 0x11f0
movl %eax, %edi
callq 0x1250
cmpl $0x0, %eax
jne 0x1441
cmpl $0x1, -0x8(%rbp)
je 0x1441
leaq 0x2c5c(%rip), %rdi      # 0x4004
callq 0x1140
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x1441
movq -0x18(%rbp), %rdi
leaq 0x2f44(%rip), %rsi      # 0x430a
leaq 0x4d7b(%rip), %rdx      # 0x6148
movb $0x0, %al
callq 0x10e0
cmpl $0x1, %eax
jne 0x1441
leaq 0x2c32(%rip), %rdi      # 0x4012
callq 0x1140
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x1441
movq -0x18(%rbp), %rdi
leaq 0x2f10(%rip), %rsi      # 0x430a
leaq 0x4d4b(%rip), %rdx      # 0x614c
movb $0x0, %al
callq 0x10e0
cmpl $0x1, %eax
jne 0x1441
leaq 0x2c0d(%rip), %rdi      # 0x4021
callq 0x1140
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x1441
movq -0x18(%rbp), %rdi
leaq 0x2edc(%rip), %rsi      # 0x430a
leaq 0x4d1b(%rip), %rdx      # 0x6150
movb $0x0, %al
callq 0x10e0
cmpl $0x1, %eax
je 0x1491
jmp 0x1443
movq 0x4b96(%rip), %rax      # 0x5fe0
movq (%rax), %rdi
leaq 0x2bdb(%rip), %rsi      # 0x402f
movb $0x0, %al
callq 0x11b0
movq 0x4b7e(%rip), %rax      # 0x5fe0
movq (%rax), %rdi
leaq 0x2bf3(%rip), %rsi      # 0x405f
leaq 0x2bfc(%rip), %rdx      # 0x406f
leaq 0x2bfa(%rip), %rcx      # 0x4074
movl $0x277, %r8d            # imm = 0x277
movb $0x0, %al
callq 0x11b0
movl $0x1, %edi
callq 0x1130
leaq 0x2be9(%rip), %rdi      # 0x4081
callq 0x1140
cmpq $0x0, %rax
setne %al
andb $0x1, %al
movzbl %al, %eax
movb %al, -0x19(%rbp)
leaq 0x2bce(%rip), %rdi      # 0x4081
callq 0x1160
leaq 0x2b62(%rip), %rdi      # 0x4021
callq 0x1160
leaq 0x2b39(%rip), %rdi      # 0x4004
callq 0x1160
leaq 0x2b3b(%rip), %rdi      # 0x4012
callq 0x1160
callq 0x15d0
leaq 0x4c70(%rip), %rdi      # 0x6158
xorl %eax, %eax
movl %eax, %esi
callq 0x1200
movq 0x4c60(%rip), %rax      # 0x6158
movq %rax, 0x4c69(%rip)      # 0x6168
movq 0x4c5a(%rip), %rax      # 0x6160
movq %rax, 0x4c63(%rip)      # 0x6170
callq 0x17f0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
callq 0x1890
callq 0x1b10
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
cmpl $0x0, %edx
jne 0x157f
movl $0x1, %edi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1230
movl $0x2, %edi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1230
movl $0x1, %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x1170
movl $0x2, %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x1170
jmp 0x1581
movzbl -0x19(%rbp), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x21(%rbp)
je 0x15a0
callq 0x1b60
movzbl %al, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x21(%rbp)
movb -0x21(%rbp), %al
testb $0x1, %al
jne 0x14e1
movq 0x4bc6(%rip), %rdi      # 0x6178
callq 0x10f0
movl 0x4bc3(%rip), %edi      # 0x6180
xorl %esi, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x10c0
xorl %edi, %edi
callq 0x1130
nop