#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*/ BN_CTX;
typedef int /*<<< orphan*/ BIO;
typedef int /*<<< orphan*/ BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ BIO_NOCLOSE;
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_s_file();
int /*<<< orphan*/ BIO_set_fp(int /*<<< orphan*/ *, int /*<<< orphan*/,
                              int /*<<< orphan*/);
unsigned char BN_BITS;
unsigned char BN_BITS2;
int /*<<< orphan*/ BN_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_CTX_new();
scalar_t__ BN_cmp(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mod(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int BN_mod_exp_mont(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                    int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                    int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int BN_mod_exp_mont_consttime(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                              int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                              int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int BN_mod_exp_mont_ct(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                       int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                       int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int BN_mod_exp_mont_nonct(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int BN_mod_exp_recp(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                    int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                    int /*<<< orphan*/ *);
int BN_mod_exp_simple(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                      int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                      int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_new();
int BN_num_bits(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_print(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_rand(int /*<<< orphan*/ *, unsigned char,
                           int /*<<< orphan*/, int);
int /*<<< orphan*/ CRYPTO_mem_leaks(int /*<<< orphan*/ *);
int /*<<< orphan*/ ERR_load_BN_strings();
int /*<<< orphan*/ ERR_load_crypto_strings();
int /*<<< orphan*/ ERR_print_errors(int /*<<< orphan*/ *);
int /*<<< orphan*/ ERR_remove_thread_state(int /*<<< orphan*/ *);
int /*<<< orphan*/ arc4random_buf(unsigned char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
scalar_t__ test_exp_mod_zero();
int main(int argc, char *argv[]) {
  BN_CTX *ctx;
  BIO *out = NULL;
  int i, ret;
  unsigned char c;
  BIGNUM *r_mont, *r_mont_const, *r_recp, *r_simple, *r_mont_ct, *r_mont_nonct,
      *a, *b, *m;
  ERR_load_BN_strings();
  ctx = BN_CTX_new();
  if (ctx == NULL)
    exit(1);
  r_mont = BN_new();
  r_mont_const = BN_new();
  r_mont_ct = BN_new();
  r_mont_nonct = BN_new();
  r_recp = BN_new();
  r_simple = BN_new();
  a = BN_new();
  b = BN_new();
  m = BN_new();
  if ((r_mont == NULL) || (r_recp == NULL) || (a == NULL) || (b == NULL))
    goto err;
  out = BIO_new(BIO_s_file());
  if (out == NULL)
    exit(1);
  BIO_set_fp(out, stdout, BIO_NOCLOSE);
  for (i = 0; i < 200; i++) {
    arc4random_buf(&c, 1);
    c = (c % BN_BITS) - BN_BITS2;
    BN_rand(a, (BN_BITS * 2) + c, 0, 0);
    arc4random_buf(&c, 1);
    c = (c % BN_BITS) - BN_BITS2;
    BN_rand(b, (BN_BITS * 2) + c, 0, 0);
    arc4random_buf(&c, 1);
    c = (c % BN_BITS) - BN_BITS2;
    BN_rand(m, (BN_BITS * 2) + c, 0, 1);
    BN_mod(a, a, m, ctx);
    BN_mod(b, b, m, ctx);
    ret = BN_mod_exp_mont(r_mont, a, b, m, ctx, NULL);
    if (ret <= 0) {
      printf("BN_mod_exp_mont() problems\n");
      ERR_print_errors(out);
      exit(1);
    }
    ret = BN_mod_exp_mont_ct(r_mont_ct, a, b, m, ctx, NULL);
    if (ret <= 0) {
      printf("BN_mod_exp_mont_ct() problems\n");
      ERR_print_errors(out);
      exit(1);
    }
    ret = BN_mod_exp_mont_nonct(r_mont_nonct, a, b, m, ctx, NULL);
    if (ret <= 0) {
      printf("BN_mod_exp_mont_nonct() problems\n");
      ERR_print_errors(out);
      exit(1);
    }
    ret = BN_mod_exp_recp(r_recp, a, b, m, ctx);
    if (ret <= 0) {
      printf("BN_mod_exp_recp() problems\n");
      ERR_print_errors(out);
      exit(1);
    }
    ret = BN_mod_exp_simple(r_simple, a, b, m, ctx);
    if (ret <= 0) {
      printf("BN_mod_exp_simple() problems\n");
      ERR_print_errors(out);
      exit(1);
    }
    ret = BN_mod_exp_mont_consttime(r_mont_const, a, b, m, ctx, NULL);
    if (ret <= 0) {
      printf("BN_mod_exp_mont_consttime() problems\n");
      ERR_print_errors(out);
      exit(1);
    }
    if (BN_cmp(r_simple, r_mont) == 0 && BN_cmp(r_simple, r_recp) == 0 &&
        BN_cmp(r_simple, r_mont_const) == 0) {
      printf(".");
      fflush(stdout);
    } else {
      if (BN_cmp(r_simple, r_mont) != 0)
        printf("\nsimple and mont results differ\n");
      if (BN_cmp(r_simple, r_mont_const) != 0)
        printf("\nsimple and mont const time results differ\n");
      if (BN_cmp(r_simple, r_recp) != 0)
        printf("\nsimple and recp results differ\n");
      if (BN_cmp(r_mont, r_mont_ct) != 0)
        printf("\nmont_ct and mont results differ\n");
      if (BN_cmp(r_mont_ct, r_mont_nonct) != 0)
        printf("\nmont_ct and mont_nonct results differ\n");
      printf("a (%3d) = ", BN_num_bits(a));
      BN_print(out, a);
      printf("\nb (%3d) = ", BN_num_bits(b));
      BN_print(out, b);
      printf("\nm (%3d) = ", BN_num_bits(m));
      BN_print(out, m);
      printf("\nsimple   =");
      BN_print(out, r_simple);
      printf("\nrecp	 =");
      BN_print(out, r_recp);
      printf("\nmont	 =");
      BN_print(out, r_mont);
      printf("\nmont_ct  =");
      BN_print(out, r_mont_const);
      printf("\n");
      exit(1);
    }
  }
  BN_free(r_mont);
  BN_free(r_mont_const);
  BN_free(r_recp);
  BN_free(r_simple);
  BN_free(a);
  BN_free(b);
  BN_free(m);
  BN_CTX_free(ctx);
  ERR_remove_thread_state(NULL);
  CRYPTO_mem_leaks(out);
  BIO_free(out);
  printf("\n");
  if (test_exp_mod_zero() != 0)
    goto err;
  printf("done\n");
  return (0);
err:
  ERR_load_crypto_strings();
  ERR_print_errors(out);
  return (1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1100 <ERR_load_BN_strings@plt>
mov    $0x0,%al
call   10f0 <BN_CTX_new@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1318 <main+0x48>
mov    $0x1,%edi
call   11b0 <exit@plt>
mov    $0x0,%al
call   1070 <BN_new@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1070 <BN_new@plt>
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1070 <BN_new@plt>
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   1070 <BN_new@plt>
mov    %rax,-0x60(%rbp)
mov    $0x0,%al
call   1070 <BN_new@plt>
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   1070 <BN_new@plt>
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   1070 <BN_new@plt>
mov    %rax,-0x68(%rbp)
mov    $0x0,%al
call   1070 <BN_new@plt>
mov    %rax,-0x70(%rbp)
mov    $0x0,%al
call   1070 <BN_new@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     13a7 <main+0xd7>
cmpq   $0x0,-0x48(%rbp)
je     13a7 <main+0xd7>
cmpq   $0x0,-0x68(%rbp)
je     13a7 <main+0xd7>
cmpq   $0x0,-0x70(%rbp)
jne    13ac <main+0xdc>
jmp    19af <main+0x6df>
mov    $0x0,%al
call   11d0 <BIO_s_file@plt>
mov    %eax,%edi
call   1130 <BIO_new@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    13d3 <main+0x103>
mov    $0x1,%edi
call   11b0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2bea(%rip),%rax
mov    (%rax),%esi
mov    0x2c01(%rip),%rax
mov    (%rax),%edx
call   1170 <BIO_set_fp@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0xc8,-0x24(%rbp)
jge    190e <main+0x63e>
lea    -0x29(%rbp),%rdi
mov    $0x1,%esi
call   1090 <arc4random_buf@plt>
movzbl -0x29(%rbp),%eax
mov    0x2bc5(%rip),%rcx
movzbl (%rcx),%ecx
cltd
idiv   %ecx
mov    0x2ba8(%rip),%rax
movzbl (%rax),%eax
sub    %eax,%edx
mov    %dl,%al
mov    %al,-0x29(%rbp)
mov    -0x68(%rbp),%rdi
mov    0x2ba3(%rip),%rax
movzbl (%rax),%eax
shl    $0x1,%eax
movzbl -0x29(%rbp),%ecx
add    %ecx,%eax
xor    %ecx,%ecx
movzbl %al,%esi
mov    %ecx,%edx
call   1030 <BN_rand@plt>
lea    -0x29(%rbp),%rdi
mov    $0x1,%esi
call   1090 <arc4random_buf@plt>
movzbl -0x29(%rbp),%eax
mov    0x2b72(%rip),%rcx
movzbl (%rcx),%ecx
cltd
idiv   %ecx
mov    0x2b55(%rip),%rax
movzbl (%rax),%eax
sub    %eax,%edx
mov    %dl,%al
mov    %al,-0x29(%rbp)
mov    -0x70(%rbp),%rdi
mov    0x2b50(%rip),%rax
movzbl (%rax),%eax
shl    $0x1,%eax
movzbl -0x29(%rbp),%ecx
add    %ecx,%eax
xor    %ecx,%ecx
movzbl %al,%esi
mov    %ecx,%edx
call   1030 <BN_rand@plt>
lea    -0x29(%rbp),%rdi
mov    $0x1,%esi
call   1090 <arc4random_buf@plt>
movzbl -0x29(%rbp),%eax
mov    0x2b1f(%rip),%rcx
movzbl (%rcx),%ecx
cltd
idiv   %ecx
mov    0x2b02(%rip),%rax
movzbl (%rax),%eax
sub    %eax,%edx
mov    %dl,%al
mov    %al,-0x29(%rbp)
mov    -0x78(%rbp),%rdi
mov    0x2afd(%rip),%rax
movzbl (%rax),%eax
shl    $0x1,%eax
movzbl -0x29(%rbp),%ecx
add    %ecx,%eax
xor    %edx,%edx
mov    $0x1,%ecx
movzbl %al,%esi
call   1030 <BN_rand@plt>
mov    -0x68(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x78(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1150 <BN_mod@plt>
mov    -0x70(%rbp),%rdi
mov    -0x70(%rbp),%rsi
mov    -0x78(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1150 <BN_mod@plt>
mov    -0x38(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x70(%rbp),%rdx
mov    -0x78(%rbp),%rcx
mov    -0x18(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   11f0 <BN_mod_exp_mont@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jg     1574 <main+0x2a4>
lea    0xaa6(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ERR_print_errors@plt>
mov    $0x1,%edi
call   11b0 <exit@plt>
mov    -0x58(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x70(%rbp),%rdx
mov    -0x78(%rbp),%rcx
mov    -0x18(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   11e0 <BN_mod_exp_mont_ct@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jg     15c0 <main+0x2f0>
lea    0xa76(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ERR_print_errors@plt>
mov    $0x1,%edi
call   11b0 <exit@plt>
mov    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x70(%rbp),%rdx
mov    -0x78(%rbp),%rcx
mov    -0x18(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   10c0 <BN_mod_exp_mont_nonct@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jg     160c <main+0x33c>
lea    0xa49(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ERR_print_errors@plt>
mov    $0x1,%edi
call   11b0 <exit@plt>
mov    -0x48(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x70(%rbp),%rdx
mov    -0x78(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1040 <BN_mod_exp_recp@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jg     1653 <main+0x383>
lea    0xa24(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ERR_print_errors@plt>
mov    $0x1,%edi
call   11b0 <exit@plt>
mov    -0x50(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x70(%rbp),%rdx
mov    -0x78(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   10d0 <BN_mod_exp_simple@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jg     169a <main+0x3ca>
lea    0x9f9(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ERR_print_errors@plt>
mov    $0x1,%edi
call   11b0 <exit@plt>
mov    -0x40(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    -0x70(%rbp),%rdx
mov    -0x78(%rbp),%rcx
mov    -0x18(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1190 <BN_mod_exp_mont_consttime@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jg     16e6 <main+0x416>
lea    0x9cb(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ERR_print_errors@plt>
mov    $0x1,%edi
call   11b0 <exit@plt>
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1180 <BN_cmp@plt>
cmp    $0x0,%rax
jne    174c <main+0x47c>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1180 <BN_cmp@plt>
cmp    $0x0,%rax
jne    174c <main+0x47c>
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1180 <BN_cmp@plt>
cmp    $0x0,%rax
jne    174c <main+0x47c>
lea    0x98b(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    0x2888(%rip),%rax
mov    (%rax),%edi
call   1120 <fflush@plt>
jmp    18fb <main+0x62b>
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1180 <BN_cmp@plt>
cmp    $0x0,%rax
je     1771 <main+0x4a1>
lea    0x955(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1180 <BN_cmp@plt>
cmp    $0x0,%rax
je     1796 <main+0x4c6>
lea    0x951(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1180 <BN_cmp@plt>
cmp    $0x0,%rax
je     17bb <main+0x4eb>
lea    0x958(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1180 <BN_cmp@plt>
cmp    $0x0,%rax
je     17e0 <main+0x510>
lea    0x954(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x58(%rbp),%rdi
mov    -0x60(%rbp),%rsi
call   1180 <BN_cmp@plt>
cmp    $0x0,%rax
je     1805 <main+0x535>
lea    0x951(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x68(%rbp),%rdi
call   1080 <BN_num_bits@plt>
mov    %eax,%esi
lea    0x960(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x68(%rbp),%rsi
call   1110 <BN_print@plt>
mov    -0x70(%rbp),%rdi
call   1080 <BN_num_bits@plt>
mov    %eax,%esi
lea    0x945(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x70(%rbp),%rsi
call   1110 <BN_print@plt>
mov    -0x78(%rbp),%rdi
call   1080 <BN_num_bits@plt>
mov    %eax,%esi
lea    0x92b(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x78(%rbp),%rsi
call   1110 <BN_print@plt>
lea    0x91c(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1110 <BN_print@plt>
lea    0x90d(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1110 <BN_print@plt>
lea    0x8fb(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1110 <BN_print@plt>
lea    0x8e9(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1110 <BN_print@plt>
lea    0x8de(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    $0x1,%edi
call   11b0 <exit@plt>
jmp    1900 <main+0x630>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    13f5 <main+0x125>
mov    -0x38(%rbp),%rdi
call   10e0 <BN_free@plt>
mov    -0x40(%rbp),%rdi
call   10e0 <BN_free@plt>
mov    -0x48(%rbp),%rdi
call   10e0 <BN_free@plt>
mov    -0x50(%rbp),%rdi
call   10e0 <BN_free@plt>
mov    -0x68(%rbp),%rdi
call   10e0 <BN_free@plt>
mov    -0x70(%rbp),%rdi
call   10e0 <BN_free@plt>
mov    -0x78(%rbp),%rdi
call   10e0 <BN_free@plt>
mov    -0x18(%rbp),%rdi
call   10b0 <BN_CTX_free@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <ERR_remove_thread_state@plt>
mov    -0x20(%rbp),%rdi
call   11c0 <CRYPTO_mem_leaks@plt>
mov    -0x20(%rbp),%rdi
call   1140 <BIO_free@plt>
lea    0x850(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    $0x0,%al
call   1160 <test_exp_mod_zero@plt>
cmp    $0x0,%rax
je     1995 <main+0x6c5>
jmp    19af <main+0x6df>
lea    0x828(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    19c6 <main+0x6f6>
mov    $0x0,%al
call   11a0 <ERR_load_crypto_strings@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ERR_print_errors@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
xor    %eax,%eax
call   1120 <ERR_load_BN_strings@plt>
xor    %eax,%eax
call   1110 <BN_CTX_new@plt>
test   %rax,%rax
je     1892 <main+0x5a2>
mov    %rax,%r12
xor    %eax,%eax
mov    %rax,0x10(%rsp)
xor    %eax,%eax
call   1090 <BN_new@plt>
mov    %rax,0x18(%rsp)
xor    %eax,%eax
call   1090 <BN_new@plt>
mov    %rax,0x28(%rsp)
xor    %eax,%eax
call   1090 <BN_new@plt>
mov    %rax,0x38(%rsp)
xor    %eax,%eax
call   1090 <BN_new@plt>
mov    %rax,0x50(%rsp)
xor    %eax,%eax
call   1090 <BN_new@plt>
mov    %rax,%r13
xor    %eax,%eax
call   1090 <BN_new@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1090 <BN_new@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1090 <BN_new@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1090 <BN_new@plt>
cmpq   $0x0,0x18(%rsp)
je     1684 <main+0x394>
test   %r13,%r13
je     1684 <main+0x394>
test   %r15,%r15
je     1684 <main+0x394>
test   %rbx,%rbx
je     1684 <main+0x394>
mov    %rax,%rbp
mov    %r13,0x20(%rsp)
xor    %eax,%eax
call   11f0 <BIO_s_file@plt>
mov    %eax,%edi
call   1150 <BIO_new@plt>
test   %rax,%rax
je     1892 <main+0x5a2>
mov    %rax,%rdi
mov    0x2bfa(%rip),%rax
mov    (%rax),%esi
mov    0x2c11(%rip),%rax
mov    (%rax),%edx
mov    %rdi,0x10(%rsp)
call   1190 <BIO_set_fp@plt>
mov    $0xc8,%r13d
mov    %r14,0x30(%rsp)
mov    %rbp,0x48(%rsp)
mov    %rbx,0x40(%rsp)
nopl   0x0(%rax,%rax,1)
lea    0xf(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
call   10b0 <arc4random_buf@plt>
mov    0x2bc7(%rip),%rbp
movzbl 0x0(%rbp),%ecx
movzbl 0xf(%rsp),%eax
div    %cl
movzbl %ah,%eax
mov    0x2ba2(%rip),%r14
sub    (%r14),%al
mov    %al,0xf(%rsp)
add    %cl,%cl
add    %al,%cl
movzbl %cl,%esi
mov    %r15,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <BN_rand@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   10b0 <arc4random_buf@plt>
movzbl 0x0(%rbp),%ecx
movzbl 0xf(%rsp),%eax
div    %cl
movzbl %ah,%eax
sub    (%r14),%al
mov    %al,0xf(%rsp)
add    %cl,%cl
add    %al,%cl
movzbl %cl,%esi
mov    0x40(%rsp),%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <BN_rand@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   10b0 <arc4random_buf@plt>
movzbl 0x0(%rbp),%ecx
mov    0x48(%rsp),%rbp
movzbl 0xf(%rsp),%eax
div    %cl
movzbl %ah,%eax
sub    (%r14),%al
mov    0x40(%rsp),%rbx
mov    %al,0xf(%rsp)
add    %cl,%cl
add    %al,%cl
movzbl %cl,%esi
mov    %rbp,%rdi
xor    %edx,%edx
mov    $0x1,%ecx
call   1030 <BN_rand@plt>
mov    %r15,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %r12,%rcx
call   1170 <BN_mod@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r12,%rcx
call   1170 <BN_mod@plt>
mov    0x18(%rsp),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %r12,%r8
xor    %r9d,%r9d
call   1210 <BN_mod_exp_mont@plt>
test   %eax,%eax
jle    184f <main+0x55f>
mov    0x38(%rsp),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %r12,%r8
xor    %r9d,%r9d
call   1200 <BN_mod_exp_mont_ct@plt>
test   %eax,%eax
jle    1858 <main+0x568>
mov    0x50(%rsp),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %r12,%r8
xor    %r9d,%r9d
call   10e0 <BN_mod_exp_mont_nonct@plt>
test   %eax,%eax
mov    0x30(%rsp),%r14
jle    1861 <main+0x571>
mov    0x20(%rsp),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %r12,%r8
call   1050 <BN_mod_exp_recp@plt>
test   %eax,%eax
jle    186a <main+0x57a>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %r12,%r8
call   10f0 <BN_mod_exp_simple@plt>
test   %eax,%eax
jle    1873 <main+0x583>
mov    0x28(%rsp),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %r12,%r8
xor    %r9d,%r9d
call   11b0 <BN_mod_exp_mont_consttime@plt>
test   %eax,%eax
jle    187c <main+0x58c>
mov    %r14,%rdi
mov    0x18(%rsp),%rsi
call   11a0 <BN_cmp@plt>
test   %rax,%rax
jne    16b9 <main+0x3c9>
mov    %r14,%rdi
mov    0x20(%rsp),%rsi
call   11a0 <BN_cmp@plt>
test   %rax,%rax
jne    16b9 <main+0x3c9>
mov    %r14,%rdi
mov    0x28(%rsp),%rsi
call   11a0 <BN_cmp@plt>
test   %rax,%rax
jne    16b9 <main+0x3c9>
mov    $0x2e,%edi
call   1040 <putchar@plt>
mov    0x29cf(%rip),%rax
mov    (%rax),%edi
call   1140 <fflush@plt>
add    $0xffffffff,%r13d
jne    1400 <main+0x110>
mov    0x18(%rsp),%rdi
call   1100 <BN_free@plt>
mov    0x28(%rsp),%rdi
call   1100 <BN_free@plt>
mov    0x20(%rsp),%rdi
call   1100 <BN_free@plt>
mov    %r14,%rdi
call   1100 <BN_free@plt>
mov    %r15,%rdi
call   1100 <BN_free@plt>
mov    %rbx,%rdi
call   1100 <BN_free@plt>
mov    %rbp,%rdi
call   1100 <BN_free@plt>
mov    %r12,%rdi
call   10d0 <BN_CTX_free@plt>
xor    %ebx,%ebx
xor    %edi,%edi
call   1070 <ERR_remove_thread_state@plt>
mov    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   11e0 <CRYPTO_mem_leaks@plt>
mov    %rbp,%rdi
call   1160 <BIO_free@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
call   1180 <test_exp_mod_zero@plt>
test   %rax,%rax
je     16ab <main+0x3bb>
xor    %eax,%eax
call   11c0 <ERR_load_crypto_strings@plt>
mov    0x10(%rsp),%rdi
call   1080 <ERR_print_errors@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x99b(%rip),%rdi
call   1060 <puts@plt>
jmp    169a <main+0x3aa>
mov    %r14,%rdi
mov    0x18(%rsp),%rsi
call   11a0 <BN_cmp@plt>
test   %rax,%rax
je     16d7 <main+0x3e7>
lea    0xa13(%rip),%rdi
call   1060 <puts@plt>
mov    0x30(%rsp),%rdi
mov    0x28(%rsp),%rsi
call   11a0 <BN_cmp@plt>
test   %rax,%rax
je     16f7 <main+0x407>
lea    0x9c8(%rip),%rdi
call   1060 <puts@plt>
mov    0x30(%rsp),%rdi
mov    0x20(%rsp),%rsi
call   11a0 <BN_cmp@plt>
test   %rax,%rax
je     1717 <main+0x427>
lea    0x988(%rip),%rdi
call   1060 <puts@plt>
mov    0x18(%rsp),%rdi
mov    0x38(%rsp),%rsi
call   11a0 <BN_cmp@plt>
test   %rax,%rax
je     1737 <main+0x447>
lea    0x947(%rip),%rdi
call   1060 <puts@plt>
mov    0x38(%rsp),%rdi
mov    0x50(%rsp),%rsi
call   11a0 <BN_cmp@plt>
test   %rax,%rax
je     1757 <main+0x467>
lea    0x900(%rip),%rdi
call   1060 <puts@plt>
mov    %r15,%rdi
call   10a0 <BN_num_bits@plt>
lea    0x89a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10c0 <printf@plt>
mov    0x10(%rsp),%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   1130 <BN_print@plt>
mov    0x40(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <BN_num_bits@plt>
lea    0x878(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10c0 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1130 <BN_print@plt>
mov    0x48(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <BN_num_bits@plt>
lea    0x85c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   10c0 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1130 <BN_print@plt>
lea    0x84d(%rip),%rdi
xor    %eax,%eax
call   10c0 <printf@plt>
mov    %r12,%rdi
mov    0x30(%rsp),%rsi
call   1130 <BN_print@plt>
lea    0x83e(%rip),%rdi
xor    %eax,%eax
call   10c0 <printf@plt>
mov    %r12,%rdi
mov    0x20(%rsp),%rsi
call   1130 <BN_print@plt>
lea    0x82c(%rip),%rdi
xor    %eax,%eax
call   10c0 <printf@plt>
mov    %r12,%rdi
mov    0x18(%rsp),%rsi
call   1130 <BN_print@plt>
lea    0x81a(%rip),%rdi
xor    %eax,%eax
call   10c0 <printf@plt>
mov    %r12,%rdi
mov    0x28(%rsp),%rsi
call   1130 <BN_print@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    $0x1,%edi
call   11d0 <exit@plt>
lea    0x94b(%rip),%rdi
jmp    1883 <main+0x593>
lea    0x924(%rip),%rdi
jmp    1883 <main+0x593>
lea    0x8fa(%rip),%rdi
jmp    1883 <main+0x593>
lea    0x8d6(%rip),%rdi
jmp    1883 <main+0x593>
lea    0x8b0(%rip),%rdi
jmp    1883 <main+0x593>
lea    0x882(%rip),%rdi
call   1060 <puts@plt>
mov    0x10(%rsp),%rdi
call   1080 <ERR_print_errors@plt>
mov    $0x1,%edi
call   11d0 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@BIO_NOCLOSE = global i32 0
@BN_BITS = global i8 0
@BN_BITS2 = global i8 0
@.str = [28 x i8] c"BN_mod_exp_mont() problems\0A\00"
@.str.1 = [31 x i8] c"BN_mod_exp_mont_ct() problems\0A\00"
@.str.2 = [34 x i8] c"BN_mod_exp_mont_nonct() problems\0A\00"
@.str.3 = [28 x i8] c"BN_mod_exp_recp() problems\0A\00"
@.str.4 = [30 x i8] c"BN_mod_exp_simple() problems\0A\00"
@.str.5 = [38 x i8] c"BN_mod_exp_mont_consttime() problems\0A\00"
@.str.6 = [2 x i8] c".\00"
@.str.7 = [33 x i8] c"\0Asimple and mont results differ\0A\00"
@.str.8 = [44 x i8] c"\0Asimple and mont const time results differ\0A\00"
@.str.9 = [33 x i8] c"\0Asimple and recp results differ\0A\00"
@.str.10 = [34 x i8] c"\0Amont_ct and mont results differ\0A\00"
@.str.11 = [40 x i8] c"\0Amont_ct and mont_nonct results differ\0A\00"
@.str.12 = [11 x i8] c"a (%3d) = \00"
@.str.13 = [12 x i8] c"\0Ab (%3d) = \00"
@.str.14 = [12 x i8] c"\0Am (%3d) = \00"
@.str.15 = [12 x i8] c"\0Asimple =\00"
@.str.16 = [9 x i8] c"\0Arecp\09 =\00"
@.str.17 = [9 x i8] c"\0Amont\09 =\00"
@.str.18 = [12 x i8] c"\0Amont_ct =\00"
@.str.19 = [2 x i8] c"\0A\00"
@.str.20 = [6 x i8] c"done\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %7
%20 = call i32 (...) @ERR_load_BN_strings()
%21 = call i32* (...) @BN_CTX_new()
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %26
24: ; preds = %2
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = call i32* (...) @BN_new()
store i32* %27, i32** %11
%28 = call i32* (...) @BN_new()
store i32* %28, i32** %12
%29 = call i32* (...) @BN_new()
store i32* %29, i32** %15
%30 = call i32* (...) @BN_new()
store i32* %30, i32** %16
%31 = call i32* (...) @BN_new()
store i32* %31, i32** %13
%32 = call i32* (...) @BN_new()
store i32* %32, i32** %14
%33 = call i32* (...) @BN_new()
store i32* %33, i32** %17
%34 = call i32* (...) @BN_new()
store i32* %34, i32** %18
%35 = call i32* (...) @BN_new()
store i32* %35, i32** %19
%36 = load i32*, i32** %11
%37 = icmp eq i32* %36, null
br i1 %37, label %47, label %38
38: ; preds = %26
%39 = load i32*, i32** %13
%40 = icmp eq i32* %39, null
br i1 %40, label %47, label %41
41: ; preds = %38
%42 = load i32*, i32** %17
%43 = icmp eq i32* %42, null
br i1 %43, label %47, label %44
44: ; preds = %41
%45 = load i32*, i32** %18
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %48
47: ; preds = %44, %41, %38, %26
br label %337
48: ; preds = %44
%49 = call i32 (...) @BIO_s_file()
%50 = call i32* @BIO_new(i32 %49)
store i32* %50, i32** %7
%51 = load i32*, i32** %7
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %55
53: ; preds = %48
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %48
%56 = load i32*, i32** %7
%57 = load i32, i32* @stdout
%58 = load i32, i32* @BIO_NOCLOSE
%59 = call i32 @BIO_set_fp(i32* %56, i32 %57, i32 %58)
store i32 0, i32* %8
br label %60
60: ; preds = %306, %55
%61 = load i32, i32* %8
%62 = icmp slt i32 %61, 200
br i1 %62, label %63, label %309
63: ; preds = %60
%64 = call i32 @arc4random_buf(i8* %10, i32 1)
%65 = load i8, i8* %10
%66 = zext i8 %65 to i32
%67 = load i8, i8* @BN_BITS
%68 = zext i8 %67 to i32
%69 = srem i32 %66, %68
%70 = load i8, i8* @BN_BITS2
%71 = zext i8 %70 to i32
%72 = sub nsw i32 %69, %71
%73 = trunc i32 %72 to i8
store i8 %73, i8* %10
%74 = load i32*, i32** %17
%75 = load i8, i8* @BN_BITS
%76 = zext i8 %75 to i32
%77 = mul nsw i32 %76, 2
%78 = load i8, i8* %10
%79 = zext i8 %78 to i32
%80 = add nsw i32 %77, %79
%81 = trunc i32 %80 to i8
%82 = call i32 @BN_rand(i32* %74, i8 zeroext %81, i32 0, i32 0)
%83 = call i32 @arc4random_buf(i8* %10, i32 1)
%84 = load i8, i8* %10
%85 = zext i8 %84 to i32
%86 = load i8, i8* @BN_BITS
%87 = zext i8 %86 to i32
%88 = srem i32 %85, %87
%89 = load i8, i8* @BN_BITS2
%90 = zext i8 %89 to i32
%91 = sub nsw i32 %88, %90
%92 = trunc i32 %91 to i8
store i8 %92, i8* %10
%93 = load i32*, i32** %18
%94 = load i8, i8* @BN_BITS
%95 = zext i8 %94 to i32
%96 = mul nsw i32 %95, 2
%97 = load i8, i8* %10
%98 = zext i8 %97 to i32
%99 = add nsw i32 %96, %98
%100 = trunc i32 %99 to i8
%101 = call i32 @BN_rand(i32* %93, i8 zeroext %100, i32 0, i32 0)
%102 = call i32 @arc4random_buf(i8* %10, i32 1)
%103 = load i8, i8* %10
%104 = zext i8 %103 to i32
%105 = load i8, i8* @BN_BITS
%106 = zext i8 %105 to i32
%107 = srem i32 %104, %106
%108 = load i8, i8* @BN_BITS2
%109 = zext i8 %108 to i32
%110 = sub nsw i32 %107, %109
%111 = trunc i32 %110 to i8
store i8 %111, i8* %10
%112 = load i32*, i32** %19
%113 = load i8, i8* @BN_BITS
%114 = zext i8 %113 to i32
%115 = mul nsw i32 %114, 2
%116 = load i8, i8* %10
%117 = zext i8 %116 to i32
%118 = add nsw i32 %115, %117
%119 = trunc i32 %118 to i8
%120 = call i32 @BN_rand(i32* %112, i8 zeroext %119, i32 0, i32 1)
%121 = load i32*, i32** %17
%122 = load i32*, i32** %17
%123 = load i32*, i32** %19
%124 = load i32*, i32** %6
%125 = call i32 @BN_mod(i32* %121, i32* %122, i32* %123, i32* %124)
%126 = load i32*, i32** %18
%127 = load i32*, i32** %18
%128 = load i32*, i32** %19
%129 = load i32*, i32** %6
%130 = call i32 @BN_mod(i32* %126, i32* %127, i32* %128, i32* %129)
%131 = load i32*, i32** %11
%132 = load i32*, i32** %17
%133 = load i32*, i32** %18
%134 = load i32*, i32** %19
%135 = load i32*, i32** %6
%136 = call i32 @BN_mod_exp_mont(i32* %131, i32* %132, i32* %133, i32* %134, i32* %135, i32* null)
store i32 %136, i32* %9
%137 = load i32, i32* %9
%138 = icmp sle i32 %137, 0
br i1 %138, label %139, label %144
139: ; preds = %63
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%141 = load i32*, i32** %7
%142 = call i32 @ERR_print_errors(i32* %141)
%143 = call i32 @exit(i32 1)
unreachable
144: ; preds = %63
%145 = load i32*, i32** %15
%146 = load i32*, i32** %17
%147 = load i32*, i32** %18
%148 = load i32*, i32** %19
%149 = load i32*, i32** %6
%150 = call i32 @BN_mod_exp_mont_ct(i32* %145, i32* %146, i32* %147, i32* %148, i32* %149, i32* null)
store i32 %150, i32* %9
%151 = load i32, i32* %9
%152 = icmp sle i32 %151, 0
br i1 %152, label %153, label %158
153: ; preds = %144
%154 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%155 = load i32*, i32** %7
%156 = call i32 @ERR_print_errors(i32* %155)
%157 = call i32 @exit(i32 1)
unreachable
158: ; preds = %144
%159 = load i32*, i32** %16
%160 = load i32*, i32** %17
%161 = load i32*, i32** %18
%162 = load i32*, i32** %19
%163 = load i32*, i32** %6
%164 = call i32 @BN_mod_exp_mont_nonct(i32* %159, i32* %160, i32* %161, i32* %162, i32* %163, i32* null)
store i32 %164, i32* %9
%165 = load i32, i32* %9
%166 = icmp sle i32 %165, 0
br i1 %166, label %167, label %172
167: ; preds = %158
%168 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%169 = load i32*, i32** %7
%170 = call i32 @ERR_print_errors(i32* %169)
%171 = call i32 @exit(i32 1)
unreachable
172: ; preds = %158
%173 = load i32*, i32** %13
%174 = load i32*, i32** %17
%175 = load i32*, i32** %18
%176 = load i32*, i32** %19
%177 = load i32*, i32** %6
%178 = call i32 @BN_mod_exp_recp(i32* %173, i32* %174, i32* %175, i32* %176, i32* %177)
store i32 %178, i32* %9
%179 = load i32, i32* %9
%180 = icmp sle i32 %179, 0
br i1 %180, label %181, label %186
181: ; preds = %172
%182 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%183 = load i32*, i32** %7
%184 = call i32 @ERR_print_errors(i32* %183)
%185 = call i32 @exit(i32 1)
unreachable
186: ; preds = %172
%187 = load i32*, i32** %14
%188 = load i32*, i32** %17
%189 = load i32*, i32** %18
%190 = load i32*, i32** %19
%191 = load i32*, i32** %6
%192 = call i32 @BN_mod_exp_simple(i32* %187, i32* %188, i32* %189, i32* %190, i32* %191)
store i32 %192, i32* %9
%193 = load i32, i32* %9
%194 = icmp sle i32 %193, 0
br i1 %194, label %195, label %200
195: ; preds = %186
%196 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%197 = load i32*, i32** %7
%198 = call i32 @ERR_print_errors(i32* %197)
%199 = call i32 @exit(i32 1)
unreachable
200: ; preds = %186
%201 = load i32*, i32** %12
%202 = load i32*, i32** %17
%203 = load i32*, i32** %18
%204 = load i32*, i32** %19
%205 = load i32*, i32** %6
%206 = call i32 @BN_mod_exp_mont_consttime(i32* %201, i32* %202, i32* %203, i32* %204, i32* %205, i32* null)
store i32 %206, i32* %9
%207 = load i32, i32* %9
%208 = icmp sle i32 %207, 0
br i1 %208, label %209, label %214
209: ; preds = %200
%210 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
%211 = load i32*, i32** %7
%212 = call i32 @ERR_print_errors(i32* %211)
%213 = call i32 @exit(i32 1)
unreachable
214: ; preds = %200
%215 = load i32*, i32** %14
%216 = load i32*, i32** %11
%217 = call i64 @BN_cmp(i32* %215, i32* %216)
%218 = icmp eq i64 %217, 0
br i1 %218, label %219, label %233
219: ; preds = %214
%220 = load i32*, i32** %14
%221 = load i32*, i32** %13
%222 = call i64 @BN_cmp(i32* %220, i32* %221)
%223 = icmp eq i64 %222, 0
br i1 %223, label %224, label %233
224: ; preds = %219
%225 = load i32*, i32** %14
%226 = load i32*, i32** %12
%227 = call i64 @BN_cmp(i32* %225, i32* %226)
%228 = icmp eq i64 %227, 0
br i1 %228, label %229, label %233
229: ; preds = %224
%230 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%231 = load i32, i32* @stdout
%232 = call i32 @fflush(i32 %231)
br label %305
233: ; preds = %224, %219, %214
%234 = load i32*, i32** %14
%235 = load i32*, i32** %11
%236 = call i64 @BN_cmp(i32* %234, i32* %235)
%237 = icmp ne i64 %236, 0
br i1 %237, label %238, label %240
238: ; preds = %233
%239 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
br label %240
240: ; preds = %238, %233
%241 = load i32*, i32** %14
%242 = load i32*, i32** %12
%243 = call i64 @BN_cmp(i32* %241, i32* %242)
%244 = icmp ne i64 %243, 0
br i1 %244, label %245, label %247
245: ; preds = %240
%246 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.8, i64 0, i64 0))
br label %247
247: ; preds = %245, %240
%248 = load i32*, i32** %14
%249 = load i32*, i32** %13
%250 = call i64 @BN_cmp(i32* %248, i32* %249)
%251 = icmp ne i64 %250, 0
br i1 %251, label %252, label %254
252: ; preds = %247
%253 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0))
br label %254
254: ; preds = %252, %247
%255 = load i32*, i32** %11
%256 = load i32*, i32** %15
%257 = call i64 @BN_cmp(i32* %255, i32* %256)
%258 = icmp ne i64 %257, 0
br i1 %258, label %259, label %261
259: ; preds = %254
%260 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0))
br label %261
261: ; preds = %259, %254
%262 = load i32*, i32** %15
%263 = load i32*, i32** %16
%264 = call i64 @BN_cmp(i32* %262, i32* %263)
%265 = icmp ne i64 %264, 0
br i1 %265, label %266, label %268
266: ; preds = %261
%267 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.11, i64 0, i64 0))
br label %268
268: ; preds = %266, %261
%269 = load i32*, i32** %17
%270 = call i32 @BN_num_bits(i32* %269)
%271 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0), i32 %270)
%272 = load i32*, i32** %7
%273 = load i32*, i32** %17
%274 = call i32 @BN_print(i32* %272, i32* %273)
%275 = load i32*, i32** %18
%276 = call i32 @BN_num_bits(i32* %275)
%277 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0), i32 %276)
%278 = load i32*, i32** %7
%279 = load i32*, i32** %18
%280 = call i32 @BN_print(i32* %278, i32* %279)
%281 = load i32*, i32** %19
%282 = call i32 @BN_num_bits(i32* %281)
%283 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0), i32 %282)
%284 = load i32*, i32** %7
%285 = load i32*, i32** %19
%286 = call i32 @BN_print(i32* %284, i32* %285)
%287 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0))
%288 = load i32*, i32** %7
%289 = load i32*, i32** %14
%290 = call i32 @BN_print(i32* %288, i32* %289)
%291 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.16, i64 0, i64 0))
%292 = load i32*, i32** %7
%293 = load i32*, i32** %13
%294 = call i32 @BN_print(i32* %292, i32* %293)
%295 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.17, i64 0, i64 0))
%296 = load i32*, i32** %7
%297 = load i32*, i32** %11
%298 = call i32 @BN_print(i32* %296, i32* %297)
%299 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.18, i64 0, i64 0))
%300 = load i32*, i32** %7
%301 = load i32*, i32** %12
%302 = call i32 @BN_print(i32* %300, i32* %301)
%303 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.19, i64 0, i64 0))
%304 = call i32 @exit(i32 1)
unreachable
305: ; preds = %229
br label %306
306: ; preds = %305
%307 = load i32, i32* %8
%308 = add nsw i32 %307, 1
store i32 %308, i32* %8
br label %60
309: ; preds = %60
%310 = load i32*, i32** %11
%311 = call i32 @BN_free(i32* %310)
%312 = load i32*, i32** %12
%313 = call i32 @BN_free(i32* %312)
%314 = load i32*, i32** %13
%315 = call i32 @BN_free(i32* %314)
%316 = load i32*, i32** %14
%317 = call i32 @BN_free(i32* %316)
%318 = load i32*, i32** %17
%319 = call i32 @BN_free(i32* %318)
%320 = load i32*, i32** %18
%321 = call i32 @BN_free(i32* %320)
%322 = load i32*, i32** %19
%323 = call i32 @BN_free(i32* %322)
%324 = load i32*, i32** %6
%325 = call i32 @BN_CTX_free(i32* %324)
%326 = call i32 @ERR_remove_thread_state(i32* null)
%327 = load i32*, i32** %7
%328 = call i32 @CRYPTO_mem_leaks(i32* %327)
%329 = load i32*, i32** %7
%330 = call i32 @BIO_free(i32* %329)
%331 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.19, i64 0, i64 0))
%332 = call i64 (...) @test_exp_mod_zero()
%333 = icmp ne i64 %332, 0
br i1 %333, label %334, label %335
334: ; preds = %309
br label %337
335: ; preds = %309
%336 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.20, i64 0, i64 0))
store i32 0, i32* %3
br label %341
337: ; preds = %334, %47
%338 = call i32 (...) @ERR_load_crypto_strings()
%339 = load i32*, i32** %7
%340 = call i32 @ERR_print_errors(i32* %339)
store i32 1, i32* %3
br label %341
341: ; preds = %337, %335
%342 = load i32, i32* %3
ret i32 %342
}

LLVM IR (-O2):
@stdout = global i32 0
@BIO_NOCLOSE = global i32 0
@BN_BITS = global i8 0
@BN_BITS2 = global i8 0
@.str.12 = [11 x i8] c"a (%3d) = \00"
@.str.13 = [12 x i8] c"\0Ab (%3d) = \00"
@.str.14 = [12 x i8] c"\0Am (%3d) = \00"
@.str.15 = [12 x i8] c"\0Asimple =\00"
@.str.16 = [9 x i8] c"\0Arecp\09 =\00"
@.str.17 = [9 x i8] c"\0Amont\09 =\00"
@.str.18 = [12 x i8] c"\0Amont_ct =\00"
@str = [5 x i8] c"done\00"
@str.21 = [39 x i8] c"\0Amont_ct and mont_nonct results differ\00"
@str.22 = [33 x i8] c"\0Amont_ct and mont results differ\00"
@str.23 = [32 x i8] c"\0Asimple and recp results differ\00"
@str.24 = [43 x i8] c"\0Asimple and mont const time results differ\00"
@str.25 = [32 x i8] c"\0Asimple and mont results differ\00"
@str.26 = [37 x i8] c"BN_mod_exp_mont_consttime() problems\00"
@str.27 = [29 x i8] c"BN_mod_exp_simple() problems\00"
@str.28 = [27 x i8] c"BN_mod_exp_recp() problems\00"
@str.29 = [33 x i8] c"BN_mod_exp_mont_nonct() problems\00"
@str.30 = [30 x i8] c"BN_mod_exp_mont_ct() problems\00"
@str.31 = [27 x i8] c"BN_mod_exp_mont() problems\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = tail call i32 (...) @ERR_load_BN_strings()
%5 = tail call i32* (...) @BN_CTX_new()
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = tail call i32* (...) @BN_new()
%11 = tail call i32* (...) @BN_new()
%12 = tail call i32* (...) @BN_new()
%13 = tail call i32* (...) @BN_new()
%14 = tail call i32* (...) @BN_new()
%15 = tail call i32* (...) @BN_new()
%16 = tail call i32* (...) @BN_new()
%17 = tail call i32* (...) @BN_new()
%18 = tail call i32* (...) @BN_new()
%19 = icmp eq i32* %10, null
%20 = icmp eq i32* %14, null
%21 = select i1 %19, i1 true, i1 %20
%22 = icmp eq i32* %16, null
%23 = select i1 %21, i1 true, i1 %22
%24 = icmp eq i32* %17, null
%25 = select i1 %23, i1 true, i1 %24
br i1 %25, label %185, label %26
26: ; preds = %9
%27 = tail call i32 (...) @BIO_s_file()
%28 = tail call i32* @BIO_new(i32 %27)
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %26
%33 = load i32, i32* @stdout
%34 = load i32, i32* @BIO_NOCLOSE
%35 = tail call i32 @BIO_set_fp(i32* %28, i32 %33, i32 %34)
br label %36
36: ; preds = %32, %117
%37 = phi i32 [ 0, %32 ], [ %121, %117 ]
%38 = call i32 @arc4random_buf(i8* %3, i32 1)
%39 = load i8, i8* %3
%40 = load i8, i8* @BN_BITS
%41 = urem i8 %39, %40
%42 = load i8, i8* @BN_BITS2
%43 = sub i8 %41, %42
store i8 %43, i8* %3
%44 = shl i8 %40, 1
%45 = add i8 %43, %44
%46 = call i32 @BN_rand(i32* %16, i8 zeroext %45, i32 0, i32 0)
%47 = call i32 @arc4random_buf(i8* %3, i32 1)
%48 = load i8, i8* %3
%49 = load i8, i8* @BN_BITS
%50 = urem i8 %48, %49
%51 = load i8, i8* @BN_BITS2
%52 = sub i8 %50, %51
store i8 %52, i8* %3
%53 = shl i8 %49, 1
%54 = add i8 %52, %53
%55 = call i32 @BN_rand(i32* %17, i8 zeroext %54, i32 0, i32 0)
%56 = call i32 @arc4random_buf(i8* %3, i32 1)
%57 = load i8, i8* %3
%58 = load i8, i8* @BN_BITS
%59 = urem i8 %57, %58
%60 = load i8, i8* @BN_BITS2
%61 = sub i8 %59, %60
store i8 %61, i8* %3
%62 = shl i8 %58, 1
%63 = add i8 %61, %62
%64 = call i32 @BN_rand(i32* %18, i8 zeroext %63, i32 0, i32 1)
%65 = call i32 @BN_mod(i32* %16, i32* %16, i32* %18, i32* %5)
%66 = call i32 @BN_mod(i32* %17, i32* %17, i32* %18, i32* %5)
%67 = call i32 @BN_mod_exp_mont(i32* %10, i32* %16, i32* %17, i32* %18, i32* %5, i32* null)
%68 = icmp slt i32 %67, 1
br i1 %68, label %69, label %73
69: ; preds = %36
%70 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.31, i64 0, i64 0))
%71 = call i32 @ERR_print_errors(i32* %28)
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %36
%74 = call i32 @BN_mod_exp_mont_ct(i32* %12, i32* %16, i32* %17, i32* %18, i32* %5, i32* null)
%75 = icmp slt i32 %74, 1
br i1 %75, label %76, label %80
76: ; preds = %73
%77 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.30, i64 0, i64 0))
%78 = call i32 @ERR_print_errors(i32* %28)
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %73
%81 = call i32 @BN_mod_exp_mont_nonct(i32* %13, i32* %16, i32* %17, i32* %18, i32* %5, i32* null)
%82 = icmp slt i32 %81, 1
br i1 %82, label %83, label %87
83: ; preds = %80
%84 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.29, i64 0, i64 0))
%85 = call i32 @ERR_print_errors(i32* %28)
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %80
%88 = call i32 @BN_mod_exp_recp(i32* %14, i32* %16, i32* %17, i32* %18, i32* %5)
%89 = icmp slt i32 %88, 1
br i1 %89, label %90, label %94
90: ; preds = %87
%91 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.28, i64 0, i64 0))
%92 = call i32 @ERR_print_errors(i32* %28)
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %87
%95 = call i32 @BN_mod_exp_simple(i32* %15, i32* %16, i32* %17, i32* %18, i32* %5)
%96 = icmp slt i32 %95, 1
br i1 %96, label %97, label %101
97: ; preds = %94
%98 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.27, i64 0, i64 0))
%99 = call i32 @ERR_print_errors(i32* %28)
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %94
%102 = call i32 @BN_mod_exp_mont_consttime(i32* %11, i32* %16, i32* %17, i32* %18, i32* %5, i32* null)
%103 = icmp slt i32 %102, 1
br i1 %103, label %104, label %108
104: ; preds = %101
%105 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.26, i64 0, i64 0))
%106 = call i32 @ERR_print_errors(i32* %28)
%107 = call i32 @exit(i32 1)
unreachable
108: ; preds = %101
%109 = call i64 @BN_cmp(i32* %15, i32* %10)
%110 = icmp eq i64 %109, 0
br i1 %110, label %111, label %123
111: ; preds = %108
%112 = call i64 @BN_cmp(i32* %15, i32* %14)
%113 = icmp eq i64 %112, 0
br i1 %113, label %114, label %123
114: ; preds = %111
%115 = call i64 @BN_cmp(i32* %15, i32* %11)
%116 = icmp eq i64 %115, 0
br i1 %116, label %117, label %123
117: ; preds = %114
%118 = call i32 @putchar(i32 46)
%119 = load i32, i32* @stdout
%120 = call i32 @fflush(i32 %119)
%121 = add nuw nsw i32 %37, 1
%122 = icmp eq i32 %121, 200
br i1 %122, label %168, label %36
123: ; preds = %114, %111, %108
%124 = call i64 @BN_cmp(i32* %15, i32* %10)
%125 = icmp eq i64 %124, 0
br i1 %125, label %128, label %126
126: ; preds = %123
%127 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.25, i64 0, i64 0))
br label %128
128: ; preds = %126, %123
%129 = call i64 @BN_cmp(i32* %15, i32* %11)
%130 = icmp eq i64 %129, 0
br i1 %130, label %133, label %131
131: ; preds = %128
%132 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.24, i64 0, i64 0))
br label %133
133: ; preds = %131, %128
%134 = call i64 @BN_cmp(i32* %15, i32* %14)
%135 = icmp eq i64 %134, 0
br i1 %135, label %138, label %136
136: ; preds = %133
%137 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.23, i64 0, i64 0))
br label %138
138: ; preds = %136, %133
%139 = call i64 @BN_cmp(i32* %10, i32* %12)
%140 = icmp eq i64 %139, 0
br i1 %140, label %143, label %141
141: ; preds = %138
%142 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.22, i64 0, i64 0))
br label %143
143: ; preds = %141, %138
%144 = call i64 @BN_cmp(i32* %12, i32* %13)
%145 = icmp eq i64 %144, 0
br i1 %145, label %148, label %146
146: ; preds = %143
%147 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.21, i64 0, i64 0))
br label %148
148: ; preds = %146, %143
%149 = call i32 @BN_num_bits(i32* %16)
%150 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0), i32 %149)
%151 = call i32 @BN_print(i32* %28, i32* %16)
%152 = call i32 @BN_num_bits(i32* %17)
%153 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0), i32 %152)
%154 = call i32 @BN_print(i32* %28, i32* %17)
%155 = call i32 @BN_num_bits(i32* %18)
%156 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0), i32 %155)
%157 = call i32 @BN_print(i32* %28, i32* %18)
%158 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0))
%159 = call i32 @BN_print(i32* %28, i32* %15)
%160 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.16, i64 0, i64 0))
%161 = call i32 @BN_print(i32* %28, i32* %14)
%162 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.17, i64 0, i64 0))
%163 = call i32 @BN_print(i32* %28, i32* %10)
%164 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.18, i64 0, i64 0))
%165 = call i32 @BN_print(i32* %28, i32* %11)
%166 = call i32 @putchar(i32 10)
%167 = call i32 @exit(i32 1)
unreachable
168: ; preds = %117
%169 = call i32 @BN_free(i32* %10)
%170 = call i32 @BN_free(i32* %11)
%171 = call i32 @BN_free(i32* %14)
%172 = call i32 @BN_free(i32* %15)
%173 = call i32 @BN_free(i32* %16)
%174 = call i32 @BN_free(i32* %17)
%175 = call i32 @BN_free(i32* %18)
%176 = call i32 @BN_CTX_free(i32* %5)
%177 = call i32 @ERR_remove_thread_state(i32* null)
%178 = call i32 @CRYPTO_mem_leaks(i32* %28)
%179 = call i32 @BIO_free(i32* %28)
%180 = call i32 @putchar(i32 10)
%181 = call i64 (...) @test_exp_mod_zero()
%182 = icmp eq i64 %181, 0
br i1 %182, label %183, label %185
183: ; preds = %168
%184 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
br label %189
185: ; preds = %168, %9
%186 = phi i32* [ null, %9 ], [ %28, %168 ]
%187 = call i32 (...) @ERR_load_crypto_strings()
%188 = call i32 @ERR_print_errors(i32* %186)
br label %189
189: ; preds = %185, %183
%190 = phi i32 [ 1, %185 ], [ 0, %183 ]
ret i32 %190
}