#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*/ BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ BN_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_CTX_new();
int /*<<< orphan*/ BN_free(int /*<<< orphan*/ *);
scalar_t__ BN_is_zero(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_mod_exp(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_zero(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
int test_exp_mod_zero() {
  BIGNUM *a = NULL, *p = NULL, *m = NULL;
  BIGNUM *r = NULL;
  BN_CTX *ctx = BN_CTX_new();
  int ret = 1;
  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;
  BN_mod_exp(r, a, p, m, ctx);
  BN_CTX_free(ctx);
  if (BN_is_zero(r))
    ret = 0;
  else {
    printf("1**0 mod 1 = ");
    BN_print_fp(stdout, r);
    printf(", should be 0\n");
  }
err:
  BN_free(r);
  BN_free(a);
  BN_free(p);
  BN_free(m);
  return ret;
}


x86 assembly (clang, -O0):
<test_exp_mod_zero>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1090 <BN_CTX_new@plt>
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    $0x0,%al
call   1030 <BN_new@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f5 <test_exp_mod_zero+0x55>
jmp    12d1 <test_exp_mod_zero+0x131>
mov    -0x18(%rbp),%rdi
call   10c0 <BN_one@plt>
mov    $0x0,%al
call   1030 <BN_new@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1219 <test_exp_mod_zero+0x79>
jmp    12d1 <test_exp_mod_zero+0x131>
mov    -0x8(%rbp),%rdi
call   10c0 <BN_one@plt>
mov    $0x0,%al
call   1030 <BN_new@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    123d <test_exp_mod_zero+0x9d>
jmp    12d1 <test_exp_mod_zero+0x131>
mov    -0x10(%rbp),%rdi
call   10b0 <BN_zero@plt>
mov    $0x0,%al
call   1030 <BN_new@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1261 <test_exp_mod_zero+0xc1>
jmp    12d1 <test_exp_mod_zero+0x131>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1080 <BN_mod_exp@plt>
mov    -0x28(%rbp),%rdi
call   1050 <BN_CTX_free@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <BN_is_zero@plt>
cmp    $0x0,%rax
je     12a2 <test_exp_mod_zero+0x102>
movl   $0x0,-0x2c(%rbp)
jmp    12cc <test_exp_mod_zero+0x12c>
lea    0xd57(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
call   1070 <BN_print_fp@plt>
lea    0xd47(%rip),%rdi
call   1040 <printf@plt>
jmp    12d1 <test_exp_mod_zero+0x131>
mov    -0x20(%rbp),%rdi
call   1060 <BN_free@plt>
mov    -0x8(%rbp),%rdi
call   1060 <BN_free@plt>
mov    -0x10(%rbp),%rdi
call   1060 <BN_free@plt>
mov    -0x18(%rbp),%rdi
call   1060 <BN_free@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_exp_mod_zero>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %eax,%eax
call   10a0 <BN_CTX_new@plt>
mov    %rax,%r13
xor    %eax,%eax
call   1040 <BN_new@plt>
mov    %rax,%r15
mov    $0x1,%r14d
test   %rax,%rax
je     1253 <test_exp_mod_zero+0xa3>
mov    %r15,%rdi
call   10d0 <BN_one@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <BN_new@plt>
test   %rax,%rax
je     1253 <test_exp_mod_zero+0xa3>
mov    %rax,%r12
mov    %rax,%rdi
call   10d0 <BN_one@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <BN_new@plt>
test   %rax,%rax
je     128a <test_exp_mod_zero+0xda>
mov    %rax,%rbp
mov    %rax,%rdi
call   10c0 <BN_zero@plt>
xor    %eax,%eax
call   1040 <BN_new@plt>
test   %rax,%rax
je     128e <test_exp_mod_zero+0xde>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
mov    %r15,%rcx
mov    %r13,%r8
call   1090 <BN_mod_exp@plt>
mov    %r13,%rdi
call   1060 <BN_CTX_free@plt>
mov    %rbx,%rdi
call   10b0 <BN_is_zero@plt>
test   %rax,%rax
je     1292 <test_exp_mod_zero+0xe2>
xor    %r14d,%r14d
jmp    1258 <test_exp_mod_zero+0xa8>
xor    %ebx,%ebx
xor    %r12d,%r12d
mov    %rbx,%rdi
call   1070 <BN_free@plt>
mov    %r12,%rdi
call   1070 <BN_free@plt>
mov    %rbp,%rdi
call   1070 <BN_free@plt>
mov    %r15,%rdi
call   1070 <BN_free@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
jmp    1258 <test_exp_mod_zero+0xa8>
xor    %ebx,%ebx
jmp    1258 <test_exp_mod_zero+0xa8>
lea    0xd67(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1080 <BN_print_fp@plt>
lea    0xd58(%rip),%rdi
call   1030 <puts@plt>
jmp    1258 <test_exp_mod_zero+0xa8>

LLVM IR (-O0):
@.str = [14 x i8] c"1**0 mod 1 = \00"
@stdout = global i32 0
@.str.1 = [15 x i8] c", should be 0\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
store i32* null, i32** %1
store i32* null, i32** %2
store i32* null, i32** %3
store i32* null, i32** %4
%7 = call i32* (...) @BN_CTX_new()
store i32* %7, i32** %5
store i32 1, i32* %6
%8 = call i32* (...) @BN_new()
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp ne i32* %9, null
br i1 %10, label %12, label %11
11: ; preds = %0
br label %53
12: ; preds = %0
%13 = load i32*, i32** %3
%14 = call i32 @BN_one(i32* %13)
%15 = call i32* (...) @BN_new()
store i32* %15, i32** %1
%16 = load i32*, i32** %1
%17 = icmp ne i32* %16, null
br i1 %17, label %19, label %18
18: ; preds = %12
br label %53
19: ; preds = %12
%20 = load i32*, i32** %1
%21 = call i32 @BN_one(i32* %20)
%22 = call i32* (...) @BN_new()
store i32* %22, i32** %2
%23 = load i32*, i32** %2
%24 = icmp ne i32* %23, null
br i1 %24, label %26, label %25
25: ; preds = %19
br label %53
26: ; preds = %19
%27 = load i32*, i32** %2
%28 = call i32 @BN_zero(i32* %27)
%29 = call i32* (...) @BN_new()
store i32* %29, i32** %4
%30 = load i32*, i32** %4
%31 = icmp ne i32* %30, null
br i1 %31, label %33, label %32
32: ; preds = %26
br label %53
33: ; preds = %26
%34 = load i32*, i32** %4
%35 = load i32*, i32** %1
%36 = load i32*, i32** %2
%37 = load i32*, i32** %3
%38 = load i32*, i32** %5
%39 = call i32 @BN_mod_exp(i32* %34, i32* %35, i32* %36, i32* %37, i32* %38)
%40 = load i32*, i32** %5
%41 = call i32 @BN_CTX_free(i32* %40)
%42 = load i32*, i32** %4
%43 = call i64 @BN_is_zero(i32* %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %33
store i32 0, i32* %6
br label %52
46: ; preds = %33
%47 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%48 = load i32, i32* @stdout
%49 = load i32*, i32** %4
%50 = call i32 @BN_print_fp(i32 %48, i32* %49)
%51 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %52
52: ; preds = %46, %45
br label %53
53: ; preds = %52, %32, %25, %18, %11
%54 = load i32*, i32** %4
%55 = call i32 @BN_free(i32* %54)
%56 = load i32*, i32** %1
%57 = call i32 @BN_free(i32* %56)
%58 = load i32*, i32** %2
%59 = call i32 @BN_free(i32* %58)
%60 = load i32*, i32** %3
%61 = call i32 @BN_free(i32* %60)
%62 = load i32, i32* %6
ret i32 %62
}

LLVM IR (-O2):
@.str = [14 x i8] c"1**0 mod 1 = \00"
@stdout = global i32 0
@str = [14 x i8] c", should be 0\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 %26, 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 %26, 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 %26, 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 %26, label %16
16: ; preds = %12
%17 = tail call i32 @BN_mod_exp(i32* %14, i32* %6, i32* %10, i32* %2, i32* %1)
%18 = tail call i32 @BN_CTX_free(i32* %1)
%19 = tail call i64 @BN_is_zero(i32* %14)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* @stdout
%24 = tail call i32 @BN_print_fp(i32 %23, i32* %14)
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %26
26: ; preds = %16, %21, %12, %8, %4, %0
%27 = phi i32* [ %10, %21 ], [ %10, %12 ], [ null, %8 ], [ null, %4 ], [ null, %0 ], [ %10, %16 ]
%28 = phi i32* [ %14, %21 ], [ null, %12 ], [ null, %8 ], [ null, %4 ], [ null, %0 ], [ %14, %16 ]
%29 = phi i32* [ %6, %21 ], [ %6, %12 ], [ %6, %8 ], [ null, %4 ], [ null, %0 ], [ %6, %16 ]
%30 = phi i32 [ 1, %21 ], [ 1, %12 ], [ 1, %8 ], [ 1, %4 ], [ 1, %0 ], [ 0, %16 ]
%31 = tail call i32 @BN_free(i32* %28)
%32 = tail call i32 @BN_free(i32* %29)
%33 = tail call i32 @BN_free(i32* %27)
%34 = tail call i32 @BN_free(i32* %2)
ret i32 %30
}