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

/* Variables and functions */
int /*<<< orphan*/ BN_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_CTX_new();
int /*<<< orphan*/ BN_RAND_BOTTOM_ANY;
int /*<<< orphan*/ BN_RAND_TOP_ONE;
int /*<<< orphan*/ BN_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_is_zero(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mod_exp(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                              int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                              int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mod_exp_mont(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *, 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_mont_word(int /*<<< orphan*/ *, int,
                                        int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mod_exp_recp(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_print_fp(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_rand(int /*<<< orphan*/ *, int, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ BN_zero(int /*<<< orphan*/ *);
int /*<<< orphan*/ a_is_zero_mod_one(char *, int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int test_exp_mod_zero() {
  BIGNUM *a = NULL, *p = NULL, *m = NULL;
  BIGNUM *r = NULL;
  BN_ULONG one_word = 1;
  BN_CTX *ctx = BN_CTX_new();
  int ret = 1, failed = 0;
  m = BN_new();
  if (!m)
    goto err;
  BN_one(m);
  a = BN_new();
  if (!a)
    goto err;
  BN_one(a);
  p = BN_new();
  if (!p)
    goto err;
  BN_zero(p);
  r = BN_new();
  if (!r)
    goto err;
  if (!BN_rand(a, 1024, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))
    goto err;
  if (!BN_mod_exp(r, a, p, m, ctx))
    goto err;
  if (!a_is_zero_mod_one("BN_mod_exp", r, a))
    failed = 1;
  if (!BN_mod_exp_recp(r, a, p, m, ctx))
    goto err;
  if (!a_is_zero_mod_one("BN_mod_exp_recp", r, a))
    failed = 1;
  if (!BN_mod_exp_simple(r, a, p, m, ctx))
    goto err;
  if (!a_is_zero_mod_one("BN_mod_exp_simple", r, a))
    failed = 1;
  if (!BN_mod_exp_mont(r, a, p, m, ctx, NULL))
    goto err;
  if (!a_is_zero_mod_one("BN_mod_exp_mont", r, a))
    failed = 1;
  if (!BN_mod_exp_mont_consttime(r, a, p, m, ctx, NULL)) {
    goto err;
  }
  if (!a_is_zero_mod_one("BN_mod_exp_mont_consttime", r, a))
    failed = 1;
  if (!BN_mod_exp_mont_word(r, one_word, p, m, ctx, NULL))
    goto err;
  if (!BN_is_zero(r)) {
    fprintf(stderr, "BN_mod_exp_mont_word failed:\n");
    fprintf(stderr, "1 ** 0 mod 1 = r (should be 0)\n");
    fprintf(stderr, "r = ");
    BN_print_fp(stderr, r);
    fprintf(stderr, "\n");
    return 0;
  }
  ret = failed;
err:
  BN_free(r);
  BN_free(a);
  BN_free(p);
  BN_free(m);
  BN_CTX_free(ctx);
  return ret;
}


x86 assembly (clang, -O0):
<test_exp_mod_zero>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    $0x0,%al
call   10d0 <BN_CTX_new@plt>
mov    %rax,-0x38(%rbp)
movl   $0x1,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1273 <test_exp_mod_zero+0x63>
jmp    1543 <test_exp_mod_zero+0x333>
mov    -0x20(%rbp),%rdi
call   1100 <BN_one@plt>
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1297 <test_exp_mod_zero+0x87>
jmp    1543 <test_exp_mod_zero+0x333>
mov    -0x10(%rbp),%rdi
call   1100 <BN_one@plt>
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12bb <test_exp_mod_zero+0xab>
jmp    1543 <test_exp_mod_zero+0x333>
mov    -0x18(%rbp),%rdi
call   10f0 <BN_zero@plt>
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12df <test_exp_mod_zero+0xcf>
jmp    1543 <test_exp_mod_zero+0x333>
mov    -0x10(%rbp),%rdi
mov    0x2cfe(%rip),%rax
mov    (%rax),%edx
mov    0x2cdd(%rip),%rax
mov    (%rax),%ecx
mov    $0x400,%esi
call   1030 <BN_rand@plt>
cmp    $0x0,%eax
jne    130d <test_exp_mod_zero+0xfd>
jmp    1543 <test_exp_mod_zero+0x333>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x38(%rbp),%r8
call   10c0 <BN_mod_exp@plt>
cmp    $0x0,%eax
jne    1334 <test_exp_mod_zero+0x124>
jmp    1543 <test_exp_mod_zero+0x333>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xcbd(%rip),%rdi
call   1060 <a_is_zero_mod_one@plt>
cmp    $0x0,%eax
jne    1358 <test_exp_mod_zero+0x148>
movl   $0x1,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x38(%rbp),%r8
call   1040 <BN_mod_exp_recp@plt>
cmp    $0x0,%eax
jne    137f <test_exp_mod_zero+0x16f>
jmp    1543 <test_exp_mod_zero+0x333>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xc7d(%rip),%rdi
call   1060 <a_is_zero_mod_one@plt>
cmp    $0x0,%eax
jne    13a3 <test_exp_mod_zero+0x193>
movl   $0x1,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x38(%rbp),%r8
call   1080 <BN_mod_exp_simple@plt>
cmp    $0x0,%eax
jne    13ca <test_exp_mod_zero+0x1ba>
jmp    1543 <test_exp_mod_zero+0x333>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xc42(%rip),%rdi
call   1060 <a_is_zero_mod_one@plt>
cmp    $0x0,%eax
jne    13ee <test_exp_mod_zero+0x1de>
movl   $0x1,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x38(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1130 <BN_mod_exp_mont@plt>
cmp    $0x0,%eax
jne    141a <test_exp_mod_zero+0x20a>
jmp    1543 <test_exp_mod_zero+0x333>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xc04(%rip),%rdi
call   1060 <a_is_zero_mod_one@plt>
cmp    $0x0,%eax
jne    143e <test_exp_mod_zero+0x22e>
movl   $0x1,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x38(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1110 <BN_mod_exp_mont_consttime@plt>
cmp    $0x0,%eax
jne    146a <test_exp_mod_zero+0x25a>
jmp    1543 <test_exp_mod_zero+0x333>
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xbc4(%rip),%rdi
call   1060 <a_is_zero_mod_one@plt>
cmp    $0x0,%eax
jne    148e <test_exp_mod_zero+0x27e>
movl   $0x1,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x38(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1120 <BN_mod_exp_mont_word@plt>
cmp    $0x0,%eax
jne    14b9 <test_exp_mod_zero+0x2a9>
jmp    1543 <test_exp_mod_zero+0x333>
mov    -0x28(%rbp),%rdi
call   10e0 <BN_is_zero@plt>
cmp    $0x0,%eax
jne    153d <test_exp_mod_zero+0x32d>
mov    0x2b06(%rip),%rax
mov    (%rax),%edi
lea    0xb7c(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2af1(%rip),%rax
mov    (%rax),%edi
lea    0xb85(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2adc(%rip),%rax
mov    (%rax),%edi
lea    0xb90(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2ac7(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rsi
call   10a0 <BN_print_fp@plt>
mov    0x2ab5(%rip),%rax
mov    (%rax),%edi
lea    0xb67(%rip),%rsi
call   10b0 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1576 <test_exp_mod_zero+0x366>
mov    -0x40(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
call   1090 <BN_free@plt>
mov    -0x10(%rbp),%rdi
call   1090 <BN_free@plt>
mov    -0x18(%rbp),%rdi
call   1090 <BN_free@plt>
mov    -0x20(%rbp),%rdi
call   1090 <BN_free@plt>
mov    -0x38(%rbp),%rdi
call   1070 <BN_CTX_free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_exp_mod_zero>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   10d0 <BN_CTX_new@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,%r15
mov    $0x1,%r12d
test   %rax,%rax
je     143b <test_exp_mod_zero+0x22b>
mov    %r15,%rdi
call   1100 <BN_one@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <BN_new@plt>
test   %rax,%rax
je     143b <test_exp_mod_zero+0x22b>
mov    %rax,%rbp
mov    %rax,%rdi
call   1100 <BN_one@plt>
xor    %r13d,%r13d
xor    %eax,%eax
call   1050 <BN_new@plt>
test   %rax,%rax
je     147a <test_exp_mod_zero+0x26a>
mov    %rax,%rbx
mov    %rax,%rdi
call   10f0 <BN_zero@plt>
xor    %eax,%eax
call   1050 <BN_new@plt>
test   %rax,%rax
je     147e <test_exp_mod_zero+0x26e>
mov    %rax,%r13
mov    0x2d48(%rip),%rax
mov    (%rax),%edx
mov    0x2d27(%rip),%rax
mov    (%rax),%ecx
mov    %rbp,%rdi
mov    $0x400,%esi
call   1030 <BN_rand@plt>
test   %eax,%eax
je     1440 <test_exp_mod_zero+0x230>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   10c0 <BN_mod_exp@plt>
test   %eax,%eax
je     1440 <test_exp_mod_zero+0x230>
lea    0xd1d(%rip),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1060 <a_is_zero_mod_one@plt>
mov    %eax,0x10(%rsp)
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <BN_mod_exp_recp@plt>
test   %eax,%eax
je     1440 <test_exp_mod_zero+0x230>
lea    0xcf6(%rip),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1060 <a_is_zero_mod_one@plt>
mov    %eax,0xc(%rsp)
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1080 <BN_mod_exp_simple@plt>
test   %eax,%eax
je     1440 <test_exp_mod_zero+0x230>
lea    0xcd4(%rip),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1060 <a_is_zero_mod_one@plt>
mov    %eax,0x8(%rsp)
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r14,%r8
xor    %r9d,%r9d
call   1130 <BN_mod_exp_mont@plt>
test   %eax,%eax
je     1440 <test_exp_mod_zero+0x230>
lea    0xcb1(%rip),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1060 <a_is_zero_mod_one@plt>
mov    %eax,0x14(%rsp)
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r14,%r8
xor    %r9d,%r9d
call   1110 <BN_mod_exp_mont_consttime@plt>
test   %eax,%eax
je     1440 <test_exp_mod_zero+0x230>
lea    0xc8c(%rip),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1060 <a_is_zero_mod_one@plt>
mov    %eax,0x4(%rsp)
mov    $0x1,%r12d
mov    %r13,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r14,%r8
xor    %r9d,%r9d
call   1120 <BN_mod_exp_mont_word@plt>
test   %eax,%eax
je     1440 <test_exp_mod_zero+0x230>
cmpl   $0x0,0x4(%rsp)
sete   0x4(%rsp)
cmpl   $0x0,0x10(%rsp)
sete   0x10(%rsp)
cmpl   $0x0,0xc(%rsp)
sete   0xc(%rsp)
cmpl   $0x0,0x8(%rsp)
sete   %r12b
cmpl   $0x0,0x14(%rsp)
sete   0x8(%rsp)
mov    %r13,%rdi
call   10e0 <BN_is_zero@plt>
test   %eax,%eax
je     1483 <test_exp_mod_zero+0x273>
mov    0x4(%rsp),%al
or     0x8(%rsp),%al
or     0xc(%rsp),%r12b
or     %al,%r12b
or     0x10(%rsp),%r12b
movzbl %r12b,%r12d
jmp    1440 <test_exp_mod_zero+0x230>
xor    %r13d,%r13d
xor    %ebp,%ebp
mov    %r13,%rdi
call   1090 <BN_free@plt>
mov    %rbp,%rdi
call   1090 <BN_free@plt>
mov    %rbx,%rdi
call   1090 <BN_free@plt>
mov    %r15,%rdi
call   1090 <BN_free@plt>
mov    %r14,%rdi
call   1070 <BN_CTX_free@plt>
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
jmp    1440 <test_exp_mod_zero+0x230>
xor    %r13d,%r13d
jmp    1440 <test_exp_mod_zero+0x230>
mov    0x2b4e(%rip),%rbx
mov    (%rbx),%edi
lea    0xbc4(%rip),%rsi
call   10b0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xbd4(%rip),%rsi
call   10b0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xbe6(%rip),%rsi
call   10b0 <fprintf@plt>
mov    (%rbx),%edi
mov    %r13,%rsi
call   10a0 <BN_print_fp@plt>
mov    (%rbx),%edi
lea    0xbcc(%rip),%rsi
call   10b0 <fprintf@plt>
xor    %r12d,%r12d
jmp    1468 <test_exp_mod_zero+0x258>

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

LLVM IR (-O2):
@BN_RAND_TOP_ONE = global i32 0
@BN_RAND_BOTTOM_ANY = global i32 0
@.str = [11 x i8] c"BN_mod_exp\00"
@.str.1 = [16 x i8] c"BN_mod_exp_recp\00"
@.str.2 = [18 x i8] c"BN_mod_exp_simple\00"
@.str.3 = [16 x i8] c"BN_mod_exp_mont\00"
@.str.4 = [26 x i8] c"BN_mod_exp_mont_consttime\00"
@stderr = global i32 0
@.str.5 = [30 x i8] c"BN_mod_exp_mont_word failed:\0A\00"
@.str.6 = [32 x i8] c"1 ** 0 mod 1 = r (should be 0)\0A\00"
@.str.7 = [5 x i8] c"r = \00"
@.str.8 = [2 x i8] c"\0A\00"
define i32 @test_exp_mod_zero() {
%1 = tail call i32* (...) @BN_CTX_new()
%2 = tail call i32* (...) @BN_new()
%3 = icmp eq i32* %2, null
br i1 %3, label %68, label %4
4: ; preds = %0
%5 = tail call i32 @BN_one(i32* %2)
%6 = tail call i32* (...) @BN_new()
%7 = icmp eq i32* %6, null
br i1 %7, label %68, label %8
8: ; preds = %4
%9 = tail call i32 @BN_one(i32* %6)
%10 = tail call i32* (...) @BN_new()
%11 = icmp eq i32* %10, null
br i1 %11, label %68, label %12
12: ; preds = %8
%13 = tail call i32 @BN_zero(i32* %10)
%14 = tail call i32* (...) @BN_new()
%15 = icmp eq i32* %14, null
br i1 %15, label %68, label %16
16: ; preds = %12
%17 = load i32, i32* @BN_RAND_TOP_ONE
%18 = load i32, i32* @BN_RAND_BOTTOM_ANY
%19 = tail call i32 @BN_rand(i32* %6, i32 1024, i32 %17, i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %68, label %21
21: ; preds = %16
%22 = tail call i32 @BN_mod_exp(i32* %14, i32* %6, i32* %10, i32* %2, i32* %1)
%23 = icmp eq i32 %22, 0
br i1 %23, label %68, label %24
24: ; preds = %21
%25 = tail call i32 @a_is_zero_mod_one(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* %14, i32* %6)
%26 = tail call i32 @BN_mod_exp_recp(i32* %14, i32* %6, i32* %10, i32* %2, i32* %1)
%27 = icmp eq i32 %26, 0
br i1 %27, label %68, label %28
28: ; preds = %24
%29 = tail call i32 @a_is_zero_mod_one(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32* %14, i32* %6)
%30 = tail call i32 @BN_mod_exp_simple(i32* %14, i32* %6, i32* %10, i32* %2, i32* %1)
%31 = icmp eq i32 %30, 0
br i1 %31, label %68, label %32
32: ; preds = %28
%33 = tail call i32 @a_is_zero_mod_one(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32* %14, i32* %6)
%34 = tail call i32 @BN_mod_exp_mont(i32* %14, i32* %6, i32* %10, i32* %2, i32* %1, i32* null)
%35 = icmp eq i32 %34, 0
br i1 %35, label %68, label %36
36: ; preds = %32
%37 = tail call i32 @a_is_zero_mod_one(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32* %14, i32* %6)
%38 = tail call i32 @BN_mod_exp_mont_consttime(i32* %14, i32* %6, i32* %10, i32* %2, i32* %1, i32* null)
%39 = icmp eq i32 %38, 0
br i1 %39, label %68, label %40
40: ; preds = %36
%41 = tail call i32 @a_is_zero_mod_one(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32* %14, i32* %6)
%42 = tail call i32 @BN_mod_exp_mont_word(i32* %14, i32 1, i32* %10, i32* %2, i32* %1, i32* null)
%43 = icmp eq i32 %42, 0
br i1 %43, label %68, label %44
44: ; preds = %40
%45 = icmp eq i32 %41, 0
%46 = icmp eq i32 %25, 0
%47 = icmp eq i32 %29, 0
%48 = icmp eq i32 %33, 0
%49 = icmp eq i32 %37, 0
%50 = select i1 %45, i1 true, i1 %49
%51 = select i1 %50, i1 true, i1 %48
%52 = select i1 %51, i1 true, i1 %47
%53 = select i1 %52, i1 true, i1 %46
%54 = zext i1 %53 to i32
%55 = tail call i32 @BN_is_zero(i32* %14)
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %68
57: ; preds = %44
%58 = load i32, i32* @stderr
%59 = tail call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%60 = load i32, i32* @stderr
%61 = tail call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
%62 = load i32, i32* @stderr
%63 = tail call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%64 = load i32, i32* @stderr
%65 = tail call i32 @BN_print_fp(i32 %64, i32* %14)
%66 = load i32, i32* @stderr
%67 = tail call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %78
68: ; preds = %44, %40, %36, %32, %28, %24, %21, %16, %12, %8, %4, %0
%69 = phi i32* [ %10, %40 ], [ %10, %36 ], [ %10, %32 ], [ %10, %28 ], [ %10, %24 ], [ %10, %21 ], [ %10, %16 ], [ %10, %12 ], [ null, %8 ], [ null, %4 ], [ null, %0 ], [ %10, %44 ]
%70 = phi i32* [ %14, %40 ], [ %14, %36 ], [ %14, %32 ], [ %14, %28 ], [ %14, %24 ], [ %14, %21 ], [ %14, %16 ], [ null, %12 ], [ null, %8 ], [ null, %4 ], [ null, %0 ], [ %14, %44 ]
%71 = phi i32* [ %6, %40 ], [ %6, %36 ], [ %6, %32 ], [ %6, %28 ], [ %6, %24 ], [ %6, %21 ], [ %6, %16 ], [ %6, %12 ], [ %6, %8 ], [ null, %4 ], [ null, %0 ], [ %6, %44 ]
%72 = phi i32 [ 1, %40 ], [ 1, %36 ], [ 1, %32 ], [ 1, %28 ], [ 1, %24 ], [ 1, %21 ], [ 1, %16 ], [ 1, %12 ], [ 1, %8 ], [ 1, %4 ], [ 1, %0 ], [ %54, %44 ]
%73 = tail call i32 @BN_free(i32* %70)
%74 = tail call i32 @BN_free(i32* %71)
%75 = tail call i32 @BN_free(i32* %69)
%76 = tail call i32 @BN_free(i32* %2)
%77 = tail call i32 @BN_CTX_free(i32* %1)
br label %78
78: ; preds = %68, %57
%79 = phi i32 [ %72, %68 ], [ 0, %57 ]
ret i32 %79
}