// File: /workspace/github_c_makefile_star2_O2/tomcatzh[P]RealityBenchmark/aes_bench.c
// Function: encryptContent
static CONTENTS *encryptContent(const CONTENTS* data) {
  EVP_CIPHER_CTX *ctx;

  ctx = EVP_CIPHER_CTX_new();
  assert(ctx);

  int len;
  size_t dataLength = data->size + keyLength - 1;

  int i = 0;
  switch (cipherMode) {
  case cipherModeCBC:
    switch (keyLength) {
      case keyLength128Bit:
        i = EVP_EncryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, key, iv);
        break;
      case keyLength192Bit:
        i = EVP_EncryptInit_ex(ctx, EVP_aes_192_cbc(), NULL, key, iv);
        break;
      case keyLength256Bit:
        i = EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv);
        break;
    }
    break;
  case cipherModeCFB:
    switch (keyLength) {
      case keyLength128Bit:
        i = EVP_EncryptInit_ex(ctx, EVP_aes_128_cfb(), NULL, key, iv);
        break;
      case keyLength192Bit:
        i = EVP_EncryptInit_ex(ctx, EVP_aes_192_cfb(), NULL, key, iv);
        break;
      case keyLength256Bit:
        i = EVP_EncryptInit_ex(ctx, EVP_aes_256_cfb(), NULL, key, iv);
        break;
    }
    break;
  case cipherModeOFB:
    switch (keyLength) {
      case keyLength128Bit:
        i = EVP_EncryptInit_ex(ctx, EVP_aes_128_cfb(), NULL, key, iv);
        break;
      case keyLength192Bit:
        i = EVP_EncryptInit_ex(ctx, EVP_aes_192_cfb(), NULL, key, iv);
        break;
      case keyLength256Bit:
        i = EVP_EncryptInit_ex(ctx, EVP_aes_256_cfb(), NULL, key, iv);
        break;
    }
    break;
  case cipherModeCTR:
    switch (keyLength) {
      case keyLength128Bit:
        i = EVP_EncryptInit_ex(ctx, EVP_aes_128_ctr(), NULL, key, iv);
        break;
      case keyLength192Bit:
        i = EVP_EncryptInit_ex(ctx, EVP_aes_192_ctr(), NULL, key, iv);
        break;
      case keyLength256Bit:
        i = EVP_EncryptInit_ex(ctx, EVP_aes_256_ctr(), NULL, key, iv);
        break;
    }
    break;
  case cipherModeGCM:
    switch (keyLength) {
      case keyLength128Bit:
        i = EVP_EncryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL);
        break;
      case keyLength192Bit:
        i = EVP_EncryptInit_ex(ctx, EVP_aes_192_gcm(), NULL, NULL, NULL);
        break;
      case keyLength256Bit:
        i = EVP_EncryptInit_ex(ctx, EVP_aes_256_gcm(), NULL, NULL, NULL);
        break;
    }

    dataLength += tagLength;

    i = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, ivLength, NULL);
    assert(i==1);

    i = EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv);
    assert(i==1);

    i = EVP_EncryptUpdate(ctx, NULL, &len, aad, sizeof(aad));
    assert(i==1);

    break;
  case cipherModeCCM:
    switch (keyLength) {
      case keyLength128Bit:
        i = EVP_EncryptInit_ex(ctx, EVP_aes_128_ccm(), NULL, NULL, NULL);
        break;
      case keyLength192Bit:
        i = EVP_EncryptInit_ex(ctx, EVP_aes_192_ccm(), NULL, NULL, NULL);
        break;
      case keyLength256Bit:
        i = EVP_EncryptInit_ex(ctx, EVP_aes_256_ccm(), NULL, NULL, NULL);
        break;
    }

    dataLength += tagLength;

    i = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_IVLEN, ivLength, NULL);
    assert(i==1);

    EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_TAG, tagLength, NULL);

    i = EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv);
    assert(i==1);

    i = EVP_EncryptUpdate(ctx, NULL, &len, NULL, data->size);
    assert(i==1);

    i = EVP_EncryptUpdate(ctx, NULL, &len, aad, sizeof(aad));
    assert(i==1);

    break;
  }
  assert(i==1);

  CONTENTS* ret = NULL;
  ret = calloc(1, sizeof(CONTENTS));
  assert(ret);
  ret->body = (unsigned char*)malloc(dataLength);

  i = EVP_EncryptUpdate(ctx, ret->body, &len, data->body, data->size);
  assert(i==1);
  ret->size = len;

  i = EVP_EncryptFinal_ex(ctx, ret->body + len, &len);
  assert(i==1);
  ret->size += len;

  switch (cipherMode)
  {
  case cipherModeGCM:
    i = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, tagLength, ret->body + ret->size);
    assert(i==1);
    ret->size += tagLength;
    break;
  case cipherModeCCM:
    i = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_GET_TAG, tagLength, ret->body + ret->size);
    assert(i==1);
    ret->size += tagLength;
    break;
  }

  EVP_CIPHER_CTX_free(ctx);

  return ret;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %r14
callq 0x2170
testq %rax, %rax
je 0x2da1
movq %rax, %rbx
movq 0x8(%r14), %rcx
movl 0x887b(%rip), %eax      # 0xb250
leaq (%rcx,%rax), %r15
decq %r15
movl 0x8872(%rip), %ecx      # 0xb254
leal -0x1(%rcx), %edx
cmpl $0x7, %edx
ja 0x2a1f
leaq 0x4643(%rip), %rcx      # 0x7034
movslq (%rcx,%rdx,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
cmpl $0x20, %eax
je 0x2aa7
cmpl $0x18, %eax
je 0x2aa0
cmpl $0x10, %eax
jne 0x2aec
callq 0x2330
jmp 0x2ac8
cmpl $0x10, %ecx
je 0x2a82
cmpl $0x20, %ecx
jne 0x2aec
cmpl $0x20, %eax
je 0x2bc0
cmpl $0x18, %eax
je 0x2bb9
cmpl $0x10, %eax
jne 0x2bd7
callq 0x2390
jmp 0x2bc5
cmpl $0x20, %eax
je 0x2ab5
cmpl $0x18, %eax
je 0x2aae
cmpl $0x10, %eax
jne 0x2aec
callq 0x2120
jmp 0x2ac8
cmpl $0x20, %eax
je 0x2ac3
cmpl $0x18, %eax
je 0x2abc
cmpl $0x10, %eax
jne 0x2aec
callq 0x2240
jmp 0x2ac8
cmpl $0x20, %eax
je 0x2b12
cmpl $0x18, %eax
je 0x2b0b
cmpl $0x10, %eax
jne 0x2b29
callq 0x21e0
jmp 0x2b17
callq 0x2370
jmp 0x2ac8
callq 0x2200
jmp 0x2ac8
callq 0x23e0
jmp 0x2ac8
callq 0x2160
jmp 0x2ac8
callq 0x2140
jmp 0x2ac8
callq 0x22e0
movq %rax, %rsi
leaq 0x878e(%rip), %rcx      # 0xb260
leaq 0x87a7(%rip), %r8       # 0xb280
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2130
cmpl $0x1, %eax
je 0x2c89
leaq 0x47f7(%rip), %rdi      # 0x72ea
leaq 0x45dc(%rip), %rsi      # 0x70d6
leaq 0x47be(%rip), %rcx      # 0x72bf
movl $0x149, %edx            # imm = 0x149
callq 0x2190
callq 0x23f0
jmp 0x2b17
callq 0x2360
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2130
movzbl 0x872b(%rip), %r12d     # 0xb25c
movzbl 0x8720(%rip), %eax      # 0xb258
leal (%rax,%rax,4), %edx
addl $0x7, %edx
pushq $0x9
popq %rsi
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x2310
cmpl $0x1, %eax
jne 0x2e3c
leaq 0x8705(%rip), %rcx      # 0xb260
leaq 0x871e(%rip), %r8       # 0xb280
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2130
cmpl $0x1, %eax
jne 0x2e7a
leaq 0x8712(%rip), %rcx      # 0xb290
leaq 0xc(%rsp), %rdx
pushq $0x20
popq %r8
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2050
cmpl $0x1, %eax
je 0x2c81
leaq 0x4749(%rip), %rdi      # 0x72ea
leaq 0x452e(%rip), %rsi      # 0x70d6
leaq 0x4710(%rip), %rcx      # 0x72bf
movl $0x127, %edx            # imm = 0x127
callq 0x2190
callq 0x2290
jmp 0x2bc5
callq 0x22a0
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2130
movzbl 0x867d(%rip), %r12d     # 0xb25c
movzbl 0x8672(%rip), %eax      # 0xb258
leal (%rax,%rax,4), %edx
addl $0x7, %edx
pushq $0x9
popq %rsi
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x2310
cmpl $0x1, %eax
jne 0x2e5b
movzbl 0x8653(%rip), %eax      # 0xb25c
leal 0xc(,%rax,4), %edx
pushq $0x11
popq %rsi
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x2310
leaq 0x863c(%rip), %rcx      # 0xb260
leaq 0x8655(%rip), %r8       # 0xb280
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2130
cmpl $0x1, %eax
jne 0x2e99
movl 0x8(%r14), %r8d
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x2050
cmpl $0x1, %eax
jne 0x2eb8
leaq 0x862b(%rip), %rcx      # 0xb290
leaq 0xc(%rsp), %rdx
pushq $0x20
popq %r8
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2050
cmpl $0x1, %eax
jne 0x2ed7
leaq (%r15,%r12,4), %r15
addq $0xc, %r15
pushq $0x1
popq %rdi
pushq $0x10
popq %rsi
callq 0x21a0
testq %rax, %rax
je 0x2dc0
movq %rax, %r12
movq %r15, %rdi
callq 0x2430
movq %rax, %r15
movq %rax, (%r12)
movq (%r14), %rcx
movl 0x8(%r14), %r8d
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2050
cmpl $0x1, %eax
jne 0x2ddf
leaq 0xc(%rsp), %rdx
movslq (%rdx), %r13
leaq (%r15,%r13), %rsi
movq %rbx, %rdi
callq 0x2380
cmpl $0x1, %eax
jne 0x2dfe
movslq 0xc(%rsp), %r14
addq %r13, %r14
movq %r14, 0x8(%r12)
movl 0x8555(%rip), %eax      # 0xb254
cmpl $0x20, %eax
je 0x2d4c
cmpl $0x10, %eax
jne 0x2d88
movzbl 0x854c(%rip), %eax      # 0xb25c
leal 0xc(,%rax,4), %edx
addq %r14, %r15
pushq $0x10
popq %rsi
movq %rbx, %rdi
movq %r15, %rcx
callq 0x2310
cmpl $0x1, %eax
je 0x2d74
leaq 0x45b6(%rip), %rdi      # 0x72ea
leaq 0x439b(%rip), %rsi      # 0x70d6
leaq 0x457d(%rip), %rcx      # 0x72bf
movl $0x15c, %edx            # imm = 0x15C
callq 0x2190
movzbl 0x8509(%rip), %eax      # 0xb25c
leal 0xc(,%rax,4), %edx
addq %r14, %r15
pushq $0x10
popq %rsi
movq %rbx, %rdi
movq %r15, %rcx
callq 0x2310
cmpl $0x1, %eax
jne 0x2e1d
movzbl 0x84e1(%rip), %eax      # 0xb25c
leaq (%r14,%rax,4), %rax
addq $0xc, %rax
movq %rax, 0x8(%r12)
movq %rbx, %rdi
callq 0x2250
movq %r12, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x4513(%rip), %rdi      # 0x72bb
leaq 0x4327(%rip), %rsi      # 0x70d6
leaq 0x4509(%rip), %rcx      # 0x72bf
movl $0xd6, %edx
callq 0x2190
leaq 0x4528(%rip), %rdi      # 0x72ef
leaq 0x4308(%rip), %rsi      # 0x70d6
leaq 0x44ea(%rip), %rcx      # 0x72bf
movl $0x14d, %edx            # imm = 0x14D
callq 0x2190
leaq 0x4504(%rip), %rdi      # 0x72ea
leaq 0x42e9(%rip), %rsi      # 0x70d6
leaq 0x44cb(%rip), %rcx      # 0x72bf
movl $0x151, %edx            # imm = 0x151
callq 0x2190
leaq 0x44e5(%rip), %rdi      # 0x72ea
leaq 0x42ca(%rip), %rsi      # 0x70d6
leaq 0x44ac(%rip), %rcx      # 0x72bf
movl $0x155, %edx            # imm = 0x155
callq 0x2190
leaq 0x44c6(%rip), %rdi      # 0x72ea
leaq 0x42ab(%rip), %rsi      # 0x70d6
leaq 0x448d(%rip), %rcx      # 0x72bf
movl $0x161, %edx            # imm = 0x161
callq 0x2190
leaq 0x44a7(%rip), %rdi      # 0x72ea
leaq 0x428c(%rip), %rsi      # 0x70d6
leaq 0x446e(%rip), %rcx      # 0x72bf
movl $0x121, %edx            # imm = 0x121
callq 0x2190
leaq 0x4488(%rip), %rdi      # 0x72ea
leaq 0x426d(%rip), %rsi      # 0x70d6
leaq 0x444f(%rip), %rcx      # 0x72bf
movl $0x13a, %edx            # imm = 0x13A
callq 0x2190
leaq 0x4469(%rip), %rdi      # 0x72ea
leaq 0x424e(%rip), %rsi      # 0x70d6
leaq 0x4430(%rip), %rcx      # 0x72bf
movl $0x124, %edx            # imm = 0x124
callq 0x2190
leaq 0x444a(%rip), %rdi      # 0x72ea
leaq 0x422f(%rip), %rsi      # 0x70d6
leaq 0x4411(%rip), %rcx      # 0x72bf
movl $0x13f, %edx            # imm = 0x13F
callq 0x2190
leaq 0x442b(%rip), %rdi      # 0x72ea
leaq 0x4210(%rip), %rsi      # 0x70d6
leaq 0x43f2(%rip), %rcx      # 0x72bf
movl $0x142, %edx            # imm = 0x142
callq 0x2190
leaq 0x440c(%rip), %rdi      # 0x72ea
leaq 0x41f1(%rip), %rsi      # 0x70d6
leaq 0x43d3(%rip), %rcx      # 0x72bf
movl $0x145, %edx            # imm = 0x145
callq 0x2190