// File: /workspace/github_c_makefile_star2_O0/silverneko[P]miku/./src/testsuite.cpp
// Function: testsuite(submission&)
int testsuite(submission &sub)
{
   system("rm -f ./testzone/*");
   const int testBoxid = BOXOFFSET + 0, spBoxid = BOXOFFSET + 1;
   sandboxInit(testBoxid);
   sandboxInit(spBoxid);
   int status = compile(sub, testBoxid, spBoxid);
   if(status != OK) return status;
   
   //anyway, only have batch judge right now
   map<pid_t, int> proc;
   int procnum = 0;
   int problem_id = sub.problem_id;
   int* time_limit = sub.time_limit;
   int* mem_limit = sub.mem_limit;

   for(int i = 0; i < sub.testdata_count; ++i){
      while(procnum >= MAXPARNUM){
         int status;
         pid_t cid = waitpid(-1, &status, 0);
         if(cid == -1){
            perror("[ERROR] in testsuite,  `waitpid()` failed :");
            return ER;
         }
         int td = proc[cid];
         eval(sub, td, BOXOFFSET + 10 + td, spBoxid);
         if(AGGUPDATE){
            sendResult(sub, OK, false);
         }
         //cerr << "td" << td << " : " << sub.verdict[td] << endl;
         sandboxDele(BOXOFFSET + 10 + td);
         --procnum;
      }

      if(procnum < MAXPARNUM){
         //batch judge
         ostringstream command;
         command << "batchjudge " << problem_id;
         command << " " << i;
         command << " " << BOXOFFSET + 10 + i;
         command << " " << time_limit[i];
         if(sub.lang == "haskell")
           command << " " << mem_limit[i]*5 + 24*1024;
         else
           command << " " << mem_limit[i];
         command << " " << testBoxid;
         pid_t pid = fork();
         if(pid == -1){
            perror("[ERROR] in testsuite, `fork()` failed :");
            return ER;
         }
         if(pid == 0){
            //child proc
            execl("/bin/sh", "sh", "-c", command.str().c_str(), NULL);
            perror("[ERROR] in testsuite, `execl()` failed :");
            exit(0);
         }
         proc[pid] = i;
         ++procnum;
      }
   }
   while(procnum >= 1){
      int status;
      pid_t cid = waitpid(-1, &status, 0);
      if(cid == -1){
         perror("[ERROR] in testsuite,  `waitpid()` failed :");
         return ER;
      }
      const int td = proc[cid];
      //sub.verdict[td] = eval(problem_id, td);
      eval(sub, td, BOXOFFSET + 10 + td, spBoxid);
      if(AGGUPDATE){
         sendResult(sub, OK, false);
      }
      //cerr << "td" << td << " : " << sub.verdict[td] << endl;
      sandboxDele(BOXOFFSET + 10 + td);
      --procnum;
   }
   //clear box-10
   sandboxDele(testBoxid);
   sandboxDele(spBoxid);
   return OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2b0, %rsp            # imm = 0x2B0
movq %rdi, -0x10(%rbp)
leaq 0x93ea(%rip), %rdi      # 0xf410
callq 0x42f0
movl 0xf343(%rip), %eax      # 0x15374
addl $0x0, %eax
movl %eax, -0x14(%rbp)
movl 0xf337(%rip), %eax      # 0x15374
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %edi
callq 0x5b70
movl -0x18(%rbp), %edi
callq 0x5b70
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x65f0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x6076
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x65d8
leaq -0x50(%rbp), %rdi
callq 0x8d90
movl $0x0, -0x54(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x58(%rbp)
movq -0x10(%rbp), %rax
addq $0x414, %rax            # imm = 0x414
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
addq $0xf4, %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xf0(%rcx), %eax
jge 0x64b0
jmp 0x60c7
movl -0x54(%rbp), %eax
cmpl 0xf2a0(%rip), %eax      # 0x15370
jl 0x61bf
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
leaq -0x70(%rbp), %rsi
xorl %edx, %edx
callq 0x42a0
movl %eax, -0x240(%rbp)
jmp 0x60ee
movl -0x240(%rbp), %eax
movl %eax, -0x74(%rbp)
cmpl $-0x1, -0x74(%rbp)
jne 0x6135
leaq 0x931f(%rip), %rdi      # 0xf423
callq 0x42d0
jmp 0x610b
movl $0x13, -0x4(%rbp)
movl $0x1, -0x88(%rbp)
jmp 0x65c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x65cd
leaq -0x50(%rbp), %rdi
leaq -0x74(%rbp), %rsi
callq 0x8db0
movq %rax, -0x248(%rbp)
jmp 0x614b
movq -0x248(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x8c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x8c(%rbp), %esi
movl 0xf20a(%rip), %edx      # 0x15374
movl %esi, %ecx
movl %edx, %eax
leal 0xa(%rax,%rcx), %edx
movl -0x18(%rbp), %ecx
callq 0x71c0
jmp 0x617c
testb $0x1, 0xf1f9(%rip)      # 0x1537c
je 0x6196
movq -0x10(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xde00
jmp 0x6194
jmp 0x6196
movl 0xf1d8(%rip), %edx      # 0x15374
movl -0x8c(%rbp), %eax
movl %eax, %ecx
movl %edx, %eax
leal 0xa(%rax,%rcx), %edi
callq 0x5cf0
jmp 0x61b1
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x60c7
movl -0x54(%rbp), %eax
cmpl 0xf1a8(%rip), %eax      # 0x15370
jge 0x64a0
leaq -0x208(%rbp), %rdi
callq 0x4480
jmp 0x61dc
leaq 0x926c(%rip), %rsi      # 0xf44f
leaq -0x208(%rbp), %rdi
callq 0x4320
movq %rax, -0x250(%rbp)
jmp 0x61f8
movq -0x250(%rbp), %rdi
movl -0x58(%rbp), %esi
callq 0x45e0
jmp 0x6209
leaq 0x917e(%rip), %rsi      # 0xf38e
leaq -0x208(%rbp), %rdi
callq 0x4320
movq %rax, -0x258(%rbp)
jmp 0x6225
movq -0x258(%rbp), %rdi
movl -0x6c(%rbp), %esi
callq 0x45e0
jmp 0x6236
leaq 0x9151(%rip), %rsi      # 0xf38e
leaq -0x208(%rbp), %rdi
callq 0x4320
movq %rax, -0x260(%rbp)
jmp 0x6252
movq -0x260(%rbp), %rdi
movl 0xf115(%rip), %edx      # 0x15374
movl -0x6c(%rbp), %eax
movl %eax, %ecx
movl %edx, %eax
leal 0xa(%rax,%rcx), %esi
callq 0x45e0
jmp 0x6271
leaq 0x9116(%rip), %rsi      # 0xf38e
leaq -0x208(%rbp), %rdi
callq 0x4320
movq %rax, -0x268(%rbp)
jmp 0x628d
movq -0x268(%rbp), %rdi
movq -0x60(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0x45e0
jmp 0x62a6
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
leaq 0x91a6(%rip), %rsi      # 0xf45b
callq 0x8e90
movb %al, -0x269(%rbp)
jmp 0x62c2
movb -0x269(%rbp), %al
testb $0x1, %al
jne 0x62ce
jmp 0x632e
leaq 0x90b9(%rip), %rsi      # 0xf38e
leaq -0x208(%rbp), %rdi
callq 0x4320
movq %rax, -0x278(%rbp)
jmp 0x62ea
movq -0x278(%rbp), %rdi
movq -0x68(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
movl %ecx, %eax
leal 0x6000(%rax,%rax,4), %esi
callq 0x45e0
jmp 0x630c
jmp 0x6365
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x40d0
jmp 0x65cd
leaq 0x9059(%rip), %rsi      # 0xf38e
leaq -0x208(%rbp), %rdi
callq 0x4320
movq %rax, -0x280(%rbp)
jmp 0x634a
movq -0x280(%rbp), %rdi
movq -0x68(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0x45e0
jmp 0x6363
jmp 0x6365
leaq 0x9022(%rip), %rsi      # 0xf38e
leaq -0x208(%rbp), %rdi
callq 0x4320
movq %rax, -0x288(%rbp)
jmp 0x6381
movq -0x288(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x45e0
jmp 0x6392
callq 0x4100
movl %eax, -0x20c(%rbp)
cmpl $-0x1, -0x20c(%rbp)
jne 0x63ca
leaq 0x90b6(%rip), %rdi      # 0xf463
callq 0x42d0
jmp 0x63b4
movl $0x13, -0x4(%rbp)
movl $0x1, -0x88(%rbp)
jmp 0x6482
cmpl $0x0, -0x20c(%rbp)
jne 0x643e
leaq -0x230(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x4350
jmp 0x63e8
leaq -0x230(%rbp), %rdi
movq %rdi, -0x290(%rbp)
callq 0x4180
movq %rax, %rcx
leaq 0x9086(%rip), %rdi      # 0xf48b
leaq 0x9084(%rip), %rsi      # 0xf490
leaq 0x9080(%rip), %rdx      # 0xf493
xorl %eax, %eax
movl %eax, %r8d
callq 0x4430
movq -0x290(%rbp), %rdi
callq 0x4240
leaq 0x9066(%rip), %rdi      # 0xf496
callq 0x42d0
jmp 0x6437
xorl %edi, %edi
callq 0x4400
movl -0x6c(%rbp), %eax
movl %eax, -0x29c(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x20c(%rbp), %rsi
callq 0x8db0
movq %rax, -0x298(%rbp)
jmp 0x6460
movq -0x298(%rbp), %rax
movl -0x29c(%rbp), %ecx
movl %ecx, (%rax)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl $0x0, -0x88(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x40d0
movl -0x88(%rbp), %eax
testl %eax, %eax
jne 0x65c2
jmp 0x649e
jmp 0x64a0
jmp 0x64a2
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x60b2
jmp 0x64b2
cmpl $0x1, -0x54(%rbp)
jl 0x659d
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
leaq -0x234(%rbp), %rsi
xorl %edx, %edx
callq 0x42a0
movl %eax, -0x2a0(%rbp)
jmp 0x64d7
movl -0x2a0(%rbp), %eax
movl %eax, -0x238(%rbp)
cmpl $-0x1, -0x238(%rbp)
jne 0x6510
leaq 0x8f30(%rip), %rdi      # 0xf423
callq 0x42d0
jmp 0x64fa
movl $0x13, -0x4(%rbp)
movl $0x1, -0x88(%rbp)
jmp 0x65c2
leaq -0x50(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x8db0
movq %rax, -0x2a8(%rbp)
jmp 0x6529
movq -0x2a8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x23c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x23c(%rbp), %esi
movl 0xee2c(%rip), %edx      # 0x15374
movl %esi, %ecx
movl %edx, %eax
leal 0xa(%rax,%rcx), %edx
movl -0x18(%rbp), %ecx
callq 0x71c0
jmp 0x655a
testb $0x1, 0xee1b(%rip)      # 0x1537c
je 0x6574
movq -0x10(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xde00
jmp 0x6572
jmp 0x6574
movl 0xedfa(%rip), %edx      # 0x15374
movl -0x23c(%rbp), %eax
movl %eax, %ecx
movl %edx, %eax
leal 0xa(%rax,%rcx), %edi
callq 0x5cf0
jmp 0x658f
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x64b2
movl -0x14(%rbp), %edi
callq 0x5cf0
jmp 0x65a7
movl -0x18(%rbp), %edi
callq 0x5cf0
jmp 0x65b1
movl $0x0, -0x4(%rbp)
movl $0x1, -0x88(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x8ec0
jmp 0x65d8
leaq -0x50(%rbp), %rdi
callq 0x8ec0
jmp 0x65e4
movl -0x4(%rbp), %eax
addq $0x2b0, %rsp            # imm = 0x2B0
popq %rbp
retq
movq -0x80(%rbp), %rdi
callq 0x45f0
nopl (%rax)