// File: /workspace/github_c_makefile_star2_O1/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 0x2e9e
movq %rax, %rbx
movq 0x8(%r14), %rcx
movl 0x977f(%rip), %eax      # 0xc250
leaq (%rcx,%rax), %r15
decq %r15
xorl %ecx, %ecx
movl 0x9774(%rip), %edx      # 0xc254
leal -0x1(%rdx), %esi
cmpl $0x7, %esi
ja 0x2b19
leaq 0x5545(%rip), %rdx      # 0x8034
movslq (%rdx,%rsi,4), %rsi
addq %rdx, %rsi
jmpq *%rsi
cmpl $0x20, %eax
je 0x2b9c
cmpl $0x18, %eax
je 0x2b95
cmpl $0x10, %eax
jne 0x2b78
callq 0x2340
jmp 0x2bbd
cmpl $0x10, %edx
je 0x2b7f
cmpl $0x20, %edx
jne 0x2d6d
cmpl $0x20, %eax
je 0x2c9c
cmpl $0x18, %eax
je 0x2c95
cmpl $0x10, %eax
jne 0x2cb3
callq 0x23a0
jmp 0x2ca1
cmpl $0x20, %eax
je 0x2baa
cmpl $0x18, %eax
je 0x2ba3
cmpl $0x10, %eax
jne 0x2b78
callq 0x2250
jmp 0x2bbd
cmpl $0x20, %eax
je 0x2bb8
cmpl $0x18, %eax
je 0x2bb1
cmpl $0x10, %eax
jne 0x2b78
callq 0x2120
jmp 0x2bbd
xorl %ecx, %ecx
jmp 0x2d6d
cmpl $0x20, %eax
je 0x2bea
cmpl $0x18, %eax
je 0x2be3
cmpl $0x10, %eax
jne 0x2c01
callq 0x21f0
jmp 0x2bef
callq 0x2380
jmp 0x2bbd
callq 0x2210
jmp 0x2bbd
callq 0x2140
jmp 0x2bbd
callq 0x22f0
jmp 0x2bbd
callq 0x23f0
jmp 0x2bbd
callq 0x2160
movq %rax, %rsi
leaq 0x9699(%rip), %rcx      # 0xc260
leaq 0x96b2(%rip), %r8       # 0xc280
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2130
cmpl $0x1, %eax
sete %cl
jmp 0x2d6d
callq 0x2400
jmp 0x2bef
callq 0x2370
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2130
movzbl 0x9653(%rip), %r12d     # 0xc25c
movzbl 0x9648(%rip), %eax      # 0xc258
leal (%rax,%rax,4), %edx
addl $0x7, %edx
movq %rbx, %rdi
movl $0x9, %esi
xorl %ecx, %ecx
callq 0x2320
cmpl $0x1, %eax
jne 0x2f58
leaq 0x962b(%rip), %rcx      # 0xc260
leaq 0x9644(%rip), %r8       # 0xc280
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2130
cmpl $0x1, %eax
jne 0x2f96
leaq 0x9638(%rip), %rcx      # 0xc290
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
movl $0x20, %r8d
callq 0x2050
cmpl $0x1, %eax
je 0x2d63
leaq 0x566d(%rip), %rdi      # 0x82ea
leaq 0x5452(%rip), %rsi      # 0x80d6
leaq 0x5634(%rip), %rcx      # 0x82bf
movl $0x127, %edx            # imm = 0x127
callq 0x2190
callq 0x22a0
jmp 0x2ca1
callq 0x22b0
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2130
movzbl 0x95a1(%rip), %r12d     # 0xc25c
movzbl 0x9596(%rip), %eax      # 0xc258
leal (%rax,%rax,4), %edx
addl $0x7, %edx
movq %rbx, %rdi
movl $0x9, %esi
xorl %ecx, %ecx
callq 0x2320
cmpl $0x1, %eax
jne 0x2f77
movzbl 0x9575(%rip), %eax      # 0xc25c
leal 0xc(,%rax,4), %edx
movq %rbx, %rdi
movl $0x11, %esi
xorl %ecx, %ecx
callq 0x2320
leaq 0x955c(%rip), %rcx      # 0xc260
leaq 0x9575(%rip), %r8       # 0xc280
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2130
cmpl $0x1, %eax
jne 0x2fb5
movl 0x8(%r14), %r8d
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x2050
cmpl $0x1, %eax
jne 0x2fd4
leaq 0x954b(%rip), %rcx      # 0xc290
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
movl $0x20, %r8d
callq 0x2050
cmpl $0x1, %eax
jne 0x2ff3
leaq (%r15,%r12,4), %r15
addq $0xc, %r15
movb $0x1, %cl
testb %cl, %cl
je 0x2ebd
movl $0x1, %edi
movl $0x10, %esi
callq 0x21a0
testq %rax, %rax
je 0x2edc
movq %rax, %r12
movq %r15, %rdi
callq 0x2440
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 0x2efb
leaq 0xc(%rsp), %rdx
movslq (%rdx), %r13
movq %r13, 0x8(%r12)
leaq (%r15,%r13), %rsi
movq %rbx, %rdi
callq 0x2390
cmpl $0x1, %eax
jne 0x2f1a
movslq 0xc(%rsp), %r14
addq %r13, %r14
movq %r14, 0x8(%r12)
movl 0x9460(%rip), %eax      # 0xc254
cmpl $0x20, %eax
je 0x2e47
cmpl $0x10, %eax
jne 0x2e85
movzbl 0x9453(%rip), %eax      # 0xc25c
leal 0xc(,%rax,4), %edx
addq %r14, %r15
movq %rbx, %rdi
movl $0x10, %esi
movq %r15, %rcx
callq 0x2320
cmpl $0x1, %eax
je 0x2e71
leaq 0x54bb(%rip), %rdi      # 0x82ea
leaq 0x52a0(%rip), %rsi      # 0x80d6
leaq 0x5482(%rip), %rcx      # 0x82bf
movl $0x15c, %edx            # imm = 0x15C
callq 0x2190
movzbl 0x940e(%rip), %eax      # 0xc25c
leal 0xc(,%rax,4), %edx
addq %r14, %r15
movq %rbx, %rdi
movl $0x10, %esi
movq %r15, %rcx
callq 0x2320
cmpl $0x1, %eax
jne 0x2f39
movzbl 0x93e4(%rip), %eax      # 0xc25c
leaq (%r14,%rax,4), %rax
addq $0xc, %rax
movq %rax, 0x8(%r12)
movq %rbx, %rdi
callq 0x2260
movq %r12, %rax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x5416(%rip), %rdi      # 0x82bb
leaq 0x522a(%rip), %rsi      # 0x80d6
leaq 0x540c(%rip), %rcx      # 0x82bf
movl $0xd6, %edx
callq 0x2190
leaq 0x5426(%rip), %rdi      # 0x82ea
leaq 0x520b(%rip), %rsi      # 0x80d6
leaq 0x53ed(%rip), %rcx      # 0x82bf
movl $0x149, %edx            # imm = 0x149
callq 0x2190
leaq 0x540c(%rip), %rdi      # 0x82ef
leaq 0x51ec(%rip), %rsi      # 0x80d6
leaq 0x53ce(%rip), %rcx      # 0x82bf
movl $0x14d, %edx            # imm = 0x14D
callq 0x2190
leaq 0x53e8(%rip), %rdi      # 0x82ea
leaq 0x51cd(%rip), %rsi      # 0x80d6
leaq 0x53af(%rip), %rcx      # 0x82bf
movl $0x151, %edx            # imm = 0x151
callq 0x2190
leaq 0x53c9(%rip), %rdi      # 0x82ea
leaq 0x51ae(%rip), %rsi      # 0x80d6
leaq 0x5390(%rip), %rcx      # 0x82bf
movl $0x155, %edx            # imm = 0x155
callq 0x2190
leaq 0x53aa(%rip), %rdi      # 0x82ea
leaq 0x518f(%rip), %rsi      # 0x80d6
leaq 0x5371(%rip), %rcx      # 0x82bf
movl $0x161, %edx            # imm = 0x161
callq 0x2190
leaq 0x538b(%rip), %rdi      # 0x82ea
leaq 0x5170(%rip), %rsi      # 0x80d6
leaq 0x5352(%rip), %rcx      # 0x82bf
movl $0x121, %edx            # imm = 0x121
callq 0x2190
leaq 0x536c(%rip), %rdi      # 0x82ea
leaq 0x5151(%rip), %rsi      # 0x80d6
leaq 0x5333(%rip), %rcx      # 0x82bf
movl $0x13a, %edx            # imm = 0x13A
callq 0x2190
leaq 0x534d(%rip), %rdi      # 0x82ea
leaq 0x5132(%rip), %rsi      # 0x80d6
leaq 0x5314(%rip), %rcx      # 0x82bf
movl $0x124, %edx            # imm = 0x124
callq 0x2190
leaq 0x532e(%rip), %rdi      # 0x82ea
leaq 0x5113(%rip), %rsi      # 0x80d6
leaq 0x52f5(%rip), %rcx      # 0x82bf
movl $0x13f, %edx            # imm = 0x13F
callq 0x2190
leaq 0x530f(%rip), %rdi      # 0x82ea
leaq 0x50f4(%rip), %rsi      # 0x80d6
leaq 0x52d6(%rip), %rcx      # 0x82bf
movl $0x142, %edx            # imm = 0x142
callq 0x2190
leaq 0x52f0(%rip), %rdi      # 0x82ea
leaq 0x50d5(%rip), %rsi      # 0x80d6
leaq 0x52b7(%rip), %rcx      # 0x82bf
movl $0x145, %edx            # imm = 0x145
callq 0x2190