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

/* Variables and functions */
int /*<<< orphan*/ BN_CTX_end(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_CTX_get(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_CTX_start(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_X931_derive_prime_ex(
    int /*<<< orphan*/ *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
    int /*<<< orphan*/ const *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
    int /*<<< orphan*/ const *, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_rand(int /*<<< orphan*/ *, int, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int BN_X931_generate_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, BIGNUM *Xp1,
                              BIGNUM *Xp2, const BIGNUM *Xp, const BIGNUM *e,
                              BN_CTX *ctx, BN_GENCB *cb) {
  int ret = 0;
  BN_CTX_start(ctx);
  if (!Xp1)
    Xp1 = BN_CTX_get(ctx);
  if (!Xp2)
    Xp2 = BN_CTX_get(ctx);
  if (!BN_rand(Xp1, 101, 0, 0))
    goto error;
  if (!BN_rand(Xp2, 101, 0, 0))
    goto error;
  if (!BN_X931_derive_prime_ex(p, p1, p2, Xp, Xp1, Xp2, e, ctx, cb))
    goto error;
  ret = 1;
error:
  BN_CTX_end(ctx);
  return ret;
}


x86 assembly (clang, -O0):
<BN_X931_generate_prime_ex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    0x18(%rbp),%rdi
call   1070 <BN_CTX_start@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11a4 <BN_X931_generate_prime_ex+0x54>
mov    0x18(%rbp),%rdi
call   1040 <BN_CTX_get@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11bc <BN_X931_generate_prime_ex+0x6c>
mov    0x18(%rbp),%rdi
call   1040 <BN_CTX_get@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x65,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1030 <BN_rand@plt>
cmp    $0x0,%eax
jne    11dc <BN_X931_generate_prime_ex+0x8c>
jmp    1248 <BN_X931_generate_prime_ex+0xf8>
mov    -0x28(%rbp),%rdi
mov    $0x65,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1030 <BN_rand@plt>
cmp    $0x0,%eax
jne    11fc <BN_X931_generate_prime_ex+0xac>
jmp    1248 <BN_X931_generate_prime_ex+0xf8>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    0x10(%rbp),%r11
mov    0x18(%rbp),%r10
mov    0x20(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1050 <BN_X931_derive_prime_ex@plt>
cmp    $0x0,%eax
jne    1241 <BN_X931_generate_prime_ex+0xf1>
jmp    1248 <BN_X931_generate_prime_ex+0xf8>
movl   $0x1,-0x34(%rbp)
mov    0x18(%rbp),%rdi
call   1060 <BN_CTX_end@plt>
mov    -0x34(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BN_X931_generate_prime_ex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,0x10(%rsp)
mov    %r8,%rbx
mov    %rcx,%rbp
mov    %rdx,0x8(%rsp)
mov    %rsi,%r13
mov    %rdi,%r14
mov    0x58(%rsp),%r12
mov    %r12,%rdi
call   1070 <BN_CTX_start@plt>
test   %rbp,%rbp
je     1213 <BN_X931_generate_prime_ex+0xc3>
test   %rbx,%rbx
je     1227 <BN_X931_generate_prime_ex+0xd7>
xor    %r15d,%r15d
mov    %rbp,%rdi
mov    $0x65,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <BN_rand@plt>
test   %eax,%eax
je     11f9 <BN_X931_generate_prime_ex+0xa9>
xor    %r15d,%r15d
mov    %rbx,%rdi
mov    $0x65,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <BN_rand@plt>
test   %eax,%eax
je     11f9 <BN_X931_generate_prime_ex+0xa9>
sub    $0x8,%rsp
mov    %r14,%rdi
mov    %r13,%rsi
mov    0x10(%rsp),%rdx
mov    0x18(%rsp),%rcx
mov    %rbp,%r8
mov    %rbx,%r9
push   0x68(%rsp)
push   %r12
push   0x68(%rsp)
call   1050 <BN_X931_derive_prime_ex@plt>
add    $0x20,%rsp
xor    %r15d,%r15d
test   %eax,%eax
setne  %r15b
mov    %r12,%rdi
call   1060 <BN_CTX_end@plt>
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,%rdi
call   1040 <BN_CTX_get@plt>
mov    %rax,%rbp
test   %rbx,%rbx
jne    1193 <BN_X931_generate_prime_ex+0x43>
mov    %r12,%rdi
call   1040 <BN_CTX_get@plt>
mov    %rax,%rbx
jmp    1193 <BN_X931_generate_prime_ex+0x43>

LLVM IR (-O0):
define i32 @BN_X931_generate_prime_ex(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7, i32* %8) {
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca i32
store i32* %0, i32** %10
store i32* %1, i32** %11
store i32* %2, i32** %12
store i32* %3, i32** %13
store i32* %4, i32** %14
store i32* %5, i32** %15
store i32* %6, i32** %16
store i32* %7, i32** %17
store i32* %8, i32** %18
store i32 0, i32* %19
%20 = load i32*, i32** %17
%21 = call i32 @BN_CTX_start(i32* %20)
%22 = load i32*, i32** %13
%23 = icmp ne i32* %22, null
br i1 %23, label %27, label %24
24: ; preds = %9
%25 = load i32*, i32** %17
%26 = call i32* @BN_CTX_get(i32* %25)
store i32* %26, i32** %13
br label %27
27: ; preds = %24, %9
%28 = load i32*, i32** %14
%29 = icmp ne i32* %28, null
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load i32*, i32** %17
%32 = call i32* @BN_CTX_get(i32* %31)
store i32* %32, i32** %14
br label %33
33: ; preds = %30, %27
%34 = load i32*, i32** %13
%35 = call i32 @BN_rand(i32* %34, i32 101, i32 0, i32 0)
%36 = icmp ne i32 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %33
br label %57
38: ; preds = %33
%39 = load i32*, i32** %14
%40 = call i32 @BN_rand(i32* %39, i32 101, i32 0, i32 0)
%41 = icmp ne i32 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %38
br label %57
43: ; preds = %38
%44 = load i32*, i32** %10
%45 = load i32*, i32** %11
%46 = load i32*, i32** %12
%47 = load i32*, i32** %15
%48 = load i32*, i32** %13
%49 = load i32*, i32** %14
%50 = load i32*, i32** %16
%51 = load i32*, i32** %17
%52 = load i32*, i32** %18
%53 = call i32 @BN_X931_derive_prime_ex(i32* %44, i32* %45, i32* %46, i32* %47, i32* %48, i32* %49, i32* %50, i32* %51, i32* %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %56, label %55
55: ; preds = %43
br label %57
56: ; preds = %43
store i32 1, i32* %19
br label %57
57: ; preds = %56, %55, %42, %37
%58 = load i32*, i32** %17
%59 = call i32 @BN_CTX_end(i32* %58)
%60 = load i32, i32* %19
ret i32 %60
}

LLVM IR (-O2):
define i32 @BN_X931_generate_prime_ex(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7, i32* %8) {
%10 = tail call i32 @BN_CTX_start(i32* %7)
%11 = icmp eq i32* %3, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32* @BN_CTX_get(i32* %7)
br label %14
14: ; preds = %12, %9
%15 = phi i32* [ %3, %9 ], [ %13, %12 ]
%16 = icmp eq i32* %4, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32* @BN_CTX_get(i32* %7)
br label %19
19: ; preds = %17, %14
%20 = phi i32* [ %4, %14 ], [ %18, %17 ]
%21 = tail call i32 @BN_rand(i32* %15, i32 101, i32 0, i32 0)
%22 = icmp eq i32 %21, 0
br i1 %22, label %30, label %23
23: ; preds = %19
%24 = tail call i32 @BN_rand(i32* %20, i32 101, i32 0, i32 0)
%25 = icmp eq i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %23
%27 = tail call i32 @BN_X931_derive_prime_ex(i32* %0, i32* %1, i32* %2, i32* %5, i32* %15, i32* %20, i32* %6, i32* %7, i32* %8)
%28 = icmp ne i32 %27, 0
%29 = zext i1 %28 to i32
br label %30
30: ; preds = %26, %23, %19
%31 = phi i32 [ 0, %23 ], [ 0, %19 ], [ %29, %26 ]
%32 = tail call i32 @BN_CTX_end(i32* %7)
ret i32 %31
}