// File: /workspace/github_c_makefile_star2_O2/tomcatzh[P]RealityBenchmark/aes_bench.c
// Function: main
int main(int argc, char **argv) {
  int ret = -1;

  CONTENTS *contents = NULL;

  struct timeval timeout;
  timeout.tv_sec = 0;
  timeout.tv_usec = 0;
  unsigned int threads = 0;
  int verbose = 0;
  int formated = 0;
  size_t randomSize = 0;
  char mode[4];
  mode[0] = '\0';

  int index;
  int c;
  opterr = 0;

  while ((c = getopt(argc, argv, "r:t:vfu:k:c:")) != -1) {
    switch (c) {
    case 'r':
      timeout.tv_sec = atoi(optarg);
      break;
    case 't':
      threads = atoi(optarg);
      break;
    case 'u':
      randomSize = parseHumanSize(optarg);
      break;
    case 'v':
      verbose = 1;
      break;
    case 'f':
      formated = 1;
      break;
    case 'k':
      keyLength = atoi(optarg);
      break;
    case 'c':
      strncpy(mode, optarg, sizeof(mode));
      mode[3] = '\0';
      break;
    case '?':
      printUsage();
      goto END;
    }
  }

  if (timeout.tv_sec == 0) {
    timeout.tv_sec = 3;
  }

  if (threads == 0) {
    threads = sysconf(_SC_NPROCESSORS_ONLN);
    if (threads == 0) 
      threads = 2;
  }

  switch (keyLength) {
  case 128:
  case 0:
    keyLength = keyLength128Bit;
    break;
  case 192:
    keyLength = keyLength192Bit;
    break;
  case 256:
    keyLength = keyLength256Bit;
    break;
  default:
    printUsage();
    goto END;
  }

  if (mode[0] == '\0' || strcmp(mode, "CBC") == 0) {
    cipherMode = cipherModeCBC;
  } else if (strcmp(mode, "CFB") == 0) {
    cipherMode = cipherModeCFB;
  } else if (strcmp(mode, "OFB") == 0) {
    cipherMode = cipherModeOFB;
  } else if (strcmp(mode, "CTR") == 0) {
    cipherMode = cipherModeCTR;
  } else if (strcmp(mode, "GCM") == 0) {
    cipherMode = cipherModeGCM;
    ivLength = 12;
    tagLength = 16;
  } else if (strcmp(mode, "CCM") == 0) {
    cipherMode = cipherModeCCM;
    ivLength = 7;
    tagLength = 12;
  } else {
    printUsage();
    goto END;
  }

  init();

  if (randomSize) {
    contents = randomContents(randomSize);
  } else {
    index = optind;
    if (index >= argc) {
      printUsage();
      goto END;
    }

    contents = getContents(argv[index]);

    if (contents == NULL) {
      fprintf(stderr, "Get content error\n");
      goto END;
    } else if (contents->size == 0) {
      fprintf(stderr, "Empty content to zip\n");
      goto END;
    }
  }

  TEST *t = testNew();
  testSetThreads(t, threads);
  testSetTimeout(t, &timeout);
  testAddRun(t, &encryptContent);
  testAddRun(t, &decryptContent);
  testSetInput(t, contents);
  testSetTesting(t, contents);

  RESULT *r = testRun(t);
  assert(r);

  printResult(r, verbose, formated);

  resultDestory(r);

  ret = 0;

END:
  if (contents) {
    destroyContents(contents);
    free(contents);
    contents = NULL;
  }
  return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movl %edi, %r12d
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq 0x8a91(%rip), %rax      # 0xafe0
andl $0x0, (%rax)
leaq 0x8(%rsp), %rax
movb $0x0, (%rax)
xorl %r15d, %r15d
leaq 0x4b24(%rip), %rbp      # 0x7088
movq 0x8a3d(%rip), %rbx      # 0xafa8
leaq 0x4a92(%rip), %r13      # 0x7004
movl $0x0, 0xc(%rsp)
movq $0x0, 0x18(%rsp)
movl $0x0, 0x10(%rsp)
movl $0x0, 0x14(%rsp)
movl %r12d, %edi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x20a0
leal -0x6b(%rax), %ecx
cmpl $0xb, %ecx
ja 0x25c3
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movq (%rbx), %rdi
callq 0x2350
movl %eax, 0x8c8f(%rip)      # 0xb250
jmp 0x2593
cmpl $0x63, %eax
je 0x2623
cmpl $0x66, %eax
je 0x2617
cmpl $-0x1, %eax
je 0x263d
cmpl $0x3f, %eax
jne 0x2593
jmp 0x287e
pushq $0x1
popq %rax
movl %eax, 0x10(%rsp)
jmp 0x2593
movq (%rbx), %rdi
callq 0x2350
movl %eax, 0x14(%rsp)
jmp 0x2593
movq (%rbx), %rdi
callq 0x3b12
movq %rax, 0x18(%rsp)
jmp 0x2593
movq (%rbx), %rdi
callq 0x2350
movslq %eax, %r15
movq %r15, 0x20(%rsp)
jmp 0x2593
pushq $0x1
popq %rax
movl %eax, 0xc(%rsp)
jmp 0x2593
movq (%rbx), %rsi
leaq 0x8(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x2110
movb $0x0, 0xb(%rsp)
jmp 0x2593
testq %r15, %r15
jne 0x264b
movq $0x3, 0x20(%rsp)
movl 0x14(%rsp), %r15d
testl %r15d, %r15d
jne 0x2667
pushq $0x54
popq %rdi
callq 0x2180
testl %eax, %eax
pushq $0x2
popq %r15
cmovnel %eax, %r15d
movl 0x8be3(%rip), %eax      # 0xb250
roll $0x1a, %eax
cmpl $0x5, %eax
jae 0x287e
pushq $0x1d
popq %rcx
btl %eax, %ecx
jae 0x287e
movl %eax, %eax
leaq 0x49e6(%rip), %rcx      # 0x7074
movl (%rcx,%rax,4), %eax
movl %eax, 0x8bb9(%rip)      # 0xb250
cmpb $0x0, 0x8(%rsp)
je 0x2708
cmpl $0x434243, 0x8(%rsp)    # imm = 0x434243
je 0x2708
cmpl $0x424643, 0x8(%rsp)    # imm = 0x424643
je 0x2897
cmpl $0x42464f, 0x8(%rsp)    # imm = 0x42464F
je 0x28a6
cmpl $0x525443, 0x8(%rsp)    # imm = 0x525443
je 0x28b5
cmpl $0x4d4347, 0x8(%rsp)    # imm = 0x4D4347
je 0x28c4
cmpl $0x4d4343, 0x8(%rsp)    # imm = 0x4D4343
jne 0x287e
movl $0x20, 0x8b5c(%rip)     # 0xb254
xorl %eax, %eax
movb %al, 0x8b58(%rip)       # 0xb258
movb %al, 0x8b56(%rip)       # 0xb25c
jmp 0x2712
movl $0x1, 0x8b42(%rip)      # 0xb254
leaq 0x4b4b(%rip), %rdi      # 0x7264
xorl %esi, %esi
xorl %eax, %eax
callq 0x21b0
testl %eax, %eax
js 0x2923
movl %eax, %ebx
movl 0x8b1e(%rip), %edx      # 0xb250
leaq 0x8b27(%rip), %rsi      # 0xb260
movl %eax, %edi
callq 0x2300
movl 0x8b0a(%rip), %ecx      # 0xb250
cmpq %rcx, %rax
jne 0x293c
leaq 0x8b2a(%rip), %rsi      # 0xb280
pushq $0x10
popq %rdx
movl %ebx, %edi
callq 0x2300
cmpq $0x10, %rax
jne 0x2955
movl 0x8ae4(%rip), %eax      # 0xb254
cmpl $0x20, %eax
je 0x277a
cmpl $0x10, %eax
jne 0x2795
leaq 0x8b0f(%rip), %rsi      # 0xb290
pushq $0x20
popq %rdx
movl %ebx, %edi
callq 0x2300
cmpq $0x20, %rax
jne 0x298d
movl %ebx, %edi
callq 0x2410
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x27b0
callq 0x35fc
movq %rax, %rbx
jmp 0x27e3
movq 0x8819(%rip), %rax      # 0xafd0
movslq (%rax), %rax
cmpl %r12d, %eax
jge 0x287e
movq (%r14,%rax,8), %rdi
callq 0x36d5
testq %rax, %rax
je 0x28e1
movq %rax, %rbx
cmpq $0x0, 0x8(%rax)
je 0x28ff
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x3bcc
movq %rax, %r14
movq %rax, %rdi
movl %r15d, %esi
callq 0x3c03
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x3bfc
leaq 0x19c(%rip), %rsi       # 0x29aa
movq %r14, %rdi
callq 0x3c07
leaq 0x6d9(%rip), %rsi       # 0x2ef6
movq %r14, %rdi
callq 0x3c07
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3c63
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3c5e
movq %r14, %rdi
callq 0x3cbc
testq %rax, %rax
je 0x296e
movq %rax, %r14
movq %rax, %rdi
movl 0x10(%rsp), %esi
movl 0xc(%rsp), %edx
callq 0x3fd9
movq %r14, %rdi
callq 0x3c69
testq %rbx, %rbx
je 0x2886
movq %rbx, %rdi
callq 0x387a
movq %rbx, %rdi
callq 0x2428
jmp 0x2886
callq 0x35dd
pushq $-0x1
popq %rbp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x2, 0x89b3(%rip)      # 0xb254
jmp 0x2712
movl $0x4, 0x89a4(%rip)      # 0xb254
jmp 0x2712
movl $0x8, 0x8995(%rip)      # 0xb254
jmp 0x2712
movl $0x10, 0x8986(%rip)     # 0xb254
movb $0x1, %al
movb %al, 0x8982(%rip)       # 0xb258
movb %al, 0x8980(%rip)       # 0xb25c
jmp 0x2712
movq 0x86e0(%rip), %rax      # 0xafc8
movq (%rax), %rcx
leaq 0x47bb(%rip), %rdi      # 0x70ad
pushq $0x12
popq %rsi
pushq $0x1
popq %rdx
callq 0x2400
jmp 0x2883
movq 0x86c2(%rip), %rax      # 0xafc8
movq (%rax), %rcx
leaq 0x47b0(%rip), %rdi      # 0x70c0
pushq $0x15
popq %rsi
pushq $0x1
popq %rdx
callq 0x2400
pushq $-0x1
popq %rbp
jmp 0x286c
leaq 0x4947(%rip), %rdi      # 0x7271
leaq 0x47a5(%rip), %rsi      # 0x70d6
leaq 0x4941(%rip), %rcx      # 0x7279
pushq $0x26
jmp 0x29a4
leaq 0x4942(%rip), %rdi      # 0x7285
leaq 0x478c(%rip), %rsi      # 0x70d6
leaq 0x4928(%rip), %rcx      # 0x7279
pushq $0x2b
jmp 0x29a4
leaq 0x493a(%rip), %rdi      # 0x7296
leaq 0x4773(%rip), %rsi      # 0x70d6
leaq 0x490f(%rip), %rcx      # 0x7279
pushq $0x2e
jmp 0x29a4
leaq 0x4af0(%rip), %rdi      # 0x7465
leaq 0x475a(%rip), %rsi      # 0x70d6
leaq 0x475f(%rip), %rcx      # 0x70e2
movl $0x1f5, %edx            # imm = 0x1F5
callq 0x2190
leaq 0x4914(%rip), %rdi      # 0x72a8
leaq 0x473b(%rip), %rsi      # 0x70d6
leaq 0x48d7(%rip), %rcx      # 0x7279
pushq $0x32
popq %rdx
callq 0x2190