#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ ref;
typedef int /*<<< orphan*/ out;
typedef int /*<<< orphan*/ inp;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_f_cipher();
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_new_mem_buf(unsigned char *, int);
int /*<<< orphan*/ BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/);
int BIO_read(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ BIO_set_cipher(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                  unsigned char const *, int /*<<< orphan*/ *,
                                  int /*<<< orphan*/);
int /*<<< orphan*/ EVP_aes_128_cbc();
int /*<<< orphan*/ EVP_aes_128_ctr();
scalar_t__ RAND_bytes(unsigned char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ memcmp(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int main() {
  BIO *b;
  static const unsigned char key[16] = {0};
  static unsigned char inp[1024] = {0};
  unsigned char out[1024], ref[1024];
  int i, lref, len;
  if (RAND_bytes(inp, sizeof(inp)) <= 0)
    return -1;
  b = BIO_new(BIO_f_cipher());
  if (!BIO_set_cipher(b, EVP_aes_128_cbc(), key, NULL, 0))
    return -1;
  BIO_push(b, BIO_new_mem_buf(inp, sizeof(inp)));
  lref = BIO_read(b, ref, sizeof(ref));
  BIO_free_all(b);
  for (i = 1; i < lref; i++) {
    b = BIO_new(BIO_f_cipher());
    if (!BIO_set_cipher(b, EVP_aes_128_cbc(), key, NULL, 0))
      return -1;
    BIO_push(b, BIO_new_mem_buf(inp, sizeof(inp)));
    memset(out, 0, sizeof(out));
    out[i] = ~ref[i];
    len = BIO_read(b, out, i);
    if (out[i] != (unsigned char)~ref[i]) {
      fprintf(stderr, "CBC output overstep@%d\n", i);
      return 1;
    }
    len += BIO_read(b, out + len, sizeof(out) - len);
    BIO_free_all(b);
    if (len != lref || memcmp(out, ref, len)) {
      fprintf(stderr, "CBC output mismatch@%d\n", i);
      return 2;
    }
  }
  for (i = 1; i < lref / 2; i++) {
    int delta;
    b = BIO_new(BIO_f_cipher());
    if (!BIO_set_cipher(b, EVP_aes_128_cbc(), key, NULL, 0))
      return -1;
    BIO_push(b, BIO_new_mem_buf(inp, sizeof(inp)));
    memset(out, 0, sizeof(out));
    for (len = 0; (delta = BIO_read(b, out + len, i));) {
      len += delta;
    }
    BIO_free_all(b);
    if (len != lref || memcmp(out, ref, len)) {
      fprintf(stderr, "CBC output mismatch@%d\n", i);
      return 3;
    }
  }
  b = BIO_new(BIO_f_cipher());
  if (!BIO_set_cipher(b, EVP_aes_128_ctr(), key, NULL, 0))
    return -1;
  BIO_push(b, BIO_new_mem_buf(inp, sizeof(inp)));
  lref = BIO_read(b, ref, sizeof(ref));
  BIO_free_all(b);
  for (i = 1; i < lref; i++) {
    b = BIO_new(BIO_f_cipher());
    if (!BIO_set_cipher(b, EVP_aes_128_ctr(), key, NULL, 0))
      return -1;
    BIO_push(b, BIO_new_mem_buf(inp, sizeof(inp)));
    memset(out, 0, sizeof(out));
    out[i] = ~ref[i];
    len = BIO_read(b, out, i);
    if (out[i] != (unsigned char)~ref[i]) {
      fprintf(stderr, "CTR output overstep@%d\n", i);
      return 4;
    }
    len += BIO_read(b, out + len, sizeof(out) - len);
    BIO_free_all(b);
    if (len != lref || memcmp(out, ref, len)) {
      fprintf(stderr, "CTR output mismatch@%d\n", i);
      return 5;
    }
  }
  for (i = 1; i < lref / 2; i++) {
    int delta;
    b = BIO_new(BIO_f_cipher());
    if (!BIO_set_cipher(b, EVP_aes_128_ctr(), key, NULL, 0))
      return -1;
    BIO_push(b, BIO_new_mem_buf(inp, sizeof(inp)));
    memset(out, 0, sizeof(out));
    for (len = 0; (delta = BIO_read(b, out + len, i));) {
      len += delta;
    }
    BIO_free_all(b);
    if (len != lref || memcmp(out, ref, len)) {
      fprintf(stderr, "CTR output mismatch@%d\n", i);
      return 6;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8a0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0x2eb7(%rip),%rdi
mov    $0x400,%esi
call   1050 <RAND_bytes@plt>
cmp    $0x0,%rax
jg     1209 <main+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    1a66 <main+0x896>
mov    $0x0,%al
call   10e0 <BIO_f_cipher@plt>
mov    %eax,%edi
call   10c0 <BIO_new@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x830(%rbp)
mov    $0x0,%al
call   10d0 <EVP_aes_128_cbc@plt>
mov    -0x830(%rbp),%rdi
mov    %eax,%esi
lea    0xdc3(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   10b0 <BIO_set_cipher@plt>
cmp    $0x0,%eax
jne    125e <main+0x8e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1a66 <main+0x896>
mov    -0x10(%rbp),%rax
mov    %rax,-0x838(%rbp)
lea    0x2e30(%rip),%rdi
mov    $0x400,%esi
call   10a0 <BIO_new_mem_buf@plt>
mov    -0x838(%rbp),%rdi
mov    %eax,%esi
call   1030 <BIO_push@plt>
mov    -0x10(%rbp),%rdi
lea    -0x810(%rbp),%rsi
mov    $0x400,%edx
call   1040 <BIO_read@plt>
mov    %eax,-0x818(%rbp)
mov    -0x10(%rbp),%rdi
call   10f0 <BIO_free_all@plt>
movl   $0x1,-0x814(%rbp)
mov    -0x814(%rbp),%eax
cmp    -0x818(%rbp),%eax
jge    14a0 <main+0x2d0>
mov    $0x0,%al
call   10e0 <BIO_f_cipher@plt>
mov    %eax,%edi
call   10c0 <BIO_new@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x840(%rbp)
mov    $0x0,%al
call   10d0 <EVP_aes_128_cbc@plt>
mov    -0x840(%rbp),%rdi
mov    %eax,%esi
lea    0xd04(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   10b0 <BIO_set_cipher@plt>
cmp    $0x0,%eax
jne    131d <main+0x14d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1a66 <main+0x896>
mov    -0x10(%rbp),%rax
mov    %rax,-0x848(%rbp)
lea    0x2d71(%rip),%rdi
mov    $0x400,%esi
call   10a0 <BIO_new_mem_buf@plt>
mov    -0x848(%rbp),%rdi
mov    %eax,%esi
call   1030 <BIO_push@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movslq -0x814(%rbp),%rax
movzbl -0x810(%rbp,%rax,1),%eax
ff
xor    $0xffffffff,%eax
mov    %al,%cl
movslq -0x814(%rbp),%rax
mov    %cl,-0x410(%rbp,%rax,1)
mov    -0x10(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    -0x814(%rbp),%edx
call   1040 <BIO_read@plt>
mov    %eax,-0x81c(%rbp)
movslq -0x814(%rbp),%rax
movzbl -0x410(%rbp,%rax,1),%eax
ff
movslq -0x814(%rbp),%rcx
movzbl -0x810(%rbp,%rcx,1),%ecx
ff
xor    $0xffffffff,%ecx
movzbl %cl,%ecx
cmp    %ecx,%eax
je     13eb <main+0x21b>
mov    0x2c15(%rip),%rax
mov    (%rax),%edi
mov    -0x814(%rbp),%edx
lea    0xc36(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1a66 <main+0x896>
mov    -0x10(%rbp),%rdi
lea    -0x410(%rbp),%rsi
movslq -0x81c(%rbp),%rax
add    %rax,%rsi
movslq -0x81c(%rbp),%rcx
mov    $0x400,%eax
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <BIO_read@plt>
add    -0x81c(%rbp),%eax
mov    %eax,-0x81c(%rbp)
mov    -0x10(%rbp),%rdi
call   10f0 <BIO_free_all@plt>
mov    -0x81c(%rbp),%eax
cmp    -0x818(%rbp),%eax
jne    1460 <main+0x290>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rsi
mov    -0x81c(%rbp),%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
je     1487 <main+0x2b7>
mov    0x2b79(%rip),%rax
mov    (%rax),%edi
mov    -0x814(%rbp),%edx
lea    0xbb2(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1a66 <main+0x896>
jmp    148c <main+0x2bc>
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
jmp    12b6 <main+0xe6>
movl   $0x1,-0x814(%rbp)
mov    -0x814(%rbp),%eax
mov    %eax,-0x84c(%rbp)
mov    -0x818(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x84c(%rbp),%eax
cmp    %ecx,%eax
jge    1634 <main+0x464>
mov    $0x0,%al
call   10e0 <BIO_f_cipher@plt>
mov    %eax,%edi
call   10c0 <BIO_new@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x858(%rbp)
mov    $0x0,%al
call   10d0 <EVP_aes_128_cbc@plt>
mov    -0x858(%rbp),%rdi
mov    %eax,%esi
lea    0xaf8(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   10b0 <BIO_set_cipher@plt>
cmp    $0x0,%eax
jne    1529 <main+0x359>
movl   $0xffffffff,-0x4(%rbp)
jmp    1a66 <main+0x896>
mov    -0x10(%rbp),%rax
mov    %rax,-0x860(%rbp)
lea    0x2b65(%rip),%rdi
mov    $0x400,%esi
call   10a0 <BIO_new_mem_buf@plt>
mov    -0x860(%rbp),%rdi
mov    %eax,%esi
call   1030 <BIO_push@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movl   $0x0,-0x81c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x410(%rbp),%rsi
movslq -0x81c(%rbp),%rax
add    %rax,%rsi
mov    -0x814(%rbp),%edx
call   1040 <BIO_read@plt>
mov    %eax,-0x820(%rbp)
cmp    $0x0,%eax
je     15b6 <main+0x3e6>
mov    -0x820(%rbp),%eax
add    -0x81c(%rbp),%eax
mov    %eax,-0x81c(%rbp)
jmp    1570 <main+0x3a0>
mov    -0x10(%rbp),%rdi
call   10f0 <BIO_free_all@plt>
mov    -0x81c(%rbp),%eax
cmp    -0x818(%rbp),%eax
jne    15f4 <main+0x424>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rsi
mov    -0x81c(%rbp),%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
je     161b <main+0x44b>
mov    0x29e5(%rip),%rax
mov    (%rax),%edi
mov    -0x814(%rbp),%edx
lea    0xa1e(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    1a66 <main+0x896>
jmp    1620 <main+0x450>
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
jmp    14aa <main+0x2da>
mov    $0x0,%al
call   10e0 <BIO_f_cipher@plt>
mov    %eax,%edi
call   10c0 <BIO_new@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x868(%rbp)
mov    $0x0,%al
call   1080 <EVP_aes_128_ctr@plt>
mov    -0x868(%rbp),%rdi
mov    %eax,%esi
lea    0x998(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   10b0 <BIO_set_cipher@plt>
cmp    $0x0,%eax
jne    1689 <main+0x4b9>
movl   $0xffffffff,-0x4(%rbp)
jmp    1a66 <main+0x896>
mov    -0x10(%rbp),%rax
mov    %rax,-0x870(%rbp)
lea    0x2a05(%rip),%rdi
mov    $0x400,%esi
call   10a0 <BIO_new_mem_buf@plt>
mov    -0x870(%rbp),%rdi
mov    %eax,%esi
call   1030 <BIO_push@plt>
mov    -0x10(%rbp),%rdi
lea    -0x810(%rbp),%rsi
mov    $0x400,%edx
call   1040 <BIO_read@plt>
mov    %eax,-0x818(%rbp)
mov    -0x10(%rbp),%rdi
call   10f0 <BIO_free_all@plt>
movl   $0x1,-0x814(%rbp)
mov    -0x814(%rbp),%eax
cmp    -0x818(%rbp),%eax
jge    18cb <main+0x6fb>
mov    $0x0,%al
call   10e0 <BIO_f_cipher@plt>
mov    %eax,%edi
call   10c0 <BIO_new@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x878(%rbp)
mov    $0x0,%al
call   1080 <EVP_aes_128_ctr@plt>
mov    -0x878(%rbp),%rdi
mov    %eax,%esi
lea    0x8d9(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   10b0 <BIO_set_cipher@plt>
cmp    $0x0,%eax
jne    1748 <main+0x578>
movl   $0xffffffff,-0x4(%rbp)
jmp    1a66 <main+0x896>
mov    -0x10(%rbp),%rax
mov    %rax,-0x880(%rbp)
lea    0x2946(%rip),%rdi
mov    $0x400,%esi
call   10a0 <BIO_new_mem_buf@plt>
mov    -0x880(%rbp),%rdi
mov    %eax,%esi
call   1030 <BIO_push@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movslq -0x814(%rbp),%rax
movzbl -0x810(%rbp,%rax,1),%eax
ff
xor    $0xffffffff,%eax
mov    %al,%cl
movslq -0x814(%rbp),%rax
mov    %cl,-0x410(%rbp,%rax,1)
mov    -0x10(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    -0x814(%rbp),%edx
call   1040 <BIO_read@plt>
mov    %eax,-0x81c(%rbp)
movslq -0x814(%rbp),%rax
movzbl -0x410(%rbp,%rax,1),%eax
ff
movslq -0x814(%rbp),%rcx
movzbl -0x810(%rbp,%rcx,1),%ecx
ff
xor    $0xffffffff,%ecx
movzbl %cl,%ecx
cmp    %ecx,%eax
je     1816 <main+0x646>
mov    0x27ea(%rip),%rax
mov    (%rax),%edi
mov    -0x814(%rbp),%edx
lea    0x83b(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x4,-0x4(%rbp)
jmp    1a66 <main+0x896>
mov    -0x10(%rbp),%rdi
lea    -0x410(%rbp),%rsi
movslq -0x81c(%rbp),%rax
add    %rax,%rsi
movslq -0x81c(%rbp),%rcx
mov    $0x400,%eax
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <BIO_read@plt>
add    -0x81c(%rbp),%eax
mov    %eax,-0x81c(%rbp)
mov    -0x10(%rbp),%rdi
call   10f0 <BIO_free_all@plt>
mov    -0x81c(%rbp),%eax
cmp    -0x818(%rbp),%eax
jne    188b <main+0x6bb>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rsi
mov    -0x81c(%rbp),%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
je     18b2 <main+0x6e2>
mov    0x274e(%rip),%rax
mov    (%rax),%edi
mov    -0x814(%rbp),%edx
lea    0x7b7(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x5,-0x4(%rbp)
jmp    1a66 <main+0x896>
jmp    18b7 <main+0x6e7>
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
jmp    16e1 <main+0x511>
movl   $0x1,-0x814(%rbp)
mov    -0x814(%rbp),%eax
mov    %eax,-0x884(%rbp)
mov    -0x818(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x884(%rbp),%eax
cmp    %ecx,%eax
jge    1a5f <main+0x88f>
mov    $0x0,%al
call   10e0 <BIO_f_cipher@plt>
mov    %eax,%edi
call   10c0 <BIO_new@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x890(%rbp)
mov    $0x0,%al
call   1080 <EVP_aes_128_ctr@plt>
mov    -0x890(%rbp),%rdi
mov    %eax,%esi
lea    0x6cd(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   10b0 <BIO_set_cipher@plt>
cmp    $0x0,%eax
jne    1954 <main+0x784>
movl   $0xffffffff,-0x4(%rbp)
jmp    1a66 <main+0x896>
mov    -0x10(%rbp),%rax
mov    %rax,-0x898(%rbp)
lea    0x273a(%rip),%rdi
mov    $0x400,%esi
call   10a0 <BIO_new_mem_buf@plt>
mov    -0x898(%rbp),%rdi
mov    %eax,%esi
call   1030 <BIO_push@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movl   $0x0,-0x81c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x410(%rbp),%rsi
movslq -0x81c(%rbp),%rax
add    %rax,%rsi
mov    -0x814(%rbp),%edx
call   1040 <BIO_read@plt>
mov    %eax,-0x824(%rbp)
cmp    $0x0,%eax
je     19e1 <main+0x811>
mov    -0x824(%rbp),%eax
add    -0x81c(%rbp),%eax
mov    %eax,-0x81c(%rbp)
jmp    199b <main+0x7cb>
mov    -0x10(%rbp),%rdi
call   10f0 <BIO_free_all@plt>
mov    -0x81c(%rbp),%eax
cmp    -0x818(%rbp),%eax
jne    1a1f <main+0x84f>
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rsi
mov    -0x81c(%rbp),%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
je     1a46 <main+0x876>
mov    0x25ba(%rip),%rax
mov    (%rax),%edi
mov    -0x814(%rbp),%edx
lea    0x623(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x6,-0x4(%rbp)
jmp    1a66 <main+0x896>
jmp    1a4b <main+0x87b>
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
jmp    18d5 <main+0x705>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
lea    0x2eb8(%rip),%rdi
mov    $0x400,%esi
call   1050 <RAND_bytes@plt>
test   %rax,%rax
jle    16c1 <main+0x4f1>
xor    %eax,%eax
call   10e0 <BIO_f_cipher@plt>
mov    %eax,%edi
call   10c0 <BIO_new@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10d0 <EVP_aes_128_cbc@plt>
lea    0xde6(%rip),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10b0 <BIO_set_cipher@plt>
test   %eax,%eax
je     16c1 <main+0x4f1>
lea    0x2e68(%rip),%rdi
mov    $0x400,%esi
call   10a0 <BIO_new_mem_buf@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <BIO_push@plt>
lea    0x410(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x400,%edx
call   1040 <BIO_read@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   10f0 <BIO_free_all@plt>
cmp    $0x2,%ebp
jl     145d <main+0x28d>
mov    %ebp,%r14d
mov    $0x1,%ebx
lea    0x10(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10e0 <BIO_f_cipher@plt>
mov    %eax,%edi
call   10c0 <BIO_new@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   10d0 <EVP_aes_128_cbc@plt>
mov    %rbp,%rdi
mov    %eax,%esi
lea    0xd4c(%rip),%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10b0 <BIO_set_cipher@plt>
test   %eax,%eax
je     16c1 <main+0x4f1>
lea    0x2dd3(%rip),%rdi
mov    $0x400,%esi
call   10a0 <BIO_new_mem_buf@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1030 <BIO_push@plt>
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movzbl 0x410(%rsp,%rbx,1),%eax
not    %al
mov    %al,0x10(%rsp,%rbx,1)
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1040 <BIO_read@plt>
movzbl 0x410(%rsp,%rbx,1),%ecx
not    %cl
cmp    %cl,0x10(%rsp,%rbx,1)
jne    16f8 <main+0x528>
movslq %eax,%r15
lea    (%rsp,%r15,1),%rsi
add    $0x10,%rsi
mov    $0x400,%edx
sub    %r15d,%edx
mov    %rbp,%rdi
call   1040 <BIO_read@plt>
mov    %eax,%r12d
add    %r15d,%r12d
mov    %rbp,%rdi
call   10f0 <BIO_free_all@plt>
cmp    %r14d,%r12d
jne    16da <main+0x50a>
mov    %r13,%rdi
lea    0x410(%rsp),%rsi
mov    %r14d,%edx
call   1070 <memcmp@plt>
test   %rax,%rax
jne    16da <main+0x50a>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1290 <main+0xc0>
cmp    $0x4,%r14d
jl     145d <main+0x28d>
mov    %r14d,%eax
shr    %eax
mov    %eax,0xc(%rsp)
mov    $0x1,%ebx
lea    0x10(%rsp),%r12
xor    %eax,%eax
call   10e0 <BIO_f_cipher@plt>
mov    %eax,%edi
call   10c0 <BIO_new@plt>
mov    %rax,%r13
xor    %eax,%eax
call   10d0 <EVP_aes_128_cbc@plt>
mov    %r13,%rdi
mov    %eax,%esi
lea    0xc45(%rip),%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10b0 <BIO_set_cipher@plt>
test   %eax,%eax
je     16c1 <main+0x4f1>
lea    0x2ccc(%rip),%rdi
mov    $0x400,%esi
call   10a0 <BIO_new_mem_buf@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   1030 <BIO_push@plt>
xor    %ebp,%ebp
mov    %r12,%r15
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
nopl   0x0(%rax)
mov    %ebp,%r12d
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rsi
add    $0x10,%rsi
mov    %r13,%rdi
mov    %ebx,%edx
call   1040 <BIO_read@plt>
lea    (%rax,%r12,1),%ebp
test   %eax,%eax
jne    1400 <main+0x230>
mov    %r13,%rdi
call   10f0 <BIO_free_all@plt>
cmp    %r14d,%r12d
jne    1755 <main+0x585>
mov    %r15,%r12
mov    %r15,%rdi
lea    0x410(%rsp),%rsi
mov    %r14d,%edx
call   1070 <memcmp@plt>
test   %rax,%rax
jne    1755 <main+0x585>
add    $0x1,%ebx
cmp    0xc(%rsp),%ebx
jne    1397 <main+0x1c7>
xor    %ebp,%ebp
xor    %eax,%eax
call   10e0 <BIO_f_cipher@plt>
mov    %eax,%edi
call   10c0 <BIO_new@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1080 <EVP_aes_128_ctr@plt>
lea    0xb82(%rip),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10b0 <BIO_set_cipher@plt>
test   %eax,%eax
je     16c1 <main+0x4f1>
lea    0x2c04(%rip),%rdi
mov    $0x400,%esi
call   10a0 <BIO_new_mem_buf@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <BIO_push@plt>
lea    0x410(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x400,%edx
call   1040 <BIO_read@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   10f0 <BIO_free_all@plt>
cmp    $0x2,%r14d
jl     16c6 <main+0x4f6>
mov    %r14d,%r14d
mov    $0x1,%ebx
lea    0x10(%rsp),%r13
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10e0 <BIO_f_cipher@plt>
mov    %eax,%edi
call   10c0 <BIO_new@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1080 <EVP_aes_128_ctr@plt>
mov    %rbp,%rdi
mov    %eax,%esi
lea    0xaec(%rip),%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10b0 <BIO_set_cipher@plt>
test   %eax,%eax
je     16c1 <main+0x4f1>
lea    0x2b73(%rip),%rdi
mov    $0x400,%esi
call   10a0 <BIO_new_mem_buf@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1030 <BIO_push@plt>
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movzbl 0x410(%rsp,%rbx,1),%eax
not    %al
mov    %al,0x10(%rsp,%rbx,1)
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1040 <BIO_read@plt>
movzbl 0x410(%rsp,%rbx,1),%ecx
not    %cl
cmp    %cl,0x10(%rsp,%rbx,1)
jne    1734 <main+0x564>
movslq %eax,%r15
lea    (%rsp,%r15,1),%rsi
add    $0x10,%rsi
mov    $0x400,%edx
sub    %r15d,%edx
mov    %rbp,%rdi
call   1040 <BIO_read@plt>
mov    %eax,%r12d
add    %r15d,%r12d
mov    %rbp,%rdi
call   10f0 <BIO_free_all@plt>
cmp    %r14d,%r12d
jne    1716 <main+0x546>
mov    %r13,%rdi
lea    0x410(%rsp),%rsi
mov    %r14d,%edx
call   1070 <memcmp@plt>
test   %rax,%rax
jne    1716 <main+0x546>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    14f0 <main+0x320>
xor    %ebp,%ebp
cmp    $0x4,%r14d
jl     16c6 <main+0x4f6>
mov    %r14d,%eax
shr    %eax
mov    %eax,0xc(%rsp)
mov    $0x1,%ebx
lea    0x10(%rsp),%r12
xor    %eax,%eax
call   10e0 <BIO_f_cipher@plt>
mov    %eax,%edi
call   10c0 <BIO_new@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1080 <EVP_aes_128_ctr@plt>
mov    %rbp,%rdi
mov    %eax,%esi
lea    0x9e3(%rip),%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10b0 <BIO_set_cipher@plt>
test   %eax,%eax
je     16c1 <main+0x4f1>
lea    0x2a6a(%rip),%rdi
mov    $0x400,%esi
call   10a0 <BIO_new_mem_buf@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1030 <BIO_push@plt>
xor    %r13d,%r13d
mov    %r12,%r15
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
nop
mov    %r13d,%r12d
movslq %r13d,%rax
lea    (%rsp,%rax,1),%rsi
add    $0x10,%rsi
mov    %rbp,%rdi
mov    %ebx,%edx
call   1040 <BIO_read@plt>
lea    (%rax,%r12,1),%r13d
test   %eax,%eax
jne    1660 <main+0x490>
mov    %rbp,%rdi
call   10f0 <BIO_free_all@plt>
cmp    %r14d,%r12d
jne    1776 <main+0x5a6>
mov    %r15,%r12
mov    %r15,%rdi
lea    0x410(%rsp),%rsi
mov    %r14d,%edx
call   1070 <memcmp@plt>
test   %rax,%rax
jne    1776 <main+0x5a6>
add    $0x1,%ebx
xor    %ebp,%ebp
cmp    0xc(%rsp),%ebx
jne    15f9 <main+0x429>
jmp    16c6 <main+0x4f6>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x28ff(%rip),%rax
mov    (%rax),%edi
lea    0x93e(%rip),%rsi
mov    %ebx,%edx
call   1090 <fprintf@plt>
mov    $0x2,%ebp
jmp    16c6 <main+0x4f6>
mov    0x28e1(%rip),%rax
mov    (%rax),%edi
lea    0x908(%rip),%rsi
mov    %ebx,%edx
call   1090 <fprintf@plt>
mov    $0x1,%ebp
jmp    16c6 <main+0x4f6>
mov    0x28c3(%rip),%rax
mov    (%rax),%edi
lea    0x932(%rip),%rsi
mov    %ebx,%edx
call   1090 <fprintf@plt>
mov    $0x5,%ebp
jmp    16c6 <main+0x4f6>
mov    0x28a5(%rip),%rax
mov    (%rax),%edi
lea    0x8fc(%rip),%rsi
mov    %ebx,%edx
call   1090 <fprintf@plt>
mov    $0x4,%ebp
jmp    16c6 <main+0x4f6>
mov    0x2884(%rip),%rax
mov    (%rax),%edi
lea    0x8c3(%rip),%rsi
mov    %ebx,%edx
call   1090 <fprintf@plt>
mov    $0x3,%ebp
jmp    16c6 <main+0x4f6>
mov    0x2863(%rip),%rax
mov    (%rax),%edi
lea    0x8d2(%rip),%rsi
mov    %ebx,%edx
call   1090 <fprintf@plt>
mov    $0x6,%ebp
jmp    16c6 <main+0x4f6>

LLVM IR (-O0):
@main.key = internal constant [16 x i8] zeroinitializer
@main.inp = internal global [1024 x i8] zeroinitializer
@stderr = global i32 0
@.str = [24 x i8] c"CBC output overstep@%d\0A\00"
@.str.1 = [24 x i8] c"CBC output mismatch@%d\0A\00"
@.str.2 = [24 x i8] c"CTR output overstep@%d\0A\00"
@.str.3 = [24 x i8] c"CTR output mismatch@%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = call i64 @RAND_bytes(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.inp, i64 0, i64 0), i32 1024)
%11 = icmp sle i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %0
store i32 -1, i32* %1
br label %318
13: ; preds = %0
%14 = call i32 (...) @BIO_f_cipher()
%15 = call i32* @BIO_new(i32 %14)
store i32* %15, i32** %2
%16 = load i32*, i32** %2
%17 = call i32 (...) @EVP_aes_128_cbc()
%18 = call i32 @BIO_set_cipher(i32* %16, i32 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @main.key, i64 0, i64 0), i32* null, i32 0)
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %13
store i32 -1, i32* %1
br label %318
21: ; preds = %13
%22 = load i32*, i32** %2
%23 = call i32 @BIO_new_mem_buf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.inp, i64 0, i64 0), i32 1024)
%24 = call i32 @BIO_push(i32* %22, i32 %23)
%25 = load i32*, i32** %2
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%27 = call i32 @BIO_read(i32* %25, i8* %26, i32 1024)
store i32 %27, i32* %6
%28 = load i32*, i32** %2
%29 = call i32 @BIO_free_all(i32* %28)
store i32 1, i32* %5
br label %30
30: ; preds = %109, %21
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %112
34: ; preds = %30
%35 = call i32 (...) @BIO_f_cipher()
%36 = call i32* @BIO_new(i32 %35)
store i32* %36, i32** %2
%37 = load i32*, i32** %2
%38 = call i32 (...) @EVP_aes_128_cbc()
%39 = call i32 @BIO_set_cipher(i32* %37, i32 %38, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @main.key, i64 0, i64 0), i32* null, i32 0)
%40 = icmp ne i32 %39, 0
br i1 %40, label %42, label %41
41: ; preds = %34
store i32 -1, i32* %1
br label %318
42: ; preds = %34
%43 = load i32*, i32** %2
%44 = call i32 @BIO_new_mem_buf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.inp, i64 0, i64 0), i32 1024)
%45 = call i32 @BIO_push(i32* %43, i32 %44)
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%47 = call i32 @memset(i8* %46, i32 0, i32 1024)
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = zext i8 %51 to i32
%53 = xor i32 %52, -1
%54 = trunc i32 %53 to i8
%55 = load i32, i32* %5
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %56
store i8 %54, i8* %57
%58 = load i32*, i32** %2
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%60 = load i32, i32* %5
%61 = call i32 @BIO_read(i32* %58, i8* %59, i32 %60)
store i32 %61, i32* %7
%62 = load i32, i32* %5
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %63
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = load i32, i32* %5
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %68
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = xor i32 %71, -1
%73 = trunc i32 %72 to i8
%74 = zext i8 %73 to i32
%75 = icmp ne i32 %66, %74
br i1 %75, label %76, label %80
76: ; preds = %42
%77 = load i32, i32* @stderr
%78 = load i32, i32* %5
%79 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %78)
store i32 1, i32* %1
br label %318
80: ; preds = %42
%81 = load i32*, i32** %2
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%83 = load i32, i32* %7
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %82, i64 %84
%86 = load i32, i32* %7
%87 = sext i32 %86 to i64
%88 = sub i64 1024, %87
%89 = trunc i64 %88 to i32
%90 = call i32 @BIO_read(i32* %81, i8* %85, i32 %89)
%91 = load i32, i32* %7
%92 = add nsw i32 %91, %90
store i32 %92, i32* %7
%93 = load i32*, i32** %2
%94 = call i32 @BIO_free_all(i32* %93)
%95 = load i32, i32* %7
%96 = load i32, i32* %6
%97 = icmp ne i32 %95, %96
br i1 %97, label %104, label %98
98: ; preds = %80
%99 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%100 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%101 = load i32, i32* %7
%102 = call i64 @memcmp(i8* %99, i8* %100, i32 %101)
%103 = icmp ne i64 %102, 0
br i1 %103, label %104, label %108
104: ; preds = %98, %80
%105 = load i32, i32* @stderr
%106 = load i32, i32* %5
%107 = call i32 @fprintf(i32 %105, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %106)
store i32 2, i32* %1
br label %318
108: ; preds = %98
br label %109
109: ; preds = %108
%110 = load i32, i32* %5
%111 = add nsw i32 %110, 1
store i32 %111, i32* %5
br label %30
112: ; preds = %30
store i32 1, i32* %5
br label %113
113: ; preds = %162, %112
%114 = load i32, i32* %5
%115 = load i32, i32* %6
%116 = sdiv i32 %115, 2
%117 = icmp slt i32 %114, %116
br i1 %117, label %118, label %165
118: ; preds = %113
%119 = call i32 (...) @BIO_f_cipher()
%120 = call i32* @BIO_new(i32 %119)
store i32* %120, i32** %2
%121 = load i32*, i32** %2
%122 = call i32 (...) @EVP_aes_128_cbc()
%123 = call i32 @BIO_set_cipher(i32* %121, i32 %122, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @main.key, i64 0, i64 0), i32* null, i32 0)
%124 = icmp ne i32 %123, 0
br i1 %124, label %126, label %125
125: ; preds = %118
store i32 -1, i32* %1
br label %318
126: ; preds = %118
%127 = load i32*, i32** %2
%128 = call i32 @BIO_new_mem_buf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.inp, i64 0, i64 0), i32 1024)
%129 = call i32 @BIO_push(i32* %127, i32 %128)
%130 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%131 = call i32 @memset(i8* %130, i32 0, i32 1024)
store i32 0, i32* %7
br label %132
132: ; preds = %141, %126
%133 = load i32*, i32** %2
%134 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%135 = load i32, i32* %7
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds i8, i8* %134, i64 %136
%138 = load i32, i32* %5
%139 = call i32 @BIO_read(i32* %133, i8* %137, i32 %138)
store i32 %139, i32* %8
%140 = icmp ne i32 %139, 0
br i1 %140, label %141, label %145
141: ; preds = %132
%142 = load i32, i32* %8
%143 = load i32, i32* %7
%144 = add nsw i32 %143, %142
store i32 %144, i32* %7
br label %132
145: ; preds = %132
%146 = load i32*, i32** %2
%147 = call i32 @BIO_free_all(i32* %146)
%148 = load i32, i32* %7
%149 = load i32, i32* %6
%150 = icmp ne i32 %148, %149
br i1 %150, label %157, label %151
151: ; preds = %145
%152 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%153 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%154 = load i32, i32* %7
%155 = call i64 @memcmp(i8* %152, i8* %153, i32 %154)
%156 = icmp ne i64 %155, 0
br i1 %156, label %157, label %161
157: ; preds = %151, %145
%158 = load i32, i32* @stderr
%159 = load i32, i32* %5
%160 = call i32 @fprintf(i32 %158, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %159)
store i32 3, i32* %1
br label %318
161: ; preds = %151
br label %162
162: ; preds = %161
%163 = load i32, i32* %5
%164 = add nsw i32 %163, 1
store i32 %164, i32* %5
br label %113
165: ; preds = %113
%166 = call i32 (...) @BIO_f_cipher()
%167 = call i32* @BIO_new(i32 %166)
store i32* %167, i32** %2
%168 = load i32*, i32** %2
%169 = call i32 (...) @EVP_aes_128_ctr()
%170 = call i32 @BIO_set_cipher(i32* %168, i32 %169, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @main.key, i64 0, i64 0), i32* null, i32 0)
%171 = icmp ne i32 %170, 0
br i1 %171, label %173, label %172
172: ; preds = %165
store i32 -1, i32* %1
br label %318
173: ; preds = %165
%174 = load i32*, i32** %2
%175 = call i32 @BIO_new_mem_buf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.inp, i64 0, i64 0), i32 1024)
%176 = call i32 @BIO_push(i32* %174, i32 %175)
%177 = load i32*, i32** %2
%178 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%179 = call i32 @BIO_read(i32* %177, i8* %178, i32 1024)
store i32 %179, i32* %6
%180 = load i32*, i32** %2
%181 = call i32 @BIO_free_all(i32* %180)
store i32 1, i32* %5
br label %182
182: ; preds = %261, %173
%183 = load i32, i32* %5
%184 = load i32, i32* %6
%185 = icmp slt i32 %183, %184
br i1 %185, label %186, label %264
186: ; preds = %182
%187 = call i32 (...) @BIO_f_cipher()
%188 = call i32* @BIO_new(i32 %187)
store i32* %188, i32** %2
%189 = load i32*, i32** %2
%190 = call i32 (...) @EVP_aes_128_ctr()
%191 = call i32 @BIO_set_cipher(i32* %189, i32 %190, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @main.key, i64 0, i64 0), i32* null, i32 0)
%192 = icmp ne i32 %191, 0
br i1 %192, label %194, label %193
193: ; preds = %186
store i32 -1, i32* %1
br label %318
194: ; preds = %186
%195 = load i32*, i32** %2
%196 = call i32 @BIO_new_mem_buf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.inp, i64 0, i64 0), i32 1024)
%197 = call i32 @BIO_push(i32* %195, i32 %196)
%198 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%199 = call i32 @memset(i8* %198, i32 0, i32 1024)
%200 = load i32, i32* %5
%201 = sext i32 %200 to i64
%202 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %201
%203 = load i8, i8* %202
%204 = zext i8 %203 to i32
%205 = xor i32 %204, -1
%206 = trunc i32 %205 to i8
%207 = load i32, i32* %5
%208 = sext i32 %207 to i64
%209 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %208
store i8 %206, i8* %209
%210 = load i32*, i32** %2
%211 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%212 = load i32, i32* %5
%213 = call i32 @BIO_read(i32* %210, i8* %211, i32 %212)
store i32 %213, i32* %7
%214 = load i32, i32* %5
%215 = sext i32 %214 to i64
%216 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %215
%217 = load i8, i8* %216
%218 = zext i8 %217 to i32
%219 = load i32, i32* %5
%220 = sext i32 %219 to i64
%221 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %220
%222 = load i8, i8* %221
%223 = zext i8 %222 to i32
%224 = xor i32 %223, -1
%225 = trunc i32 %224 to i8
%226 = zext i8 %225 to i32
%227 = icmp ne i32 %218, %226
br i1 %227, label %228, label %232
228: ; preds = %194
%229 = load i32, i32* @stderr
%230 = load i32, i32* %5
%231 = call i32 @fprintf(i32 %229, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %230)
store i32 4, i32* %1
br label %318
232: ; preds = %194
%233 = load i32*, i32** %2
%234 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%235 = load i32, i32* %7
%236 = sext i32 %235 to i64
%237 = getelementptr inbounds i8, i8* %234, i64 %236
%238 = load i32, i32* %7
%239 = sext i32 %238 to i64
%240 = sub i64 1024, %239
%241 = trunc i64 %240 to i32
%242 = call i32 @BIO_read(i32* %233, i8* %237, i32 %241)
%243 = load i32, i32* %7
%244 = add nsw i32 %243, %242
store i32 %244, i32* %7
%245 = load i32*, i32** %2
%246 = call i32 @BIO_free_all(i32* %245)
%247 = load i32, i32* %7
%248 = load i32, i32* %6
%249 = icmp ne i32 %247, %248
br i1 %249, label %256, label %250
250: ; preds = %232
%251 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%252 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%253 = load i32, i32* %7
%254 = call i64 @memcmp(i8* %251, i8* %252, i32 %253)
%255 = icmp ne i64 %254, 0
br i1 %255, label %256, label %260
256: ; preds = %250, %232
%257 = load i32, i32* @stderr
%258 = load i32, i32* %5
%259 = call i32 @fprintf(i32 %257, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %258)
store i32 5, i32* %1
br label %318
260: ; preds = %250
br label %261
261: ; preds = %260
%262 = load i32, i32* %5
%263 = add nsw i32 %262, 1
store i32 %263, i32* %5
br label %182
264: ; preds = %182
store i32 1, i32* %5
br label %265
265: ; preds = %314, %264
%266 = load i32, i32* %5
%267 = load i32, i32* %6
%268 = sdiv i32 %267, 2
%269 = icmp slt i32 %266, %268
br i1 %269, label %270, label %317
270: ; preds = %265
%271 = call i32 (...) @BIO_f_cipher()
%272 = call i32* @BIO_new(i32 %271)
store i32* %272, i32** %2
%273 = load i32*, i32** %2
%274 = call i32 (...) @EVP_aes_128_ctr()
%275 = call i32 @BIO_set_cipher(i32* %273, i32 %274, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @main.key, i64 0, i64 0), i32* null, i32 0)
%276 = icmp ne i32 %275, 0
br i1 %276, label %278, label %277
277: ; preds = %270
store i32 -1, i32* %1
br label %318
278: ; preds = %270
%279 = load i32*, i32** %2
%280 = call i32 @BIO_new_mem_buf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.inp, i64 0, i64 0), i32 1024)
%281 = call i32 @BIO_push(i32* %279, i32 %280)
%282 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%283 = call i32 @memset(i8* %282, i32 0, i32 1024)
store i32 0, i32* %7
br label %284
284: ; preds = %293, %278
%285 = load i32*, i32** %2
%286 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%287 = load i32, i32* %7
%288 = sext i32 %287 to i64
%289 = getelementptr inbounds i8, i8* %286, i64 %288
%290 = load i32, i32* %5
%291 = call i32 @BIO_read(i32* %285, i8* %289, i32 %290)
store i32 %291, i32* %9
%292 = icmp ne i32 %291, 0
br i1 %292, label %293, label %297
293: ; preds = %284
%294 = load i32, i32* %9
%295 = load i32, i32* %7
%296 = add nsw i32 %295, %294
store i32 %296, i32* %7
br label %284
297: ; preds = %284
%298 = load i32*, i32** %2
%299 = call i32 @BIO_free_all(i32* %298)
%300 = load i32, i32* %7
%301 = load i32, i32* %6
%302 = icmp ne i32 %300, %301
br i1 %302, label %309, label %303
303: ; preds = %297
%304 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%305 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%306 = load i32, i32* %7
%307 = call i64 @memcmp(i8* %304, i8* %305, i32 %306)
%308 = icmp ne i64 %307, 0
br i1 %308, label %309, label %313
309: ; preds = %303, %297
%310 = load i32, i32* @stderr
%311 = load i32, i32* %5
%312 = call i32 @fprintf(i32 %310, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %311)
store i32 6, i32* %1
br label %318
313: ; preds = %303
br label %314
314: ; preds = %313
%315 = load i32, i32* %5
%316 = add nsw i32 %315, 1
store i32 %316, i32* %5
br label %265
317: ; preds = %265
store i32 0, i32* %1
br label %318
318: ; preds = %317, %309, %277, %256, %228, %193, %172, %157, %125, %104, %76, %41, %20, %12
%319 = load i32, i32* %1
ret i32 %319
}

LLVM IR (-O2):
@main.key = internal constant [16 x i8] zeroinitializer
@main.inp = internal global [1024 x i8] zeroinitializer
@stderr = global i32 0
@.str = [24 x i8] c"CBC output overstep@%d\0A\00"
@.str.1 = [24 x i8] c"CBC output mismatch@%d\0A\00"
@.str.2 = [24 x i8] c"CTR output overstep@%d\0A\00"
@.str.3 = [24 x i8] c"CTR output mismatch@%d\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = tail call i64 @RAND_bytes(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.inp, i64 0, i64 0), i32 1024)
%6 = icmp slt i64 %5, 1
br i1 %6, label %189, label %7
7: ; preds = %0
%8 = tail call i32 (...) @BIO_f_cipher()
%9 = tail call i32* @BIO_new(i32 %8)
%10 = tail call i32 (...) @EVP_aes_128_cbc()
%11 = tail call i32 @BIO_set_cipher(i32* %9, i32 %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @main.key, i64 0, i64 0), i32* null, i32 0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %189, label %13
13: ; preds = %7
%14 = tail call i32 @BIO_new_mem_buf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.inp, i64 0, i64 0), i32 1024)
%15 = tail call i32 @BIO_push(i32* %9, i32 %14)
%16 = call i32 @BIO_read(i32* %9, i8* %4, i32 1024)
%17 = call i32 @BIO_free_all(i32* %9)
%18 = icmp sgt i32 %16, 1
br i1 %18, label %19, label %98
19: ; preds = %13
%20 = zext i32 %16 to i64
br label %25
21: ; preds = %65
%22 = icmp sgt i32 %16, 3
br i1 %22, label %23, label %98
23: ; preds = %21
%24 = lshr i32 %16, 1
br label %68
25: ; preds = %19, %65
%26 = phi i64 [ 1, %19 ], [ %66, %65 ]
%27 = call i32 (...) @BIO_f_cipher()
%28 = call i32* @BIO_new(i32 %27)
%29 = call i32 (...) @EVP_aes_128_cbc()
%30 = call i32 @BIO_set_cipher(i32* %28, i32 %29, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @main.key, i64 0, i64 0), i32* null, i32 0)
%31 = icmp eq i32 %30, 0
br i1 %31, label %189, label %32
32: ; preds = %25
%33 = call i32 @BIO_new_mem_buf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.inp, i64 0, i64 0), i32 1024)
%34 = call i32 @BIO_push(i32* %28, i32 %33)
%35 = call i32 @memset(i8* %3, i32 0, i32 1024)
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %26
%37 = load i8, i8* %36
%38 = xor i8 %37, -1
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %26
store i8 %38, i8* %39
%40 = trunc i64 %26 to i32
%41 = call i32 @BIO_read(i32* %28, i8* %3, i32 %40)
%42 = load i8, i8* %39
%43 = load i8, i8* %36
%44 = xor i8 %43, -1
%45 = icmp eq i8 %42, %44
br i1 %45, label %50, label %46
46: ; preds = %32
%47 = trunc i64 %26 to i32
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %47)
br label %189
50: ; preds = %32
%51 = sext i32 %41 to i64
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %51
%53 = sub i32 1024, %41
%54 = call i32 @BIO_read(i32* %28, i8* %52, i32 %53)
%55 = add nsw i32 %54, %41
%56 = call i32 @BIO_free_all(i32* %28)
%57 = icmp eq i32 %55, %16
br i1 %57, label %58, label %61
58: ; preds = %50
%59 = call i64 @memcmp(i8* %3, i8* %4, i32 %16)
%60 = icmp eq i64 %59, 0
br i1 %60, label %65, label %61
61: ; preds = %58, %50
%62 = trunc i64 %26 to i32
%63 = load i32, i32* @stderr
%64 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %62)
br label %189
65: ; preds = %58
%66 = add nuw nsw i64 %26, 1
%67 = icmp eq i64 %66, %20
br i1 %67, label %21, label %25
68: ; preds = %23, %95
%69 = phi i32 [ %96, %95 ], [ 1, %23 ]
%70 = call i32 (...) @BIO_f_cipher()
%71 = call i32* @BIO_new(i32 %70)
%72 = call i32 (...) @EVP_aes_128_cbc()
%73 = call i32 @BIO_set_cipher(i32* %71, i32 %72, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @main.key, i64 0, i64 0), i32* null, i32 0)
%74 = icmp eq i32 %73, 0
br i1 %74, label %189, label %75
75: ; preds = %68
%76 = call i32 @BIO_new_mem_buf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.inp, i64 0, i64 0), i32 1024)
%77 = call i32 @BIO_push(i32* %71, i32 %76)
%78 = call i32 @memset(i8* %3, i32 0, i32 1024)
br label %79
79: ; preds = %79, %75
%80 = phi i32 [ 0, %75 ], [ %85, %79 ]
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %81
%83 = call i32 @BIO_read(i32* %71, i8* %82, i32 %69)
%84 = icmp eq i32 %83, 0
%85 = add nsw i32 %83, %80
br i1 %84, label %86, label %79
86: ; preds = %79
%87 = call i32 @BIO_free_all(i32* %71)
%88 = icmp eq i32 %80, %16
br i1 %88, label %89, label %92
89: ; preds = %86
%90 = call i64 @memcmp(i8* %3, i8* %4, i32 %16)
%91 = icmp eq i64 %90, 0
br i1 %91, label %95, label %92
92: ; preds = %89, %86
%93 = load i32, i32* @stderr
%94 = call i32 @fprintf(i32 %93, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %69)
br label %189
95: ; preds = %89
%96 = add nuw nsw i32 %69, 1
%97 = icmp eq i32 %96, %24
br i1 %97, label %98, label %68
98: ; preds = %95, %13, %21
%99 = call i32 (...) @BIO_f_cipher()
%100 = call i32* @BIO_new(i32 %99)
%101 = call i32 (...) @EVP_aes_128_ctr()
%102 = call i32 @BIO_set_cipher(i32* %100, i32 %101, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @main.key, i64 0, i64 0), i32* null, i32 0)
%103 = icmp eq i32 %102, 0
br i1 %103, label %189, label %104
104: ; preds = %98
%105 = call i32 @BIO_new_mem_buf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.inp, i64 0, i64 0), i32 1024)
%106 = call i32 @BIO_push(i32* %100, i32 %105)
%107 = call i32 @BIO_read(i32* %100, i8* %4, i32 1024)
%108 = call i32 @BIO_free_all(i32* %100)
%109 = icmp sgt i32 %107, 1
br i1 %109, label %110, label %189
110: ; preds = %104
%111 = zext i32 %107 to i64
br label %116
112: ; preds = %156
%113 = icmp sgt i32 %107, 3
br i1 %113, label %114, label %189
114: ; preds = %112
%115 = lshr i32 %107, 1
br label %159
116: ; preds = %110, %156
%117 = phi i64 [ 1, %110 ], [ %157, %156 ]
%118 = call i32 (...) @BIO_f_cipher()
%119 = call i32* @BIO_new(i32 %118)
%120 = call i32 (...) @EVP_aes_128_ctr()
%121 = call i32 @BIO_set_cipher(i32* %119, i32 %120, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @main.key, i64 0, i64 0), i32* null, i32 0)
%122 = icmp eq i32 %121, 0
br i1 %122, label %189, label %123
123: ; preds = %116
%124 = call i32 @BIO_new_mem_buf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.inp, i64 0, i64 0), i32 1024)
%125 = call i32 @BIO_push(i32* %119, i32 %124)
%126 = call i32 @memset(i8* %3, i32 0, i32 1024)
%127 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %117
%128 = load i8, i8* %127
%129 = xor i8 %128, -1
%130 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %117
store i8 %129, i8* %130
%131 = trunc i64 %117 to i32
%132 = call i32 @BIO_read(i32* %119, i8* %3, i32 %131)
%133 = load i8, i8* %130
%134 = load i8, i8* %127
%135 = xor i8 %134, -1
%136 = icmp eq i8 %133, %135
br i1 %136, label %141, label %137
137: ; preds = %123
%138 = trunc i64 %117 to i32
%139 = load i32, i32* @stderr
%140 = call i32 @fprintf(i32 %139, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %138)
br label %189
141: ; preds = %123
%142 = sext i32 %132 to i64
%143 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %142
%144 = sub i32 1024, %132
%145 = call i32 @BIO_read(i32* %119, i8* %143, i32 %144)
%146 = add nsw i32 %145, %132
%147 = call i32 @BIO_free_all(i32* %119)
%148 = icmp eq i32 %146, %107
br i1 %148, label %149, label %152
149: ; preds = %141
%150 = call i64 @memcmp(i8* %3, i8* %4, i32 %107)
%151 = icmp eq i64 %150, 0
br i1 %151, label %156, label %152
152: ; preds = %149, %141
%153 = trunc i64 %117 to i32
%154 = load i32, i32* @stderr
%155 = call i32 @fprintf(i32 %154, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %153)
br label %189
156: ; preds = %149
%157 = add nuw nsw i64 %117, 1
%158 = icmp eq i64 %157, %111
br i1 %158, label %112, label %116
159: ; preds = %114, %186
%160 = phi i32 [ %187, %186 ], [ 1, %114 ]
%161 = call i32 (...) @BIO_f_cipher()
%162 = call i32* @BIO_new(i32 %161)
%163 = call i32 (...) @EVP_aes_128_ctr()
%164 = call i32 @BIO_set_cipher(i32* %162, i32 %163, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @main.key, i64 0, i64 0), i32* null, i32 0)
%165 = icmp eq i32 %164, 0
br i1 %165, label %189, label %166
166: ; preds = %159
%167 = call i32 @BIO_new_mem_buf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @main.inp, i64 0, i64 0), i32 1024)
%168 = call i32 @BIO_push(i32* %162, i32 %167)
%169 = call i32 @memset(i8* %3, i32 0, i32 1024)
br label %170
170: ; preds = %170, %166
%171 = phi i32 [ 0, %166 ], [ %176, %170 ]
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %172
%174 = call i32 @BIO_read(i32* %162, i8* %173, i32 %160)
%175 = icmp eq i32 %174, 0
%176 = add nsw i32 %174, %171
br i1 %175, label %177, label %170
177: ; preds = %170
%178 = call i32 @BIO_free_all(i32* %162)
%179 = icmp eq i32 %171, %107
br i1 %179, label %180, label %183
180: ; preds = %177
%181 = call i64 @memcmp(i8* %3, i8* %4, i32 %107)
%182 = icmp eq i64 %181, 0
br i1 %182, label %186, label %183
183: ; preds = %180, %177
%184 = load i32, i32* @stderr
%185 = call i32 @fprintf(i32 %184, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %160)
br label %189
186: ; preds = %180
%187 = add nuw nsw i32 %160, 1
%188 = icmp eq i32 %187, %115
br i1 %188, label %189, label %159
189: ; preds = %25, %68, %116, %186, %159, %104, %112, %183, %92, %98, %7, %0, %152, %137, %61, %46
%190 = phi i32 [ 1, %46 ], [ 2, %61 ], [ 4, %137 ], [ 5, %152 ], [ -1, %0 ], [ -1, %7 ], [ -1, %98 ], [ 3, %92 ], [ 6, %183 ], [ 0, %112 ], [ 0, %104 ], [ 0, %186 ], [ -1, %159 ], [ -1, %116 ], [ -1, %68 ], [ -1, %25 ]
ret i32 %190
}