#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 == NULL) {
    if ((Xp1 = BN_CTX_get(ctx)) == NULL)
      goto error;
  }
  if (Xp2 == NULL) {
    if ((Xp2 = BN_CTX_get(ctx)) == NULL)
      goto error;
  }
  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    11b8 <BN_X931_generate_prime_ex+0x68>
mov    0x18(%rbp),%rdi
call   1040 <BN_CTX_get@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11b3 <BN_X931_generate_prime_ex+0x63>
jmp    1270 <BN_X931_generate_prime_ex+0x120>
jmp    11b8 <BN_X931_generate_prime_ex+0x68>
cmpq   $0x0,-0x28(%rbp)
jne    11e4 <BN_X931_generate_prime_ex+0x94>
mov    0x18(%rbp),%rdi
call   1040 <BN_CTX_get@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11df <BN_X931_generate_prime_ex+0x8f>
jmp    1270 <BN_X931_generate_prime_ex+0x120>
jmp    11e4 <BN_X931_generate_prime_ex+0x94>
mov    -0x20(%rbp),%rdi
mov    $0x65,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1030 <BN_rand@plt>
cmp    $0x0,%eax
jne    1204 <BN_X931_generate_prime_ex+0xb4>
jmp    1270 <BN_X931_generate_prime_ex+0x120>
mov    -0x28(%rbp),%rdi
mov    $0x65,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1030 <BN_rand@plt>
cmp    $0x0,%eax
jne    1224 <BN_X931_generate_prime_ex+0xd4>
jmp    1270 <BN_X931_generate_prime_ex+0x120>
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    1269 <BN_X931_generate_prime_ex+0x119>
jmp    1270 <BN_X931_generate_prime_ex+0x120>
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,%r15
mov    %r8,%rbx
mov    %rcx,%rbp
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,0x10(%rsp)
mov    0x58(%rsp),%r12
mov    %r12,%rdi
call   1070 <BN_CTX_start@plt>
test   %rbp,%rbp
jne    1198 <BN_X931_generate_prime_ex+0x48>
mov    %r12,%rdi
call   1040 <BN_CTX_get@plt>
mov    %rax,%rbp
test   %rax,%rax
je     121a <BN_X931_generate_prime_ex+0xca>
test   %rbx,%rbx
jne    11ad <BN_X931_generate_prime_ex+0x5d>
mov    %r12,%rdi
call   1040 <BN_CTX_get@plt>
mov    %rax,%rbx
test   %rax,%rax
je     121a <BN_X931_generate_prime_ex+0xca>
mov    %r15,0x8(%rsp)
xor    %r15d,%r15d
mov    %rbp,%rdi
mov    $0x65,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <BN_rand@plt>
test   %eax,%eax
je     121d <BN_X931_generate_prime_ex+0xcd>
xor    %r15d,%r15d
mov    %rbx,%rdi
mov    $0x65,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <BN_rand@plt>
test   %eax,%eax
je     121d <BN_X931_generate_prime_ex+0xcd>
sub    $0x8,%rsp
mov    0x18(%rsp),%rdi
mov    %r14,%rsi
mov    %r13,%rdx
mov    0x10(%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
jmp    121d <BN_X931_generate_prime_ex+0xcd>
xor    %r15d,%r15d
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

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 eq i32* %22, null
br i1 %23, label %24, label %30
24: ; preds = %9
%25 = load i32*, i32** %17
%26 = call i32* @BN_CTX_get(i32* %25)
store i32* %26, i32** %13
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %29
28: ; preds = %24
br label %63
29: ; preds = %24
br label %30
30: ; preds = %29, %9
%31 = load i32*, i32** %14
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %39
33: ; preds = %30
%34 = load i32*, i32** %17
%35 = call i32* @BN_CTX_get(i32* %34)
store i32* %35, i32** %14
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %38
37: ; preds = %33
br label %63
38: ; preds = %33
br label %39
39: ; preds = %38, %30
%40 = load i32*, i32** %13
%41 = call i32 @BN_rand(i32* %40, i32 101, i32 0, i32 0)
%42 = icmp ne i32 %41, 0
br i1 %42, label %44, label %43
43: ; preds = %39
br label %63
44: ; preds = %39
%45 = load i32*, i32** %14
%46 = call i32 @BN_rand(i32* %45, i32 101, i32 0, i32 0)
%47 = icmp ne i32 %46, 0
br i1 %47, label %49, label %48
48: ; preds = %44
br label %63
49: ; preds = %44
%50 = load i32*, i32** %10
%51 = load i32*, i32** %11
%52 = load i32*, i32** %12
%53 = load i32*, i32** %15
%54 = load i32*, i32** %13
%55 = load i32*, i32** %14
%56 = load i32*, i32** %16
%57 = load i32*, i32** %17
%58 = load i32*, i32** %18
%59 = call i32 @BN_X931_derive_prime_ex(i32* %50, i32* %51, i32* %52, i32* %53, i32* %54, i32* %55, i32* %56, i32* %57, i32* %58)
%60 = icmp ne i32 %59, 0
br i1 %60, label %62, label %61
61: ; preds = %49
br label %63
62: ; preds = %49
store i32 1, i32* %19
br label %63
63: ; preds = %62, %61, %48, %43, %37, %28
%64 = load i32*, i32** %17
%65 = call i32 @BN_CTX_end(i32* %64)
%66 = load i32, i32* %19
ret i32 %66
}

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 %15
12: ; preds = %9
%13 = tail call i32* @BN_CTX_get(i32* %7)
%14 = icmp eq i32* %13, null
br i1 %14, label %32, label %15
15: ; preds = %12, %9
%16 = phi i32* [ %13, %12 ], [ %3, %9 ]
%17 = icmp eq i32* %4, null
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = tail call i32* @BN_CTX_get(i32* %7)
%20 = icmp eq i32* %19, null
br i1 %20, label %32, label %21
21: ; preds = %18, %15
%22 = phi i32* [ %19, %18 ], [ %4, %15 ]
%23 = tail call i32 @BN_rand(i32* %16, i32 101, i32 0, i32 0)
%24 = icmp eq i32 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %21
%26 = tail call i32 @BN_rand(i32* %22, i32 101, i32 0, i32 0)
%27 = icmp eq i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %25
%29 = tail call i32 @BN_X931_derive_prime_ex(i32* %0, i32* %1, i32* %2, i32* %5, i32* %16, i32* %22, i32* %6, i32* %7, i32* %8)
%30 = icmp ne i32 %29, 0
%31 = zext i1 %30 to i32
br label %32
32: ; preds = %28, %25, %21, %18, %12
%33 = phi i32 [ 0, %12 ], [ 0, %18 ], [ 0, %25 ], [ 0, %21 ], [ %31, %28 ]
%34 = tail call i32 @BN_CTX_end(i32* %7)
ret i32 %33
}