#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;
  int ret = 0;
  if ((nbits < 1024) || (nbits & 0xff))
    return 0;
  nbits >>= 1;
  if (!BN_rand(Xp, nbits, 1, 0))
    return 0;
  BN_CTX_start(ctx);
  if ((t = BN_CTX_get(ctx)) == NULL)
    goto err;
  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;
  }
  if (i < 1000)
    ret = 1;
err:
  BN_CTX_end(ctx);
  return ret;
}


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)
movl   $0x0,-0x38(%rbp)
cmpl   $0x400,-0x1c(%rbp)
jl     119c <BN_X931_generate_Xpq+0x3c>
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
cmp    $0x0,%eax
je     11a8 <BN_X931_generate_Xpq+0x48>
movl   $0x0,-0x4(%rbp)
jmp    129b <BN_X931_generate_Xpq+0x13b>
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    11d9 <BN_X931_generate_Xpq+0x79>
movl   $0x0,-0x4(%rbp)
jmp    129b <BN_X931_generate_Xpq+0x13b>
mov    -0x28(%rbp),%rdi
call   1080 <BN_CTX_start@plt>
mov    -0x28(%rbp),%rdi
call   1040 <BN_CTX_get@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11fe <BN_X931_generate_Xpq+0x9e>
jmp    128c <BN_X931_generate_Xpq+0x12c>
movl   $0x0,-0x34(%rbp)
cmpl   $0x3e8,-0x34(%rbp)
jge    1273 <BN_X931_generate_Xpq+0x113>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <BN_rand@plt>
cmp    $0x0,%eax
jne    1233 <BN_X931_generate_Xpq+0xd3>
jmp    128c <BN_X931_generate_Xpq+0x12c>
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    1260 <BN_X931_generate_Xpq+0x100>
jmp    1273 <BN_X931_generate_Xpq+0x113>
jmp    1265 <BN_X931_generate_Xpq+0x105>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1205 <BN_X931_generate_Xpq+0xa5>
cmpl   $0x3e8,-0x34(%rbp)
jge    1287 <BN_X931_generate_Xpq+0x127>
movl   $0x1,-0x38(%rbp)
jmp    128c <BN_X931_generate_Xpq+0x12c>
mov    -0x28(%rbp),%rdi
call   1070 <BN_CTX_end@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-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    %ebp,%ebp
cmp    $0x400,%edx
jl     1249 <BN_X931_generate_Xpq+0xe9>
mov    %edx,%ebx
movzbl %bl,%eax
test   %eax,%eax
jne    1249 <BN_X931_generate_Xpq+0xe9>
mov    %rcx,%r14
mov    %rsi,%r15
shr    %ebx
xor    %ebp,%ebp
mov    0x10(%rsp),%rdi
mov    %ebx,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <BN_rand@plt>
test   %eax,%eax
je     1249 <BN_X931_generate_Xpq+0xe9>
mov    %r14,%rdi
call   1080 <BN_CTX_start@plt>
mov    %r14,%rdi
call   1040 <BN_CTX_get@plt>
test   %rax,%rax
je     123f <BN_X931_generate_Xpq+0xdf>
mov    %rax,%rbp
mov    %r14,0x8(%rsp)
lea    -0x64(%rbx),%r14d
mov    $0x1,%r13b
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <BN_rand@plt>
test   %eax,%eax
je     123a <BN_X931_generate_Xpq+0xda>
mov    %rbp,%rdi
mov    0x10(%rsp),%rsi
mov    %r15,%rdx
call   1060 <BN_sub@plt>
mov    %rbp,%rdi
call   1050 <BN_num_bits@plt>
cmp    %r14d,%eax
jg     122c <BN_X931_generate_Xpq+0xcc>
cmp    $0x3e7,%r12d
lea    0x1(%r12),%eax
setb   %r13b
mov    %eax,%r12d
cmp    $0x3e8,%eax
jne    11e0 <BN_X931_generate_Xpq+0x80>
movzbl %r13b,%ebp
and    $0x1,%ebp
mov    0x8(%rsp),%r14
jmp    1241 <BN_X931_generate_Xpq+0xe1>
mov    0x8(%rsp),%r14
xor    %ebp,%ebp
mov    %r14,%rdi
call   1070 <BN_CTX_end@plt>
mov    %ebp,%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
%12 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32 0, i32* %12
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 1024
br i1 %14, label %19, label %15
15: ; preds = %4
%16 = load i32, i32* %8
%17 = and i32 %16, 255
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15, %4
store i32 0, i32* %5
br label %69
20: ; preds = %15
%21 = load i32, i32* %8
%22 = ashr i32 %21, 1
store i32 %22, i32* %8
%23 = load i32*, i32** %6
%24 = load i32, i32* %8
%25 = call i32 @BN_rand(i32* %23, i32 %24, i32 1, i32 0)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %20
store i32 0, i32* %5
br label %69
28: ; preds = %20
%29 = load i32*, i32** %9
%30 = call i32 @BN_CTX_start(i32* %29)
%31 = load i32*, i32** %9
%32 = call i32* @BN_CTX_get(i32* %31)
store i32* %32, i32** %10
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %35
34: ; preds = %28
br label %65
35: ; preds = %28
store i32 0, i32* %11
br label %36
36: ; preds = %57, %35
%37 = load i32, i32* %11
%38 = icmp slt i32 %37, 1000
br i1 %38, label %39, label %60
39: ; preds = %36
%40 = load i32*, i32** %7
%41 = load i32, i32* %8
%42 = call i32 @BN_rand(i32* %40, i32 %41, i32 1, i32 0)
%43 = icmp ne i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %39
br label %65
45: ; preds = %39
%46 = load i32*, i32** %10
%47 = load i32*, i32** %6
%48 = load i32*, i32** %7
%49 = call i32 @BN_sub(i32* %46, i32* %47, i32* %48)
%50 = load i32*, i32** %10
%51 = call i32 @BN_num_bits(i32* %50)
%52 = load i32, i32* %8
%53 = sub nsw i32 %52, 100
%54 = icmp sgt i32 %51, %53
br i1 %54, label %55, label %56
55: ; preds = %45
br label %60
56: ; preds = %45
br label %57
57: ; preds = %56
%58 = load i32, i32* %11
%59 = add nsw i32 %58, 1
store i32 %59, i32* %11
br label %36
60: ; preds = %55, %36
%61 = load i32, i32* %11
%62 = icmp slt i32 %61, 1000
br i1 %62, label %63, label %64
63: ; preds = %60
store i32 1, i32* %12
br label %64
64: ; preds = %63, %60
br label %65
65: ; preds = %64, %44, %34
%66 = load i32*, i32** %9
%67 = call i32 @BN_CTX_end(i32* %66)
%68 = load i32, i32* %12
store i32 %68, i32* %5
br label %69
69: ; preds = %65, %27, %19
%70 = load i32, i32* %5
ret i32 %70
}

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 %38
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 %38, label %13
13: ; preds = %9
%14 = tail call i32 @BN_CTX_start(i32* %3)
%15 = tail call i32* @BN_CTX_get(i32* %3)
%16 = icmp eq i32* %15, null
br i1 %16, label %35, label %17
17: ; preds = %13
%18 = add nsw i32 %10, -100
br label %23
19: ; preds = %28
%20 = add nuw nsw i32 %25, 1
%21 = icmp ult i32 %25, 999
%22 = icmp eq i32 %20, 1000
br i1 %22, label %32, label %23
23: ; preds = %17, %19
%24 = phi i1 [ true, %17 ], [ %21, %19 ]
%25 = phi i32 [ 0, %17 ], [ %20, %19 ]
%26 = tail call i32 @BN_rand(i32* %1, i32 %10, i32 1, i32 0)
%27 = icmp eq i32 %26, 0
br i1 %27, label %35, label %28
28: ; preds = %23
%29 = tail call i32 @BN_sub(i32* %15, i32* %0, i32* %1)
%30 = tail call i32 @BN_num_bits(i32* %15)
%31 = icmp sgt i32 %30, %18
br i1 %31, label %32, label %19
32: ; preds = %28, %19
%33 = phi i1 [ %24, %28 ], [ %21, %19 ]
%34 = zext i1 %33 to i32
br label %35
35: ; preds = %23, %32, %13
%36 = phi i32 [ 0, %13 ], [ %34, %32 ], [ 0, %23 ]
%37 = tail call i32 @BN_CTX_end(i32* %3)
br label %38
38: ; preds = %9, %4, %35
%39 = phi i32 [ %36, %35 ], [ 0, %4 ], [ 0, %9 ]
ret i32 %39
}