// File: /workspace/github_c_makefile_star2_O3/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 0x2eab
movq %rax, %rbx
movq 0x8(%r14), %rcx
movl 0x9787(%rip), %eax      # 0xc250
leaq (%rcx,%rax), %r15
decq %r15
movl 0x977e(%rip), %ecx      # 0xc254
leal -0x1(%rcx), %edx
cmpl $0x7, %edx
ja 0x2b13
leaq 0x554f(%rip), %rcx      # 0x8034
movslq (%rcx,%rdx,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
cmpl $0x20, %eax
je 0x2b9b
cmpl $0x18, %eax
je 0x2b94
cmpl $0x10, %eax
jne 0x2be0
callq 0x2330
jmp 0x2bbc
cmpl $0x10, %ecx
je 0x2b76
cmpl $0x20, %ecx
jne 0x2be0
cmpl $0x20, %eax
je 0x2cb8
cmpl $0x18, %eax
je 0x2cb1
cmpl $0x10, %eax
jne 0x2ccf
callq 0x2390
jmp 0x2cbd
cmpl $0x20, %eax
je 0x2ba9
cmpl $0x18, %eax
je 0x2ba2
cmpl $0x10, %eax
jne 0x2be0
callq 0x2120
jmp 0x2bbc
cmpl $0x20, %eax
je 0x2bb7
cmpl $0x18, %eax
je 0x2bb0
cmpl $0x10, %eax
jne 0x2be0
callq 0x2240
jmp 0x2bbc
cmpl $0x20, %eax
je 0x2c06
cmpl $0x18, %eax
je 0x2bff
cmpl $0x10, %eax
jne 0x2c1d
callq 0x21e0
jmp 0x2c0b
callq 0x2370
jmp 0x2bbc
callq 0x2200
jmp 0x2bbc
callq 0x23e0
jmp 0x2bbc
callq 0x2160
jmp 0x2bbc
callq 0x2140
jmp 0x2bbc
callq 0x22e0
movq %rax, %rsi
leaq 0x969a(%rip), %rcx      # 0xc260
leaq 0x96b3(%rip), %r8       # 0xc280
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2130
cmpl $0x1, %eax
je 0x2d87
leaq 0x5703(%rip), %rdi      # 0x82ea
leaq 0x54e8(%rip), %rsi      # 0x80d6
leaq 0x56ca(%rip), %rcx      # 0x82bf
movl $0x149, %edx            # imm = 0x149
callq 0x2190
callq 0x23f0
jmp 0x2c0b
callq 0x2360
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2130
movzbl 0x9637(%rip), %r12d     # 0xc25c
movzbl 0x962c(%rip), %eax      # 0xc258
leal (%rax,%rax,4), %edx
addl $0x7, %edx
movq %rbx, %rdi
movl $0x9, %esi
xorl %ecx, %ecx
callq 0x2310
cmpl $0x1, %eax
jne 0x2f46
leaq 0x960f(%rip), %rcx      # 0xc260
leaq 0x9628(%rip), %r8       # 0xc280
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2130
cmpl $0x1, %eax
jne 0x2f84
leaq 0x961c(%rip), %rcx      # 0xc290
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
movl $0x20, %r8d
callq 0x2050
cmpl $0x1, %eax
je 0x2d7f
leaq 0x5651(%rip), %rdi      # 0x82ea
leaq 0x5436(%rip), %rsi      # 0x80d6
leaq 0x5618(%rip), %rcx      # 0x82bf
movl $0x127, %edx            # imm = 0x127
callq 0x2190
callq 0x2290
jmp 0x2cbd
callq 0x22a0
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2130
movzbl 0x9585(%rip), %r12d     # 0xc25c
movzbl 0x957a(%rip), %eax      # 0xc258
leal (%rax,%rax,4), %edx
addl $0x7, %edx
movq %rbx, %rdi
movl $0x9, %esi
xorl %ecx, %ecx
callq 0x2310
cmpl $0x1, %eax
jne 0x2f65
movzbl 0x9559(%rip), %eax      # 0xc25c
leal 0xc(,%rax,4), %edx
movq %rbx, %rdi
movl $0x11, %esi
xorl %ecx, %ecx
callq 0x2310
leaq 0x9540(%rip), %rcx      # 0xc260
leaq 0x9559(%rip), %r8       # 0xc280
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2130
cmpl $0x1, %eax
jne 0x2fa3
movl 0x8(%r14), %r8d
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x2050
cmpl $0x1, %eax
jne 0x2fc2
leaq 0x952f(%rip), %rcx      # 0xc290
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
movl $0x20, %r8d
callq 0x2050
cmpl $0x1, %eax
jne 0x2fe1
leaq (%r15,%r12,4), %r15
addq $0xc, %r15
movl $0x1, %edi
movl $0x10, %esi
callq 0x21a0
testq %rax, %rax
je 0x2eca
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 0x2ee9
leaq 0xc(%rsp), %rdx
movslq (%rdx), %r13
leaq (%r15,%r13), %rsi
movq %rbx, %rdi
callq 0x2380
cmpl $0x1, %eax
jne 0x2f08
movslq 0xc(%rsp), %r14
addq %r13, %r14
movq %r14, 0x8(%r12)
movl 0x9453(%rip), %eax      # 0xc254
cmpl $0x20, %eax
je 0x2e54
cmpl $0x10, %eax
jne 0x2e92
movzbl 0x9446(%rip), %eax      # 0xc25c
leal 0xc(,%rax,4), %edx
addq %r14, %r15
movq %rbx, %rdi
movl $0x10, %esi
movq %r15, %rcx
callq 0x2310
cmpl $0x1, %eax
je 0x2e7e
leaq 0x54ae(%rip), %rdi      # 0x82ea
leaq 0x5293(%rip), %rsi      # 0x80d6
leaq 0x5475(%rip), %rcx      # 0x82bf
movl $0x15c, %edx            # imm = 0x15C
callq 0x2190
movzbl 0x9401(%rip), %eax      # 0xc25c
leal 0xc(,%rax,4), %edx
addq %r14, %r15
movq %rbx, %rdi
movl $0x10, %esi
movq %r15, %rcx
callq 0x2310
cmpl $0x1, %eax
jne 0x2f27
movzbl 0x93d7(%rip), %eax      # 0xc25c
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 0x5409(%rip), %rdi      # 0x82bb
leaq 0x521d(%rip), %rsi      # 0x80d6
leaq 0x53ff(%rip), %rcx      # 0x82bf
movl $0xd6, %edx
callq 0x2190
leaq 0x541e(%rip), %rdi      # 0x82ef
leaq 0x51fe(%rip), %rsi      # 0x80d6
leaq 0x53e0(%rip), %rcx      # 0x82bf
movl $0x14d, %edx            # imm = 0x14D
callq 0x2190
leaq 0x53fa(%rip), %rdi      # 0x82ea
leaq 0x51df(%rip), %rsi      # 0x80d6
leaq 0x53c1(%rip), %rcx      # 0x82bf
movl $0x151, %edx            # imm = 0x151
callq 0x2190
leaq 0x53db(%rip), %rdi      # 0x82ea
leaq 0x51c0(%rip), %rsi      # 0x80d6
leaq 0x53a2(%rip), %rcx      # 0x82bf
movl $0x155, %edx            # imm = 0x155
callq 0x2190
leaq 0x53bc(%rip), %rdi      # 0x82ea
leaq 0x51a1(%rip), %rsi      # 0x80d6
leaq 0x5383(%rip), %rcx      # 0x82bf
movl $0x161, %edx            # imm = 0x161
callq 0x2190
leaq 0x539d(%rip), %rdi      # 0x82ea
leaq 0x5182(%rip), %rsi      # 0x80d6
leaq 0x5364(%rip), %rcx      # 0x82bf
movl $0x121, %edx            # imm = 0x121
callq 0x2190
leaq 0x537e(%rip), %rdi      # 0x82ea
leaq 0x5163(%rip), %rsi      # 0x80d6
leaq 0x5345(%rip), %rcx      # 0x82bf
movl $0x13a, %edx            # imm = 0x13A
callq 0x2190
leaq 0x535f(%rip), %rdi      # 0x82ea
leaq 0x5144(%rip), %rsi      # 0x80d6
leaq 0x5326(%rip), %rcx      # 0x82bf
movl $0x124, %edx            # imm = 0x124
callq 0x2190
leaq 0x5340(%rip), %rdi      # 0x82ea
leaq 0x5125(%rip), %rsi      # 0x80d6
leaq 0x5307(%rip), %rcx      # 0x82bf
movl $0x13f, %edx            # imm = 0x13F
callq 0x2190
leaq 0x5321(%rip), %rdi      # 0x82ea
leaq 0x5106(%rip), %rsi      # 0x80d6
leaq 0x52e8(%rip), %rcx      # 0x82bf
movl $0x142, %edx            # imm = 0x142
callq 0x2190
leaq 0x5302(%rip), %rdi      # 0x82ea
leaq 0x50e7(%rip), %rsi      # 0x80d6
leaq 0x52c9(%rip), %rcx      # 0x82bf
movl $0x145, %edx            # imm = 0x145
callq 0x2190