#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)
    Xp1 = BN_CTX_get(ctx);
  if (Xp2 == NULL)
    Xp2 = BN_CTX_get(ctx);
  if (Xp1 == NULL || Xp2 == 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    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)
cmpq   $0x0,-0x20(%rbp)
je     11d2 <BN_X931_generate_prime_ex+0x82>
cmpq   $0x0,-0x28(%rbp)
jne    11d7 <BN_X931_generate_prime_ex+0x87>
jmp    1263 <BN_X931_generate_prime_ex+0x113>
mov    -0x20(%rbp),%rdi
mov    $0x65,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1030 <BN_rand@plt>
cmp    $0x0,%eax
jne    11f7 <BN_X931_generate_prime_ex+0xa7>
jmp    1263 <BN_X931_generate_prime_ex+0x113>
mov    -0x28(%rbp),%rdi
mov    $0x65,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1030 <BN_rand@plt>
cmp    $0x0,%eax
jne    1217 <BN_X931_generate_prime_ex+0xc7>
jmp    1263 <BN_X931_generate_prime_ex+0x113>
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    125c <BN_X931_generate_prime_ex+0x10c>
jmp    1263 <BN_X931_generate_prime_ex+0x113>
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     1227 <BN_X931_generate_prime_ex+0xd7>
test   %rbx,%rbx
jne    119a <BN_X931_generate_prime_ex+0x4a>
mov    %r12,%rdi
call   1040 <BN_CTX_get@plt>
mov    %rax,%rbx
xor    %r15d,%r15d
test   %rbp,%rbp
je     120d <BN_X931_generate_prime_ex+0xbd>
test   %rbx,%rbx
je     120d <BN_X931_generate_prime_ex+0xbd>
xor    %r15d,%r15d
mov    %rbp,%rdi
mov    $0x65,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <BN_rand@plt>
test   %eax,%eax
je     120d <BN_X931_generate_prime_ex+0xbd>
xor    %r15d,%r15d
mov    %rbx,%rdi
mov    $0x65,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <BN_rand@plt>
test   %eax,%eax
je     120d <BN_X931_generate_prime_ex+0xbd>
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    119a <BN_X931_generate_prime_ex+0x4a>
jmp    118f <BN_X931_generate_prime_ex+0x3f>

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

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