#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*/ BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ BN_add_word(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ BN_copy(int /*<<< orphan*/ *, int /*<<< orphan*/ const *);
int /*<<< orphan*/ BN_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_new();
int /*<<< orphan*/ BN_rand_range(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_sub_word(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ ERR_PUT_error(int, int, int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int genrand(BIGNUM *rnd, const BIGNUM *n) {
  BIGNUM *nm1 = NULL;
  int ret = 0;
  nm1 = BN_new();
  if (nm1 == NULL)
    goto err;
  if (!BN_copy(nm1, n))
    goto err;
  if (!BN_sub_word(nm1, 1))
    goto err;
  if (!BN_rand_range(rnd, nm1))
    goto err;
  if (!BN_add_word(rnd, 1))
    goto err;
  ret = 1;
err:
  if (!ret)
    ERR_PUT_error(
        50, (110), (ERR_R_MALLOC_FAILURE),
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/openweave/openweave-core/refs/heads/master/"
        "third_party/openssl-jpake/openssl/crypto/ecjpake/ecjpake.c",
        291);
  if (nm1 != NULL)
    BN_free(nm1);
  return ret;
}


x86 assembly (clang, -O0):
<genrand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <BN_new@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11aa <genrand+0x3a>
jmp    121f <genrand+0xaf>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <BN_copy@plt>
cmp    $0x0,%eax
jne    11c5 <genrand+0x55>
jmp    121f <genrand+0xaf>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1060 <BN_sub_word@plt>
cmp    $0x0,%eax
jne    11e1 <genrand+0x71>
jmp    121f <genrand+0xaf>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <BN_rand_range@plt>
cmp    $0x0,%eax
jne    11fc <genrand+0x8c>
jmp    121f <genrand+0xaf>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1070 <BN_add_word@plt>
cmp    $0x0,%eax
jne    1218 <genrand+0xa8>
jmp    121f <genrand+0xaf>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    124e <genrand+0xde>
mov    0x2db8(%rip),%rax
mov    (%rax),%edx
mov    $0x32,%edi
mov    $0x6e,%esi
lea    0xdbd(%rip),%rcx
mov    $0x123,%r8d
call   1050 <ERR_PUT_error@plt>
cmpq   $0x0,-0x18(%rbp)
je     1262 <genrand+0xf2>
mov    -0x18(%rbp),%rdi
call   1080 <BN_free@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genrand>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%r14
xor    %r15d,%r15d
xor    %eax,%eax
call   1030 <BN_new@plt>
test   %rax,%rax
je     1207 <genrand+0x97>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1090 <BN_copy@plt>
test   %eax,%eax
je     11d5 <genrand+0x65>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <BN_sub_word@plt>
test   %eax,%eax
je     11d5 <genrand+0x65>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <BN_rand_range@plt>
test   %eax,%eax
je     11d5 <genrand+0x65>
mov    $0x1,%r15d
mov    %r14,%rdi
mov    $0x1,%esi
call   1070 <BN_add_word@plt>
test   %eax,%eax
jne    11fd <genrand+0x8d>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edx
lea    0xe1b(%rip),%rcx
mov    $0x32,%edi
mov    $0x6e,%esi
mov    $0x123,%r8d
call   1050 <ERR_PUT_error@plt>
xor    %r15d,%r15d
mov    %rbx,%rdi
call   1080 <BN_free@plt>
jmp    122c <genrand+0xbc>
mov    0x2dda(%rip),%rax
mov    (%rax),%edx
lea    0xde9(%rip),%rcx
mov    $0x32,%edi
mov    $0x6e,%esi
mov    $0x123,%r8d
call   1050 <ERR_PUT_error@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ERR_R_MALLOC_FAILURE = global i32 0
@.str = [192 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/openweave/openweave-core/refs/heads/master/third_party/openssl-jpake/openssl/crypto/ecjpake/ecjpake.c\00"
define i32 @genrand(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32* null, i32** %5
store i32 0, i32* %6
%7 = call i32* (...) @BN_new()
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
br label %34
11: ; preds = %2
%12 = load i32*, i32** %5
%13 = load i32*, i32** %4
%14 = call i32 @BN_copy(i32* %12, i32* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %11
br label %34
17: ; preds = %11
%18 = load i32*, i32** %5
%19 = call i32 @BN_sub_word(i32* %18, i32 1)
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %17
br label %34
22: ; preds = %17
%23 = load i32*, i32** %3
%24 = load i32*, i32** %5
%25 = call i32 @BN_rand_range(i32* %23, i32* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %22
br label %34
28: ; preds = %22
%29 = load i32*, i32** %3
%30 = call i32 @BN_add_word(i32* %29, i32 1)
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %28
br label %34
33: ; preds = %28
store i32 1, i32* %6
br label %34
34: ; preds = %33, %32, %27, %21, %16, %10
%35 = load i32, i32* %6
%36 = icmp ne i32 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %34
%38 = load i32, i32* @ERR_R_MALLOC_FAILURE
%39 = call i32 @ERR_PUT_error(i32 50, i32 110, i32 %38, i8* getelementptr inbounds ([192 x i8], [192 x i8]* @.str, i64 0, i64 0), i32 291)
br label %40
40: ; preds = %37, %34
%41 = load i32*, i32** %5
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i32*, i32** %5
%45 = call i32 @BN_free(i32* %44)
br label %46
46: ; preds = %43, %40
%47 = load i32, i32* %6
ret i32 %47
}

LLVM IR (-O2):
@ERR_R_MALLOC_FAILURE = global i32 0
@.str = [192 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/openweave/openweave-core/refs/heads/master/third_party/openssl-jpake/openssl/crypto/ecjpake/ecjpake.c\00"
define i32 @genrand(i32* %0, i32* %1) {
%3 = tail call i32* (...) @BN_new()
%4 = icmp eq i32* %3, null
br i1 %4, label %17, label %5
5: ; preds = %2
%6 = tail call i32 @BN_copy(i32* %3, i32* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %5
%9 = tail call i32 @BN_sub_word(i32* %3, i32 1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %8
%12 = tail call i32 @BN_rand_range(i32* %0, i32* %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %11
%15 = tail call i32 @BN_add_word(i32* %0, i32 1)
%16 = icmp eq i32 %15, 0
br i1 %16, label %20, label %23
17: ; preds = %2
%18 = load i32, i32* @ERR_R_MALLOC_FAILURE
%19 = tail call i32 @ERR_PUT_error(i32 50, i32 110, i32 %18, i8* getelementptr inbounds ([192 x i8], [192 x i8]* @.str, i64 0, i64 0), i32 291)
br label %26
20: ; preds = %5, %8, %11, %14
%21 = load i32, i32* @ERR_R_MALLOC_FAILURE
%22 = tail call i32 @ERR_PUT_error(i32 50, i32 110, i32 %21, i8* getelementptr inbounds ([192 x i8], [192 x i8]* @.str, i64 0, i64 0), i32 291)
br label %23
23: ; preds = %20, %14
%24 = phi i32 [ 1, %14 ], [ 0, %20 ]
%25 = tail call i32 @BN_free(i32* %3)
br label %26
26: ; preds = %17, %23
%27 = phi i32 [ %24, %23 ], [ 0, %17 ]
ret i32 %27
}