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

/* Variables and functions */
int /*<<< orphan*/ *BN_MONT_CTX_new();
int /*<<< orphan*/ BN_MONT_CTX_set(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_bntest_rand(int /*<<< orphan*/ *, int, int /*<<< orphan*/,
                                  int);
scalar_t__ BN_cmp(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_from_montgomery(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_is_one(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_is_zero(int /*<<< orphan*/ *);
int /*<<< orphan*/
BN_mod_exp_mont_consttime(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mod_exp_simple(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_new();
int /*<<< orphan*/ BN_one(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_zero(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int test_mod_exp_mont5(BIO *bp, BN_CTX *ctx) {
  BIGNUM *a, *p, *m, *d, *e;
  BN_MONT_CTX *mont;
  a = BN_new();
  p = BN_new();
  m = BN_new();
  d = BN_new();
  e = BN_new();
  mont = BN_MONT_CTX_new();
  BN_bntest_rand(m, 1024, 0, 1);
  BN_bntest_rand(a, 1024, 0, 0);
  BN_zero(p);
  if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))
    return 0;
  if (!BN_is_one(d)) {
    fprintf(stderr, "Modular exponentiation test failed!\n");
    return 0;
  }
  BN_bntest_rand(p, 1024, 0, 0);
  BN_zero(a);
  if (!BN_mod_exp_mont_consttime(d, a, p, m, ctx, NULL))
    return 0;
  if (!BN_is_zero(d)) {
    fprintf(stderr, "Modular exponentiation test failed!\n");
    return 0;
  }
  BN_one(a);
  BN_MONT_CTX_set(mont, m, ctx);
  if (!BN_from_montgomery(e, a, mont, ctx))
    return 0;
  if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL))
    return 0;
  if (!BN_mod_exp_simple(a, e, p, m, ctx))
    return 0;
  if (BN_cmp(a, d) != 0) {
    fprintf(stderr, "Modular exponentiation test failed!\n");
    return 0;
  }
  BN_bntest_rand(e, 1024, 0, 0);
  if (!BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL))
    return 0;
  if (!BN_mod_exp_simple(a, e, p, m, ctx))
    return 0;
  if (BN_cmp(a, d) != 0) {
    fprintf(stderr, "Modular exponentiation test failed!\n");
    return 0;
  }
  BN_free(a);
  BN_free(p);
  BN_free(m);
  BN_free(d);
  BN_free(e);
  return (1);
}


x86 assembly (clang, -O0):
<test_mod_exp_mont5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1030 <BN_MONT_CTX_new@plt>
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x400,%esi
xor    %edx,%edx
mov    $0x1,%ecx
call   1060 <BN_bntest_rand@plt>
mov    -0x20(%rbp),%rdi
mov    $0x400,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1060 <BN_bntest_rand@plt>
mov    -0x28(%rbp),%rdi
call   10d0 <BN_zero@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1100 <BN_mod_exp_mont_consttime@plt>
cmp    $0x0,%eax
jne    1295 <test_mod_exp_mont5+0xb5>
movl   $0x0,-0x4(%rbp)
jmp    1505 <test_mod_exp_mont5+0x325>
mov    -0x38(%rbp),%rdi
call   10f0 <BN_is_one@plt>
cmp    $0x0,%eax
jne    12c8 <test_mod_exp_mont5+0xe8>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
lea    0xd49(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1505 <test_mod_exp_mont5+0x325>
mov    -0x28(%rbp),%rdi
mov    $0x400,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1060 <BN_bntest_rand@plt>
mov    -0x20(%rbp),%rdi
call   10d0 <BN_zero@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1100 <BN_mod_exp_mont_consttime@plt>
cmp    $0x0,%eax
jne    1316 <test_mod_exp_mont5+0x136>
movl   $0x0,-0x4(%rbp)
jmp    1505 <test_mod_exp_mont5+0x325>
mov    -0x38(%rbp),%rdi
call   10a0 <BN_is_zero@plt>
cmp    $0x0,%eax
jne    1349 <test_mod_exp_mont5+0x169>
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
lea    0xcc8(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1505 <test_mod_exp_mont5+0x325>
mov    -0x20(%rbp),%rdi
call   10e0 <BN_one@plt>
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   10b0 <BN_MONT_CTX_set@plt>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1040 <BN_from_montgomery@plt>
cmp    $0x0,%eax
jne    138d <test_mod_exp_mont5+0x1ad>
movl   $0x0,-0x4(%rbp)
jmp    1505 <test_mod_exp_mont5+0x325>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1100 <BN_mod_exp_mont_consttime@plt>
cmp    $0x0,%eax
jne    13c0 <test_mod_exp_mont5+0x1e0>
movl   $0x0,-0x4(%rbp)
jmp    1505 <test_mod_exp_mont5+0x325>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1070 <BN_mod_exp_simple@plt>
cmp    $0x0,%eax
jne    13ee <test_mod_exp_mont5+0x20e>
movl   $0x0,-0x4(%rbp)
jmp    1505 <test_mod_exp_mont5+0x325>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   10c0 <BN_cmp@plt>
cmp    $0x0,%rax
je     1426 <test_mod_exp_mont5+0x246>
mov    0x2bd4(%rip),%rax
mov    (%rax),%edi
lea    0xbeb(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1505 <test_mod_exp_mont5+0x325>
mov    -0x40(%rbp),%rdi
mov    $0x400,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1060 <BN_bntest_rand@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1100 <BN_mod_exp_mont_consttime@plt>
cmp    $0x0,%eax
jne    146b <test_mod_exp_mont5+0x28b>
movl   $0x0,-0x4(%rbp)
jmp    1505 <test_mod_exp_mont5+0x325>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1070 <BN_mod_exp_simple@plt>
cmp    $0x0,%eax
jne    1499 <test_mod_exp_mont5+0x2b9>
movl   $0x0,-0x4(%rbp)
jmp    1505 <test_mod_exp_mont5+0x325>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   10c0 <BN_cmp@plt>
cmp    $0x0,%rax
je     14d1 <test_mod_exp_mont5+0x2f1>
mov    0x2b29(%rip),%rax
mov    (%rax),%edi
lea    0xb40(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1505 <test_mod_exp_mont5+0x325>
mov    -0x20(%rbp),%rdi
call   1080 <BN_free@plt>
mov    -0x28(%rbp),%rdi
call   1080 <BN_free@plt>
mov    -0x30(%rbp),%rdi
call   1080 <BN_free@plt>
mov    -0x38(%rbp),%rdi
call   1080 <BN_free@plt>
mov    -0x40(%rbp),%rdi
call   1080 <BN_free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_mod_exp_mont5>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,%r13
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,(%rsp)
xor    %eax,%eax
call   1030 <BN_MONT_CTX_new@plt>
mov    %rax,%rbp
mov    %r12,%rdi
mov    $0x400,%esi
xor    %edx,%edx
mov    $0x1,%ecx
call   1060 <BN_bntest_rand@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <BN_bntest_rand@plt>
mov    %r15,%rdi
call   10d0 <BN_zero@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r14,%r8
xor    %r9d,%r9d
call   1100 <BN_mod_exp_mont_consttime@plt>
test   %eax,%eax
je     1373 <test_mod_exp_mont5+0x193>
mov    %r13,%rdi
call   10f0 <BN_is_one@plt>
test   %eax,%eax
je     135e <test_mod_exp_mont5+0x17e>
mov    %r15,%rdi
mov    $0x400,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <BN_bntest_rand@plt>
mov    %rbx,%rdi
call   10d0 <BN_zero@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r14,%r8
xor    %r9d,%r9d
call   1100 <BN_mod_exp_mont_consttime@plt>
test   %eax,%eax
je     1373 <test_mod_exp_mont5+0x193>
mov    %r13,%rdi
call   10a0 <BN_is_zero@plt>
test   %eax,%eax
je     135e <test_mod_exp_mont5+0x17e>
mov    %rbx,%rdi
call   10e0 <BN_one@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   10b0 <BN_MONT_CTX_set@plt>
mov    (%rsp),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
call   1040 <BN_from_montgomery@plt>
test   %eax,%eax
mov    $0x0,%ebp
je     1375 <test_mod_exp_mont5+0x195>
xor    %ebp,%ebp
mov    %r13,%rdi
mov    (%rsp),%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r14,%r8
xor    %r9d,%r9d
call   1100 <BN_mod_exp_mont_consttime@plt>
test   %eax,%eax
je     1375 <test_mod_exp_mont5+0x195>
mov    %rbx,%rdi
mov    (%rsp),%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r14,%r8
call   1070 <BN_mod_exp_simple@plt>
test   %eax,%eax
je     1375 <test_mod_exp_mont5+0x195>
mov    %rbx,%rdi
mov    %r13,%rsi
call   10c0 <BN_cmp@plt>
test   %rax,%rax
je     1386 <test_mod_exp_mont5+0x1a6>
mov    0x2c92(%rip),%rax
mov    (%rax),%edi
lea    0xca9(%rip),%rsi
call   1090 <fprintf@plt>
jmp    1375 <test_mod_exp_mont5+0x195>
mov    0x2c7b(%rip),%rax
mov    (%rax),%edi
lea    0xc92(%rip),%rsi
call   1090 <fprintf@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
mov    (%rsp),%rdi
mov    $0x400,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <BN_bntest_rand@plt>
mov    %r13,%rdi
mov    (%rsp),%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r14,%r8
xor    %r9d,%r9d
call   1100 <BN_mod_exp_mont_consttime@plt>
test   %eax,%eax
je     1375 <test_mod_exp_mont5+0x195>
mov    %rbx,%rdi
mov    (%rsp),%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r14,%r8
call   1070 <BN_mod_exp_simple@plt>
test   %eax,%eax
je     1375 <test_mod_exp_mont5+0x195>
mov    %rbx,%rdi
mov    %r13,%rsi
call   10c0 <BN_cmp@plt>
test   %rax,%rax
jne    1347 <test_mod_exp_mont5+0x167>
mov    %rbx,%rdi
call   1080 <BN_free@plt>
mov    %r15,%rdi
call   1080 <BN_free@plt>
mov    %r12,%rdi
call   1080 <BN_free@plt>
mov    %r13,%rdi
call   1080 <BN_free@plt>
mov    (%rsp),%rdi
call   1080 <BN_free@plt>
mov    $0x1,%ebp
jmp    1375 <test_mod_exp_mont5+0x195>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"Modular exponentiation test failed!\0A\00"
define i32 @test_mod_exp_mont5(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
store i32* %0, i32** %4
store i32* %1, i32** %5
%12 = call i32* (...) @BN_new()
store i32* %12, i32** %6
%13 = call i32* (...) @BN_new()
store i32* %13, i32** %7
%14 = call i32* (...) @BN_new()
store i32* %14, i32** %8
%15 = call i32* (...) @BN_new()
store i32* %15, i32** %9
%16 = call i32* (...) @BN_new()
store i32* %16, i32** %10
%17 = call i32* (...) @BN_MONT_CTX_new()
store i32* %17, i32** %11
%18 = load i32*, i32** %8
%19 = call i32 @BN_bntest_rand(i32* %18, i32 1024, i32 0, i32 1)
%20 = load i32*, i32** %6
%21 = call i32 @BN_bntest_rand(i32* %20, i32 1024, i32 0, i32 0)
%22 = load i32*, i32** %7
%23 = call i32 @BN_zero(i32* %22)
%24 = load i32*, i32** %9
%25 = load i32*, i32** %6
%26 = load i32*, i32** %7
%27 = load i32*, i32** %8
%28 = load i32*, i32** %5
%29 = call i32 @BN_mod_exp_mont_consttime(i32* %24, i32* %25, i32* %26, i32* %27, i32* %28, i32* null)
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %2
store i32 0, i32* %3
br label %138
32: ; preds = %2
%33 = load i32*, i32** %9
%34 = call i32 @BN_is_one(i32* %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %138
39: ; preds = %32
%40 = load i32*, i32** %7
%41 = call i32 @BN_bntest_rand(i32* %40, i32 1024, i32 0, i32 0)
%42 = load i32*, i32** %6
%43 = call i32 @BN_zero(i32* %42)
%44 = load i32*, i32** %9
%45 = load i32*, i32** %6
%46 = load i32*, i32** %7
%47 = load i32*, i32** %8
%48 = load i32*, i32** %5
%49 = call i32 @BN_mod_exp_mont_consttime(i32* %44, i32* %45, i32* %46, i32* %47, i32* %48, i32* null)
%50 = icmp ne i32 %49, 0
br i1 %50, label %52, label %51
51: ; preds = %39
store i32 0, i32* %3
br label %138
52: ; preds = %39
%53 = load i32*, i32** %9
%54 = call i32 @BN_is_zero(i32* %53)
%55 = icmp ne i32 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %52
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %138
59: ; preds = %52
%60 = load i32*, i32** %6
%61 = call i32 @BN_one(i32* %60)
%62 = load i32*, i32** %11
%63 = load i32*, i32** %8
%64 = load i32*, i32** %5
%65 = call i32 @BN_MONT_CTX_set(i32* %62, i32* %63, i32* %64)
%66 = load i32*, i32** %10
%67 = load i32*, i32** %6
%68 = load i32*, i32** %11
%69 = load i32*, i32** %5
%70 = call i32 @BN_from_montgomery(i32* %66, i32* %67, i32* %68, i32* %69)
%71 = icmp ne i32 %70, 0
br i1 %71, label %73, label %72
72: ; preds = %59
store i32 0, i32* %3
br label %138
73: ; preds = %59
%74 = load i32*, i32** %9
%75 = load i32*, i32** %10
%76 = load i32*, i32** %7
%77 = load i32*, i32** %8
%78 = load i32*, i32** %5
%79 = call i32 @BN_mod_exp_mont_consttime(i32* %74, i32* %75, i32* %76, i32* %77, i32* %78, i32* null)
%80 = icmp ne i32 %79, 0
br i1 %80, label %82, label %81
81: ; preds = %73
store i32 0, i32* %3
br label %138
82: ; preds = %73
%83 = load i32*, i32** %6
%84 = load i32*, i32** %10
%85 = load i32*, i32** %7
%86 = load i32*, i32** %8
%87 = load i32*, i32** %5
%88 = call i32 @BN_mod_exp_simple(i32* %83, i32* %84, i32* %85, i32* %86, i32* %87)
%89 = icmp ne i32 %88, 0
br i1 %89, label %91, label %90
90: ; preds = %82
store i32 0, i32* %3
br label %138
91: ; preds = %82
%92 = load i32*, i32** %6
%93 = load i32*, i32** %9
%94 = call i64 @BN_cmp(i32* %92, i32* %93)
%95 = icmp ne i64 %94, 0
br i1 %95, label %96, label %99
96: ; preds = %91
%97 = load i32, i32* @stderr
%98 = call i32 @fprintf(i32 %97, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %138
99: ; preds = %91
%100 = load i32*, i32** %10
%101 = call i32 @BN_bntest_rand(i32* %100, i32 1024, i32 0, i32 0)
%102 = load i32*, i32** %9
%103 = load i32*, i32** %10
%104 = load i32*, i32** %7
%105 = load i32*, i32** %8
%106 = load i32*, i32** %5
%107 = call i32 @BN_mod_exp_mont_consttime(i32* %102, i32* %103, i32* %104, i32* %105, i32* %106, i32* null)
%108 = icmp ne i32 %107, 0
br i1 %108, label %110, label %109
109: ; preds = %99
store i32 0, i32* %3
br label %138
110: ; preds = %99
%111 = load i32*, i32** %6
%112 = load i32*, i32** %10
%113 = load i32*, i32** %7
%114 = load i32*, i32** %8
%115 = load i32*, i32** %5
%116 = call i32 @BN_mod_exp_simple(i32* %111, i32* %112, i32* %113, i32* %114, i32* %115)
%117 = icmp ne i32 %116, 0
br i1 %117, label %119, label %118
118: ; preds = %110
store i32 0, i32* %3
br label %138
119: ; preds = %110
%120 = load i32*, i32** %6
%121 = load i32*, i32** %9
%122 = call i64 @BN_cmp(i32* %120, i32* %121)
%123 = icmp ne i64 %122, 0
br i1 %123, label %124, label %127
124: ; preds = %119
%125 = load i32, i32* @stderr
%126 = call i32 @fprintf(i32 %125, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %138
127: ; preds = %119
%128 = load i32*, i32** %6
%129 = call i32 @BN_free(i32* %128)
%130 = load i32*, i32** %7
%131 = call i32 @BN_free(i32* %130)
%132 = load i32*, i32** %8
%133 = call i32 @BN_free(i32* %132)
%134 = load i32*, i32** %9
%135 = call i32 @BN_free(i32* %134)
%136 = load i32*, i32** %10
%137 = call i32 @BN_free(i32* %136)
store i32 1, i32* %3
br label %138
138: ; preds = %127, %124, %118, %109, %96, %90, %81, %72, %56, %51, %36, %31
%139 = load i32, i32* %3
ret i32 %139
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"Modular exponentiation test failed!\0A\00"
define i32 @test_mod_exp_mont5(i32* nocapture readnone %0, i32* %1) {
%3 = tail call i32* (...) @BN_new()
%4 = tail call i32* (...) @BN_new()
%5 = tail call i32* (...) @BN_new()
%6 = tail call i32* (...) @BN_new()
%7 = tail call i32* (...) @BN_new()
%8 = tail call i32* (...) @BN_MONT_CTX_new()
%9 = tail call i32 @BN_bntest_rand(i32* %5, i32 1024, i32 0, i32 1)
%10 = tail call i32 @BN_bntest_rand(i32* %3, i32 1024, i32 0, i32 0)
%11 = tail call i32 @BN_zero(i32* %4)
%12 = tail call i32 @BN_mod_exp_mont_consttime(i32* %6, i32* %3, i32* %4, i32* %5, i32* %1, i32* null)
%13 = icmp eq i32 %12, 0
br i1 %13, label %67, label %14
14: ; preds = %2
%15 = tail call i32 @BN_is_one(i32* %6)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %67
20: ; preds = %14
%21 = tail call i32 @BN_bntest_rand(i32* %4, i32 1024, i32 0, i32 0)
%22 = tail call i32 @BN_zero(i32* %3)
%23 = tail call i32 @BN_mod_exp_mont_consttime(i32* %6, i32* %3, i32* %4, i32* %5, i32* %1, i32* null)
%24 = icmp eq i32 %23, 0
br i1 %24, label %67, label %25
25: ; preds = %20
%26 = tail call i32 @BN_is_zero(i32* %6)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %67
31: ; preds = %25
%32 = tail call i32 @BN_one(i32* %3)
%33 = tail call i32 @BN_MONT_CTX_set(i32* %8, i32* %5, i32* %1)
%34 = tail call i32 @BN_from_montgomery(i32* %7, i32* %3, i32* %8, i32* %1)
%35 = icmp eq i32 %34, 0
br i1 %35, label %67, label %36
36: ; preds = %31
%37 = tail call i32 @BN_mod_exp_mont_consttime(i32* %6, i32* %7, i32* %4, i32* %5, i32* %1, i32* null)
%38 = icmp eq i32 %37, 0
br i1 %38, label %67, label %39
39: ; preds = %36
%40 = tail call i32 @BN_mod_exp_simple(i32* %3, i32* %7, i32* %4, i32* %5, i32* %1)
%41 = icmp eq i32 %40, 0
br i1 %41, label %67, label %42
42: ; preds = %39
%43 = tail call i64 @BN_cmp(i32* %3, i32* %6)
%44 = icmp eq i64 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = tail call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %67
48: ; preds = %42
%49 = tail call i32 @BN_bntest_rand(i32* %7, i32 1024, i32 0, i32 0)
%50 = tail call i32 @BN_mod_exp_mont_consttime(i32* %6, i32* %7, i32* %4, i32* %5, i32* %1, i32* null)
%51 = icmp eq i32 %50, 0
br i1 %51, label %67, label %52
52: ; preds = %48
%53 = tail call i32 @BN_mod_exp_simple(i32* %3, i32* %7, i32* %4, i32* %5, i32* %1)
%54 = icmp eq i32 %53, 0
br i1 %54, label %67, label %55
55: ; preds = %52
%56 = tail call i64 @BN_cmp(i32* %3, i32* %6)
%57 = icmp eq i64 %56, 0
br i1 %57, label %61, label %58
58: ; preds = %55
%59 = load i32, i32* @stderr
%60 = tail call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %67
61: ; preds = %55
%62 = tail call i32 @BN_free(i32* %3)
%63 = tail call i32 @BN_free(i32* %4)
%64 = tail call i32 @BN_free(i32* %5)
%65 = tail call i32 @BN_free(i32* %6)
%66 = tail call i32 @BN_free(i32* %7)
br label %67
67: ; preds = %52, %48, %39, %36, %31, %20, %2, %61, %58, %45, %28, %17
%68 = phi i32 [ 0, %45 ], [ 0, %58 ], [ 1, %61 ], [ 0, %28 ], [ 0, %17 ], [ 0, %2 ], [ 0, %20 ], [ 0, %31 ], [ 0, %36 ], [ 0, %39 ], [ 0, %48 ], [ 0, %52 ]
ret i32 %68
}