// File: /workspace/github_c_makefile_star2_O0/tomcatzh[P]RealityBenchmark/benchmark.c
// Function: loopThread
static void *loopThread(void *arg) {
  TEST *t = (TEST *)arg;

  const CONTENTS* input;
  CONTENTS *output, *needFree;

  struct timeval start, loopTime, now;
  gettimeofday(&start, NULL);

  LOOP *headLoop, *loop, *newLoop;
  RUN *headRun, *run, *newRun;

  loop = headLoop = NULL;

  do {
    newLoop = (LOOP *)calloc(1, sizeof(LOOP));
    assert(newLoop);
    if (!headLoop) headLoop = newLoop;
    if (loop) loop->next = newLoop;
    loop = newLoop;

    input = t->input;
    output = needFree = NULL;
    run = headRun = NULL;

    for (unsigned int i = 0; i < t->runCount; i ++) {
      newRun = (RUN *)calloc(1, sizeof(RUN));
      if (!headRun) headRun = newRun;
      if (run) run->next = newRun;
      run = newRun;

      if (needFree) {
        destroyContents(needFree);
        needFree = NULL;
      }
      if (output) {
        needFree = output;
        output = NULL;
      }

      gettimeofday(&loopTime, NULL);
      if (input) {
        output = (*(t->run[i]))(input);
      }
      gettimeofday(&now, NULL);

      if (output) {
        run->inputBytes = input->size;
        run->outputBytes = output->size;
        run->success = 1;
      }

      timevalSubtract(&(run->interval), &now, &loopTime);
      
      input = output;
    }

    if (needFree) {
      destroyContents(needFree);
    }

    if (output) {
      if (t->verifyData) {
        loop->correct = !(compareContents(t->verifyData, output));
      } else {
        loop->correct = 1;
      }

      destroyContents(output);
    }

    loop->runs = headRun;
  } while (timevalBeforeTimeout(&(t->timeout), &now, &start));

  return headLoop;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
leaq -0x38(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x23e0
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movl $0x1, %edi
movl $0x18, %esi
callq 0x21b0
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x4cc0
jmp 0x4cdf
leaq 0x7a2e(%rip), %rdi      # 0xc6f5
leaq 0x795a(%rip), %rsi      # 0xc628
movl $0x209, %edx            # imm = 0x209
leaq 0x7a23(%rip), %rcx      # 0xc6fd
callq 0x21a0
cmpq $0x0, -0x60(%rbp)
jne 0x4cee
movq -0x70(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x4d01
movq -0x70(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x70(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movl $0x0, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jae 0x4e66
movl $0x1, %edi
movl $0x30, %esi
callq 0x21b0
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x4d7a
movq -0x88(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x80(%rbp)
je 0x4d90
movq -0x88(%rbp), %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x88(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x4db3
movq -0x28(%rbp), %rdi
callq 0x4220
movq $0x0, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x4dca
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x20(%rbp)
leaq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x23e0
cmpq $0x0, -0x18(%rbp)
je 0x4dfa
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x8c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq -0x18(%rbp), %rdi
callq *%rax
movq %rax, -0x20(%rbp)
leaq -0x58(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x23e0
cmpq $0x0, -0x20(%rbp)
je 0x4e39
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x80(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x80(%rbp), %rdi
leaq -0x58(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0x4580
movq -0x20(%rbp), %rax
movq %rax, -0x18(%rbp)
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x4d3f
cmpq $0x0, -0x28(%rbp)
je 0x4e76
movq -0x28(%rbp), %rdi
callq 0x4220
cmpq $0x0, -0x20(%rbp)
je 0x4ec3
movq -0x10(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x4eaf
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x4330
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x4eba
movq -0x68(%rbp), %rax
movl $0x1, 0x8(%rax)
movq -0x20(%rbp), %rdi
callq 0x4220
movq -0x78(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
leaq -0x58(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0x46b0
cmpl $0x0, %eax
jne 0x4ca4
movq -0x60(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)