#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_free(int /*<<< orphan*/ *);
scalar_t__ BN_generate_prime_ex(int /*<<< orphan*/ *, int, int,
                                int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                int /*<<< orphan*/ *);
int /*<<< orphan*/ *BN_new();
int /*<<< orphan*/ BN_num_bits(int /*<<< orphan*/ *);
int /*<<< orphan*/ test_false(char *, int, char *, int);
int /*<<< orphan*/ test_int_eq(char *, int, char *, char *, int /*<<< orphan*/,
                               int);
int /*<<< orphan*/ test_ptr(char *, int, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ test_true(char *, int, char *, int);
int test_smallsafeprime(int kBits) {
  BIGNUM *r;
  int st = 0;
  if (!test_ptr("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/"
                "refs/heads/master/Src/OSF/OpenSSL-111/test/bntest.c",
                2201, "r = BN_new()", r = BN_new()))
    goto err;
  if (kBits <= 5 && kBits != 3) {
    if (!test_false(
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/heads/"
            "master/Src/OSF/OpenSSL-111/test/bntest.c",
            2205, "BN_generate_prime_ex(r, kBits, 1, NULL, NULL, NULL)",
            (BN_generate_prime_ex(r, kBits, 1, NULL, NULL, NULL)) != 0))
      goto err;
  } else {
    if (!test_true(
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/heads/"
            "master/Src/OSF/OpenSSL-111/test/bntest.c",
            2209, "BN_generate_prime_ex(r, kBits, 1, NULL, NULL, NULL)",
            (BN_generate_prime_ex(r, kBits, 1, NULL, NULL, NULL)) != 0) ||
        !test_int_eq(
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/heads/"
            "master/Src/OSF/OpenSSL-111/test/bntest.c",
            2211, "BN_num_bits(r)", "kBits", BN_num_bits(r), kBits))
      goto err;
  }
  st = 1;
err:
  BN_free(r);
  return st;
}


x86 assembly (clang, -O0):
<test_smallsafeprime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1050 <BN_new@plt>
mov    %rax,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xe59(%rip),%rdi
mov    $0x899,%esi
lea    0xef7(%rip),%rdx
call   1080 <test_ptr@plt>
cmp    $0x0,%eax
jne    11c6 <test_smallsafeprime+0x46>
jmp    12bf <test_smallsafeprime+0x13f>
cmpl   $0x5,-0x4(%rbp)
jg     122d <test_smallsafeprime+0xad>
cmpl   $0x3,-0x4(%rbp)
je     122d <test_smallsafeprime+0xad>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    $0x1,%edx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%rcx
mov    %r9,%r8
call   1070 <BN_generate_prime_ex@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%ecx
lea    0xdf7(%rip),%rdi
mov    $0x89d,%esi
lea    0xea2(%rip),%rdx
call   1030 <test_false@plt>
cmp    $0x0,%eax
jne    1228 <test_smallsafeprime+0xa8>
jmp    12bf <test_smallsafeprime+0x13f>
jmp    12b8 <test_smallsafeprime+0x138>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    $0x1,%edx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%rcx
mov    %r9,%r8
call   1070 <BN_generate_prime_ex@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%ecx
lea    0xda4(%rip),%rdi
mov    $0x8a1,%esi
lea    0xe4f(%rip),%rdx
call   1040 <test_true@plt>
cmp    $0x0,%eax
je     12ae <test_smallsafeprime+0x12e>
mov    -0x10(%rbp),%rdi
call   1060 <BN_num_bits@plt>
mov    %eax,%r8d
mov    -0x4(%rbp),%r9d
lea    0xd73(%rip),%rdi
mov    $0x8a3,%esi
lea    0xe52(%rip),%rdx
lea    0xe5a(%rip),%rcx
call   1090 <test_int_eq@plt>
cmp    $0x0,%eax
jne    12b3 <test_smallsafeprime+0x133>
jmp    12bf <test_smallsafeprime+0x13f>
jmp    12b8 <test_smallsafeprime+0x138>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <BN_free@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_smallsafeprime>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,%rbx
lea    0xe66(%rip),%rdi
lea    0xf09(%rip),%rdx
mov    $0x899,%esi
mov    %rax,%rcx
call   1080 <test_ptr@plt>
test   %eax,%eax
je     1253 <test_smallsafeprime+0xd3>
xor    %r14d,%r14d
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1070 <BN_generate_prime_ex@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
cmp    $0x5,%ebp
jg     1200 <test_smallsafeprime+0x80>
cmp    $0x3,%ebp
je     1200 <test_smallsafeprime+0x80>
lea    0xe17(%rip),%rdi
lea    0xec7(%rip),%rdx
mov    $0x89d,%esi
call   1030 <test_false@plt>
test   %eax,%eax
jne    124d <test_smallsafeprime+0xcd>
jmp    1253 <test_smallsafeprime+0xd3>
lea    0xdf9(%rip),%rdi
lea    0xea9(%rip),%rdx
mov    $0x8a1,%esi
call   1040 <test_true@plt>
test   %eax,%eax
je     1253 <test_smallsafeprime+0xd3>
mov    %rbx,%rdi
call   1060 <BN_num_bits@plt>
lea    0xdd5(%rip),%rdi
lea    0xeb9(%rip),%rdx
lea    0xec1(%rip),%rcx
mov    $0x8a3,%esi
mov    %eax,%r8d
mov    %ebp,%r9d
call   1090 <test_int_eq@plt>
test   %eax,%eax
je     1253 <test_smallsafeprime+0xd3>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   10a0 <BN_free@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [170 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/heads/master/Src/OSF/OpenSSL-111/test/bntest.c\00"
@.str.1 = [13 x i8] c"r = BN_new()\00"
@.str.2 = [52 x i8] c"BN_generate_prime_ex(r, kBits, 1, NULL, NULL, NULL)\00"
@.str.3 = [15 x i8] c"BN_num_bits(r)\00"
@.str.4 = [6 x i8] c"kBits\00"
define i32 @test_smallsafeprime(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
%5 = call i32* (...) @BN_new()
store i32* %5, i32** %3
%6 = call i32 @test_ptr(i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str, i64 0, i64 0), i32 2201, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %9, label %8
8: ; preds = %1
br label %42
9: ; preds = %1
%10 = load i32, i32* %2
%11 = icmp sle i32 %10, 5
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = load i32, i32* %2
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = load i32*, i32** %3
%17 = load i32, i32* %2
%18 = call i64 @BN_generate_prime_ex(i32* %16, i32 %17, i32 1, i32* null, i32* null, i32* null)
%19 = icmp ne i64 %18, 0
%20 = zext i1 %19 to i32
%21 = call i32 @test_false(i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str, i64 0, i64 0), i32 2205, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %15
br label %42
24: ; preds = %15
br label %41
25: ; preds = %12, %9
%26 = load i32*, i32** %3
%27 = load i32, i32* %2
%28 = call i64 @BN_generate_prime_ex(i32* %26, i32 %27, i32 1, i32* null, i32* null, i32* null)
%29 = icmp ne i64 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @test_true(i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str, i64 0, i64 0), i32 2209, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %25
%34 = load i32*, i32** %3
%35 = call i32 @BN_num_bits(i32* %34)
%36 = load i32, i32* %2
%37 = call i32 @test_int_eq(i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str, i64 0, i64 0), i32 2211, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %35, i32 %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %33, %25
br label %42
40: ; preds = %33
br label %41
41: ; preds = %40, %24
store i32 1, i32* %4
br label %42
42: ; preds = %41, %39, %23, %8
%43 = load i32*, i32** %3
%44 = call i32 @BN_free(i32* %43)
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
@.str = [170 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/papyrussolution/OpenPapyrus/refs/heads/master/Src/OSF/OpenSSL-111/test/bntest.c\00"
@.str.1 = [13 x i8] c"r = BN_new()\00"
@.str.2 = [52 x i8] c"BN_generate_prime_ex(r, kBits, 1, NULL, NULL, NULL)\00"
@.str.3 = [15 x i8] c"BN_num_bits(r)\00"
@.str.4 = [6 x i8] c"kBits\00"
define i32 @test_smallsafeprime(i32 %0) {
%2 = tail call i32* (...) @BN_new()
%3 = tail call i32 @test_ptr(i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str, i64 0, i64 0), i32 2201, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %23, label %5
5: ; preds = %1
%6 = icmp slt i32 %0, 6
%7 = icmp ne i32 %0, 3
%8 = and i1 %6, %7
%9 = tail call i64 @BN_generate_prime_ex(i32* %2, i32 %0, i32 1, i32* null, i32* null, i32* null)
%10 = icmp ne i64 %9, 0
%11 = zext i1 %10 to i32
br i1 %8, label %12, label %15
12: ; preds = %5
%13 = tail call i32 @test_false(i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str, i64 0, i64 0), i32 2205, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%14 = icmp eq i32 %13, 0
br i1 %14, label %23, label %22
15: ; preds = %5
%16 = tail call i32 @test_true(i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str, i64 0, i64 0), i32 2209, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%17 = icmp eq i32 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %15
%19 = tail call i32 @BN_num_bits(i32* %2)
%20 = tail call i32 @test_int_eq(i8* getelementptr inbounds ([170 x i8], [170 x i8]* @.str, i64 0, i64 0), i32 2211, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %19, i32 %0)
%21 = icmp eq i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %18, %12
br label %23
23: ; preds = %15, %18, %12, %1, %22
%24 = phi i32 [ 1, %22 ], [ 0, %12 ], [ 0, %18 ], [ 0, %15 ], [ 0, %1 ]
%25 = tail call i32 @BN_free(i32* %2)
ret i32 %24
}