#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*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  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();
  int i = 0;
  for (i = 0; i < 10000; i++) {
    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);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-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   1040 <BN_new@plt>
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   10a0 <BN_RECP_CTX_new@plt>
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   1050 <BN_CTX_new@plt>
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x2710,-0x54(%rbp)
jge    1379 <main+0x1b9>
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    $0x0,%al
call   10e0 <Rand@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1070 <BN_pseudo_rand@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    $0x0,%al
call   10e0 <Rand@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1070 <BN_pseudo_rand@plt>
mov    -0x20(%rbp),%rdi
call   1060 <BN_is_zero@plt>
cmp    $0x0,%rax
je     129d <main+0xdd>
jmp    136b <main+0x1ab>
mov    -0x48(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x50(%rbp),%rdx
call   10c0 <BN_RECP_CTX_set@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x50(%rbp),%r8
call   10d0 <BN_div@plt>
cmp    $0x1,%eax
je     12e4 <main+0x124>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xd21(%rip),%rdi
call   1030 <bug@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x50(%rbp),%r8
call   1080 <BN_div_recp@plt>
cmp    $0x1,%eax
je     131f <main+0x15f>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xcf9(%rip),%rdi
call   1030 <bug@plt>
jmp    1366 <main+0x1a6>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1090 <BN_cmp@plt>
cmp    $0x0,%rax
jne    134d <main+0x18d>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1090 <BN_cmp@plt>
cmp    $0x0,%rax
je     1361 <main+0x1a1>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xcc5(%rip),%rdi
call   1030 <bug@plt>
jmp    1366 <main+0x1a6>
jmp    136b <main+0x1ab>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    123c <main+0x7c>
xor    %edi,%edi
call   10b0 <exit@plt>

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,(%rsp)
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
mov    $0x2710,%r15d
jmp    1245 <main+0x85>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <bug@plt>
add    $0xffffffff,%r15d
je     131b <main+0x15b>
xor    %eax,%eax
call   10e0 <Rand@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1070 <BN_pseudo_rand@plt>
xor    %eax,%eax
call   10e0 <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    123b <main+0x7b>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   10c0 <BN_RECP_CTX_set@plt>
mov    %r13,%rdi
mov    0x8(%rsp),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %rbp,%r8
call   10d0 <BN_div@plt>
cmp    $0x1,%eax
je     12b7 <main+0xf7>
lea    0xd54(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <bug@plt>
mov    (%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %rbp,%r8
call   1080 <BN_div_recp@plt>
lea    0xd39(%rip),%rdi
cmp    $0x1,%eax
jne    1230 <main+0x70>
mov    (%rsp),%rdi
mov    %r13,%rsi
call   1090 <BN_cmp@plt>
lea    0xd30(%rip),%rdi
test   %rax,%rax
jne    1230 <main+0x70>
mov    (%rsp),%rdi
mov    %r13,%rsi
call   1090 <BN_cmp@plt>
lea    0xd14(%rip),%rdi
test   %rax,%rax
jne    1230 <main+0x70>
jmp    123b <main+0x7b>
xor    %edi,%edi
call   10b0 <exit@plt>

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(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 i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = call i32* (...) @BN_new()
store i32* %15, i32** %6
%16 = call i32* (...) @BN_new()
store i32* %16, i32** %7
%17 = call i32* (...) @BN_new()
store i32* %17, i32** %8
%18 = call i32* (...) @BN_new()
store i32* %18, i32** %9
%19 = call i32* (...) @BN_new()
store i32* %19, i32** %10
%20 = call i32* (...) @BN_new()
store i32* %20, i32** %11
%21 = call i32* (...) @BN_RECP_CTX_new()
store i32* %21, i32** %12
%22 = call i32* (...) @BN_CTX_new()
store i32* %22, i32** %13
store i32 0, i32* %14
store i32 0, i32* %14
br label %23
23: ; preds = %81, %2
%24 = load i32, i32* %14
%25 = icmp slt i32 %24, 10000
br i1 %25, label %26, label %84
26: ; preds = %23
%27 = load i32*, i32** %6
%28 = call i32 (...) @Rand()
%29 = call i32 @BN_pseudo_rand(i32* %27, i32 %28, i32 0, i32 0)
%30 = load i32*, i32** %7
%31 = call i32 (...) @Rand()
%32 = call i32 @BN_pseudo_rand(i32* %30, i32 %31, i32 0, i32 0)
%33 = load i32*, i32** %7
%34 = call i64 @BN_is_zero(i32* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %26
br label %81
37: ; preds = %26
%38 = load i32*, i32** %12
%39 = load i32*, i32** %7
%40 = load i32*, i32** %13
%41 = call i32 @BN_RECP_CTX_set(i32* %38, i32* %39, i32* %40)
%42 = load i32*, i32** %10
%43 = load i32*, i32** %11
%44 = load i32*, i32** %6
%45 = load i32*, i32** %7
%46 = load i32*, i32** %13
%47 = call i32 @BN_div(i32* %42, i32* %43, i32* %44, i32* %45, i32* %46)
%48 = icmp ne i32 %47, 1
br i1 %48, label %49, label %53
49: ; preds = %37
%50 = load i32*, i32** %6
%51 = load i32*, i32** %7
%52 = call i32 @bug(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32* %50, i32* %51)
br label %53
53: ; preds = %49, %37
%54 = load i32*, i32** %8
%55 = load i32*, i32** %9
%56 = load i32*, i32** %6
%57 = load i32*, i32** %12
%58 = load i32*, i32** %13
%59 = call i32 @BN_div_recp(i32* %54, i32* %55, i32* %56, i32* %57, i32* %58)
%60 = icmp ne i32 %59, 1
br i1 %60, label %61, label %65
61: ; preds = %53
%62 = load i32*, i32** %6
%63 = load i32*, i32** %7
%64 = call i32 @bug(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32* %62, i32* %63)
br label %80
65: ; preds = %53
%66 = load i32*, i32** %8
%67 = load i32*, i32** %10
%68 = call i64 @BN_cmp(i32* %66, i32* %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %75, label %70
70: ; preds = %65
%71 = load i32*, i32** %8
%72 = load i32*, i32** %10
%73 = call i64 @BN_cmp(i32* %71, i32* %72)
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %79
75: ; preds = %70, %65
%76 = load i32*, i32** %6
%77 = load i32*, i32** %7
%78 = call i32 @bug(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %76, i32* %77)
br label %79
79: ; preds = %75, %70
br label %80
80: ; preds = %79, %61
br label %81
81: ; preds = %80, %36
%82 = load i32, i32* %14
%83 = add nsw i32 %82, 1
store i32 %83, i32* %14
br label %23
84: ; preds = %23
%85 = call i32 @exit(i32 0)
unreachable
}

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(i32 %0, i8** nocapture readnone %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_new()
%9 = tail call i32* (...) @BN_RECP_CTX_new()
%10 = tail call i32* (...) @BN_CTX_new()
br label %11
11: ; preds = %2, %37
%12 = phi i32 [ 0, %2 ], [ %38, %37 ]
%13 = tail call i32 (...) @Rand()
%14 = tail call i32 @BN_pseudo_rand(i32* %3, i32 %13, i32 0, i32 0)
%15 = tail call i32 (...) @Rand()
%16 = tail call i32 @BN_pseudo_rand(i32* %4, i32 %15, i32 0, i32 0)
%17 = tail call i64 @BN_is_zero(i32* %4)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %37
19: ; preds = %11
%20 = tail call i32 @BN_RECP_CTX_set(i32* %9, i32* %4, i32* %10)
%21 = tail call i32 @BN_div(i32* %7, i32* %8, i32* %3, i32* %4, i32* %10)
%22 = icmp eq i32 %21, 1
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = tail call i32 @bug(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4)
br label %25
25: ; preds = %23, %19
%26 = tail call i32 @BN_div_recp(i32* %5, i32* %6, i32* %3, i32* %9, i32* %10)
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = tail call i64 @BN_cmp(i32* %5, i32* %7)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = tail call i64 @BN_cmp(i32* %5, i32* %7)
%33 = icmp eq i64 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %28, %31, %25
%35 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), %25 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), %31 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), %28 ]
%36 = tail call i32 @bug(i8* %35, i32* %3, i32* %4)
br label %37
37: ; preds = %34, %31, %11
%38 = add nuw nsw i32 %12, 1
%39 = icmp eq i32 %38, 10000
br i1 %39, label %40, label %11
40: ; preds = %37
%41 = tail call i32 @exit(i32 0)
unreachable
}