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

/* Variables and functions */
int /*<<< orphan*/ *BN_CTX_new();
int /*<<< orphan*/ *BN_RECP_CTX_new();
int /*<<< orphan*/ BN_RECP_CTX_set(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int /*<<< orphan*/ *);
scalar_t__ BN_cmp(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int BN_div(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int BN_div_recp(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                int /*<<< orphan*/ *);
scalar_t__ BN_is_zero(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_new();
int /*<<< orphan*/ BN_pseudo_rand(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                  int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ Rand();
int /*<<< orphan*/ bug(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
main() {
  BIGNUM *a = BN_new(), *b = BN_new(), *c = BN_new(), *d = BN_new(),
         *C = BN_new(), *D = BN_new();
  BN_RECP_CTX *recp = BN_RECP_CTX_new();
  BN_CTX *ctx = BN_CTX_new();
  for (;;) {
    BN_pseudo_rand(a, Rand(), 0, 0);
    BN_pseudo_rand(b, Rand(), 0, 0);
    if (BN_is_zero(b))
      continue;
    BN_RECP_CTX_set(recp, b, ctx);
    if (BN_div(C, D, a, b, ctx) != 1)
      bug("BN_div failed", a, b);
    if (BN_div_recp(c, d, a, recp, ctx) != 1)
      bug("BN_div_recp failed", a, b);
    else if (BN_cmp(c, C) != 0 || BN_cmp(c, C) != 0)
      bug("mismatch", a, b);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <BN_new@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <BN_new@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <BN_new@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <BN_new@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <BN_new@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1040 <BN_new@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   10a0 <BN_RECP_CTX_new@plt>
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1050 <BN_CTX_new@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   10d0 <Rand@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1070 <BN_pseudo_rand@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    $0x0,%al
call   10d0 <Rand@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1070 <BN_pseudo_rand@plt>
mov    -0x18(%rbp),%rdi
call   1060 <BN_is_zero@plt>
cmp    $0x0,%rax
je     126b <main+0xbb>
jmp    1217 <main+0x67>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   10b0 <BN_RECP_CTX_set@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x48(%rbp),%r8
call   10c0 <BN_div@plt>
cmp    $0x1,%eax
je     12b2 <main+0x102>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd53(%rip),%rdi
call   1030 <bug@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
call   1080 <BN_div_recp@plt>
cmp    $0x1,%eax
je     12ed <main+0x13d>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd2b(%rip),%rdi
call   1030 <bug@plt>
jmp    1334 <main+0x184>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1090 <BN_cmp@plt>
cmp    $0x0,%rax
jne    131b <main+0x16b>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1090 <BN_cmp@plt>
cmp    $0x0,%rax
je     132f <main+0x17f>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xcf7(%rip),%rdi
call   1030 <bug@plt>
jmp    1334 <main+0x184>
jmp    1217 <main+0x67>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1040 <BN_new@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1040 <BN_new@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <BN_new@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1040 <BN_new@plt>
mov    %rax,0x10(%rsp)
xor    %eax,%eax
call   1040 <BN_new@plt>
mov    %rax,%r13
xor    %eax,%eax
call   1040 <BN_new@plt>
mov    %rax,0x8(%rsp)
xor    %eax,%eax
call   10a0 <BN_RECP_CTX_new@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1050 <BN_CTX_new@plt>
mov    %rax,%rbp
jmp    122b <main+0x7b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <bug@plt>
xor    %eax,%eax
call   10d0 <Rand@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1070 <BN_pseudo_rand@plt>
xor    %eax,%eax
call   10d0 <Rand@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1070 <BN_pseudo_rand@plt>
mov    %rbx,%rdi
call   1060 <BN_is_zero@plt>
test   %rax,%rax
jne    122b <main+0x7b>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   10b0 <BN_RECP_CTX_set@plt>
mov    %r13,%rdi
mov    0x8(%rsp),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %rbp,%r8
call   10c0 <BN_div@plt>
cmp    $0x1,%eax
je     129d <main+0xed>
lea    0xd6e(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <bug@plt>
mov    %r15,%rdi
mov    0x10(%rsp),%rsi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %rbp,%r8
call   1080 <BN_div_recp@plt>
lea    0xd54(%rip),%rdi
cmp    $0x1,%eax
jne    1220 <main+0x70>
mov    %r15,%rdi
mov    %r13,%rsi
call   1090 <BN_cmp@plt>
lea    0xd4c(%rip),%rdi
test   %rax,%rax
jne    1220 <main+0x70>
mov    %r15,%rdi
mov    %r13,%rsi
call   1090 <BN_cmp@plt>
lea    0xd31(%rip),%rdi
test   %rax,%rax
jne    1220 <main+0x70>
jmp    122b <main+0x7b>

LLVM IR (-O0):
@.str = [14 x i8] c"BN_div failed\00"
@.str.1 = [19 x i8] c"BN_div_recp failed\00"
@.str.2 = [9 x i8] c"mismatch\00"
define i32 @main() {
%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 0, i32* %1
%10 = call i32* (...) @BN_new()
store i32* %10, i32** %2
%11 = call i32* (...) @BN_new()
store i32* %11, i32** %3
%12 = call i32* (...) @BN_new()
store i32* %12, i32** %4
%13 = call i32* (...) @BN_new()
store i32* %13, i32** %5
%14 = call i32* (...) @BN_new()
store i32* %14, i32** %6
%15 = call i32* (...) @BN_new()
store i32* %15, i32** %7
%16 = call i32* (...) @BN_RECP_CTX_new()
store i32* %16, i32** %8
%17 = call i32* (...) @BN_CTX_new()
store i32* %17, i32** %9
br label %18
18: ; preds = %72, %28, %0
%19 = load i32*, i32** %2
%20 = call i32 (...) @Rand()
%21 = call i32 @BN_pseudo_rand(i32* %19, i32 %20, i32 0, i32 0)
%22 = load i32*, i32** %3
%23 = call i32 (...) @Rand()
%24 = call i32 @BN_pseudo_rand(i32* %22, i32 %23, i32 0, i32 0)
%25 = load i32*, i32** %3
%26 = call i64 @BN_is_zero(i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %18
br label %18
29: ; preds = %18
%30 = load i32*, i32** %8
%31 = load i32*, i32** %3
%32 = load i32*, i32** %9
%33 = call i32 @BN_RECP_CTX_set(i32* %30, i32* %31, i32* %32)
%34 = load i32*, i32** %6
%35 = load i32*, i32** %7
%36 = load i32*, i32** %2
%37 = load i32*, i32** %3
%38 = load i32*, i32** %9
%39 = call i32 @BN_div(i32* %34, i32* %35, i32* %36, i32* %37, i32* %38)
%40 = icmp ne i32 %39, 1
br i1 %40, label %41, label %45
41: ; preds = %29
%42 = load i32*, i32** %2
%43 = load i32*, i32** %3
%44 = call i32 @bug(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32* %42, i32* %43)
br label %45
45: ; preds = %41, %29
%46 = load i32*, i32** %4
%47 = load i32*, i32** %5
%48 = load i32*, i32** %2
%49 = load i32*, i32** %8
%50 = load i32*, i32** %9
%51 = call i32 @BN_div_recp(i32* %46, i32* %47, i32* %48, i32* %49, i32* %50)
%52 = icmp ne i32 %51, 1
br i1 %52, label %53, label %57
53: ; preds = %45
%54 = load i32*, i32** %2
%55 = load i32*, i32** %3
%56 = call i32 @bug(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32* %54, i32* %55)
br label %72
57: ; preds = %45
%58 = load i32*, i32** %4
%59 = load i32*, i32** %6
%60 = call i64 @BN_cmp(i32* %58, i32* %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %67, label %62
62: ; preds = %57
%63 = load i32*, i32** %4
%64 = load i32*, i32** %6
%65 = call i64 @BN_cmp(i32* %63, i32* %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %71
67: ; preds = %62, %57
%68 = load i32*, i32** %2
%69 = load i32*, i32** %3
%70 = call i32 @bug(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %68, i32* %69)
br label %71
71: ; preds = %67, %62
br label %72
72: ; preds = %71, %53
br label %18
}

LLVM IR (-O2):
@.str = [14 x i8] c"BN_div failed\00"
@.str.1 = [19 x i8] c"BN_div_recp failed\00"
@.str.2 = [9 x i8] c"mismatch\00"
define i32 @main() {
%1 = tail call i32* (...) @BN_new()
%2 = tail call i32* (...) @BN_new()
%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_RECP_CTX_new()
%8 = tail call i32* (...) @BN_CTX_new()
br label %9
9: ; preds = %34, %0
%10 = tail call i32 (...) @Rand()
%11 = tail call i32 @BN_pseudo_rand(i32* %1, i32 %10, i32 0, i32 0)
%12 = tail call i32 (...) @Rand()
%13 = tail call i32 @BN_pseudo_rand(i32* %2, i32 %12, i32 0, i32 0)
%14 = tail call i64 @BN_is_zero(i32* %2)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %34
16: ; preds = %9
%17 = tail call i32 @BN_RECP_CTX_set(i32* %7, i32* %2, i32* %8)
%18 = tail call i32 @BN_div(i32* %5, i32* %6, i32* %1, i32* %2, i32* %8)
%19 = icmp eq i32 %18, 1
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = tail call i32 @bug(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
br label %22
22: ; preds = %20, %16
%23 = tail call i32 @BN_div_recp(i32* %3, i32* %4, i32* %1, i32* %7, i32* %8)
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = tail call i64 @BN_cmp(i32* %3, i32* %5)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = tail call i64 @BN_cmp(i32* %3, i32* %5)
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %25, %28, %22
%32 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), %22 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), %28 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), %25 ]
%33 = tail call i32 @bug(i8* %32, i32* %1, i32* %2)
br label %34
34: ; preds = %31, %28, %9
br label %9
}