#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_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 BN_num_bits(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_rand(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ BN_sub(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *);
int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx) {
  BIGNUM *t;
  int i;
  if ((nbits < 1024) || (nbits & 0xff))
    return 0;
  nbits >>= 1;
  if (!BN_rand(Xp, nbits, 1, 0))
    goto err;
  BN_CTX_start(ctx);
  t = BN_CTX_get(ctx);
  for (i = 0; i < 1000; i++) {
    if (!BN_rand(Xq, nbits, 1, 0))
      goto err;
    BN_sub(t, Xp, Xq);
    if (BN_num_bits(t) > (nbits - 100))
      break;
  }
  BN_CTX_end(ctx);
  if (i < 1000)
    return 1;
  return 0;
err:
  BN_CTX_end(ctx);
  return 0;
}


x86 assembly (clang, -O0):
<BN_X931_generate_Xpq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
cmpl   $0x400,-0x1c(%rbp)
jl     1195 <BN_X931_generate_Xpq+0x35>
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
cmp    $0x0,%eax
je     11a1 <BN_X931_generate_Xpq+0x41>
movl   $0x0,-0x4(%rbp)
jmp    1294 <BN_X931_generate_Xpq+0x134>
mov    -0x1c(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <BN_rand@plt>
cmp    $0x0,%eax
jne    11cb <BN_X931_generate_Xpq+0x6b>
jmp    1284 <BN_X931_generate_Xpq+0x124>
mov    -0x28(%rbp),%rdi
call   1080 <BN_CTX_start@plt>
mov    -0x28(%rbp),%rdi
call   1040 <BN_CTX_get@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x3e8,-0x34(%rbp)
jge    1256 <BN_X931_generate_Xpq+0xf6>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <BN_rand@plt>
cmp    $0x0,%eax
jne    1216 <BN_X931_generate_Xpq+0xb6>
jmp    1284 <BN_X931_generate_Xpq+0x124>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <BN_sub@plt>
mov    -0x30(%rbp),%rdi
call   1050 <BN_num_bits@plt>
mov    -0x1c(%rbp),%ecx
sub    $0x64,%ecx
cmp    %ecx,%eax
jle    1243 <BN_X931_generate_Xpq+0xe3>
jmp    1256 <BN_X931_generate_Xpq+0xf6>
jmp    1248 <BN_X931_generate_Xpq+0xe8>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11e8 <BN_X931_generate_Xpq+0x88>
mov    -0x28(%rbp),%rdi
call   1070 <BN_CTX_end@plt>
cmpl   $0x3e8,-0x34(%rbp)
jge    1278 <BN_X931_generate_Xpq+0x118>
movl   $0x1,-0x4(%rbp)
jmp    1294 <BN_X931_generate_Xpq+0x134>
movl   $0x0,-0x4(%rbp)
jmp    1294 <BN_X931_generate_Xpq+0x134>
mov    -0x28(%rbp),%rdi
call   1070 <BN_CTX_end@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BN_X931_generate_Xpq>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x10(%rsp)
xor    %eax,%eax
cmp    $0x400,%edx
jl     1248 <BN_X931_generate_Xpq+0xe8>
mov    %edx,%r13d
movzbl %r13b,%edx
test   %edx,%edx
jne    1248 <BN_X931_generate_Xpq+0xe8>
mov    %rsi,%r15
mov    %rcx,0x8(%rsp)
shr    %r13d
xor    %ebp,%ebp
mov    0x10(%rsp),%rdi
mov    %r13d,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <BN_rand@plt>
test   %eax,%eax
je     123c <BN_X931_generate_Xpq+0xdc>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <BN_CTX_start@plt>
mov    %rbx,%rdi
call   1040 <BN_CTX_get@plt>
mov    %rax,%rbx
lea    -0x64(%r13),%r12d
mov    $0x1,%r14b
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r13d,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <BN_rand@plt>
test   %eax,%eax
je     123c <BN_X931_generate_Xpq+0xdc>
mov    %rbx,%rdi
mov    0x10(%rsp),%rsi
mov    %r15,%rdx
call   1060 <BN_sub@plt>
mov    %rbx,%rdi
call   1050 <BN_num_bits@plt>
cmp    %r12d,%eax
jg     1229 <BN_X931_generate_Xpq+0xc9>
cmp    $0x3e7,%ebp
lea    0x1(%rbp),%eax
setb   %r14b
mov    %eax,%ebp
cmp    $0x3e8,%eax
jne    11e0 <BN_X931_generate_Xpq+0x80>
mov    0x8(%rsp),%rdi
call   1070 <BN_CTX_end@plt>
movzbl %r14b,%eax
and    $0x1,%eax
jmp    1248 <BN_X931_generate_Xpq+0xe8>
mov    0x8(%rsp),%rdi
call   1070 <BN_CTX_end@plt>
xor    %eax,%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_Xpq(i32* %0, i32* %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 1024
br i1 %13, label %18, label %14
14: ; preds = %4
%15 = load i32, i32* %8
%16 = and i32 %15, 255
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14, %4
store i32 0, i32* %5
br label %66
19: ; preds = %14
%20 = load i32, i32* %8
%21 = ashr i32 %20, 1
store i32 %21, i32* %8
%22 = load i32*, i32** %6
%23 = load i32, i32* %8
%24 = call i32 @BN_rand(i32* %22, i32 %23, i32 1, i32 0)
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %19
br label %63
27: ; preds = %19
%28 = load i32*, i32** %9
%29 = call i32 @BN_CTX_start(i32* %28)
%30 = load i32*, i32** %9
%31 = call i32* @BN_CTX_get(i32* %30)
store i32* %31, i32** %10
store i32 0, i32* %11
br label %32
32: ; preds = %53, %27
%33 = load i32, i32* %11
%34 = icmp slt i32 %33, 1000
br i1 %34, label %35, label %56
35: ; preds = %32
%36 = load i32*, i32** %7
%37 = load i32, i32* %8
%38 = call i32 @BN_rand(i32* %36, i32 %37, i32 1, i32 0)
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %35
br label %63
41: ; preds = %35
%42 = load i32*, i32** %10
%43 = load i32*, i32** %6
%44 = load i32*, i32** %7
%45 = call i32 @BN_sub(i32* %42, i32* %43, i32* %44)
%46 = load i32*, i32** %10
%47 = call i32 @BN_num_bits(i32* %46)
%48 = load i32, i32* %8
%49 = sub nsw i32 %48, 100
%50 = icmp sgt i32 %47, %49
br i1 %50, label %51, label %52
51: ; preds = %41
br label %56
52: ; preds = %41
br label %53
53: ; preds = %52
%54 = load i32, i32* %11
%55 = add nsw i32 %54, 1
store i32 %55, i32* %11
br label %32
56: ; preds = %51, %32
%57 = load i32*, i32** %9
%58 = call i32 @BN_CTX_end(i32* %57)
%59 = load i32, i32* %11
%60 = icmp slt i32 %59, 1000
br i1 %60, label %61, label %62
61: ; preds = %56
store i32 1, i32* %5
br label %66
62: ; preds = %56
store i32 0, i32* %5
br label %66
63: ; preds = %40, %26
%64 = load i32*, i32** %9
%65 = call i32 @BN_CTX_end(i32* %64)
store i32 0, i32* %5
br label %66
66: ; preds = %63, %62, %61, %18
%67 = load i32, i32* %5
ret i32 %67
}

LLVM IR (-O2):
define i32 @BN_X931_generate_Xpq(i32* %0, i32* %1, i32 %2, i32* %3) {
%5 = icmp sgt i32 %2, 1023
%6 = and i32 %2, 255
%7 = icmp eq i32 %6, 0
%8 = and i1 %5, %7
br i1 %8, label %9, label %36
9: ; preds = %4
%10 = lshr i32 %2, 1
%11 = tail call i32 @BN_rand(i32* %0, i32 %10, i32 1, i32 0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %34, label %13
13: ; preds = %9
%14 = tail call i32 @BN_CTX_start(i32* %3)
%15 = tail call i32* @BN_CTX_get(i32* %3)
%16 = add nsw i32 %10, -100
br label %21
17: ; preds = %26
%18 = add nuw nsw i32 %23, 1
%19 = icmp ult i32 %23, 999
%20 = icmp eq i32 %18, 1000
br i1 %20, label %30, label %21
21: ; preds = %13, %17
%22 = phi i1 [ true, %13 ], [ %19, %17 ]
%23 = phi i32 [ 0, %13 ], [ %18, %17 ]
%24 = tail call i32 @BN_rand(i32* %1, i32 %10, i32 1, i32 0)
%25 = icmp eq i32 %24, 0
br i1 %25, label %34, label %26
26: ; preds = %21
%27 = tail call i32 @BN_sub(i32* %15, i32* %0, i32* %1)
%28 = tail call i32 @BN_num_bits(i32* %15)
%29 = icmp sgt i32 %28, %16
br i1 %29, label %30, label %17
30: ; preds = %26, %17
%31 = phi i1 [ %22, %26 ], [ %19, %17 ]
%32 = tail call i32 @BN_CTX_end(i32* %3)
%33 = zext i1 %31 to i32
br label %36
34: ; preds = %21, %9
%35 = tail call i32 @BN_CTX_end(i32* %3)
br label %36
36: ; preds = %30, %4, %34
%37 = phi i32 [ 0, %34 ], [ 0, %4 ], [ %33, %30 ]
ret i32 %37
}