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

/* Variables and functions */
int IsPrime(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_add_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
char *mpz_get_str(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_mod_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
scalar_t__ mpz_size(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void FindNearbyPrime(mpz_t candidate, int timeout) {
  mpz_t remainder;
  mpz_init(remainder);
  mpz_mod_ui(remainder, candidate, 2);
  if (mpz_size(remainder) == 0) {
    mpz_add_ui(candidate, candidate, 1);
  }
  int candidate_counter = 1;
  int candidate_status = IsPrime(candidate, timeout);
  while (candidate_status == 0) {
    printf("Trying new candidate (%i)\n", candidate_counter);
    candidate_counter++;
    mpz_add_ui(candidate, candidate, 2);
    candidate_status = IsPrime(candidate, timeout);
  }
  if (candidate_status == 1) {
    printf("Probable prime:\n%s\n", mpz_get_str(NULL, 10, candidate));
  } else {
    printf("Prime:\n%s\n", mpz_get_str(NULL, 10, candidate));
  }
}


x86 assembly (clang, -O0):
<FindNearbyPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <mpz_init@plt>
mov    -0xc(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    $0x2,%edx
call   1050 <mpz_mod_ui@plt>
mov    -0xc(%rbp),%edi
call   1060 <mpz_size@plt>
cmp    $0x0,%rax
jne    11b8 <FindNearbyPrime+0x48>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    $0x1,%edx
call   1030 <mpz_add_ui@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1090 <IsPrime@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1214 <FindNearbyPrime+0xa4>
mov    -0x10(%rbp),%esi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    $0x2,%edx
call   1030 <mpz_add_ui@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1090 <IsPrime@plt>
mov    %eax,-0x14(%rbp)
jmp    11cd <FindNearbyPrime+0x5d>
cmpl   $0x1,-0x14(%rbp)
jne    1245 <FindNearbyPrime+0xd5>
mov    -0x4(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xa,%esi
call   1080 <mpz_get_str@plt>
mov    %rax,%rsi
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1267 <FindNearbyPrime+0xf7>
mov    -0x4(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
mov    $0xa,%esi
call   1080 <mpz_get_str@plt>
mov    %rax,%rsi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FindNearbyPrime>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebx
call   1070 <mpz_init@plt>
mov    %ebx,%esi
mov    $0x2,%edx
call   1050 <mpz_mod_ui@plt>
call   1060 <mpz_size@plt>
mov    $0x1,%edx
mov    $0x1,%ebp
test   %rax,%rax
jne    11aa <FindNearbyPrime+0x3a>
mov    %ebx,%edi
mov    %ebx,%esi
call   1030 <mpz_add_ui@plt>
mov    %ebx,%edi
mov    %r14d,%esi
call   1090 <IsPrime@plt>
lea    0xe74(%rip),%r15
test   %eax,%eax
jne    11d9 <FindNearbyPrime+0x69>
lea    0xe3a(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
mov    $0x2,%edx
jmp    11a1 <FindNearbyPrime+0x31>
cmp    $0x1,%eax
jne    11e5 <FindNearbyPrime+0x75>
lea    0xe36(%rip),%r15
xor    %edi,%edi
mov    $0xa,%esi
mov    %ebx,%edx
call   1080 <mpz_get_str@plt>
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Trying new candidate (%i)\0A\00"
@.str.1 = [20 x i8] c"Probable prime:\0A%s\0A\00"
@.str.2 = [11 x i8] c"Prime:\0A%s\0A\00"
define void @FindNearbyPrime(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %5
%9 = call i32 @mpz_init(i32 %8)
%10 = load i32, i32* %5
%11 = load i32, i32* %3
%12 = call i32 @mpz_mod_ui(i32 %10, i32 %11, i32 2)
%13 = load i32, i32* %5
%14 = call i64 @mpz_size(i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* %3
%18 = load i32, i32* %3
%19 = call i32 @mpz_add_ui(i32 %17, i32 %18, i32 1)
br label %20
20: ; preds = %16, %2
store i32 1, i32* %6
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = call i32 @IsPrime(i32 %21, i32 %22)
store i32 %23, i32* %7
br label %24
24: ; preds = %27, %20
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %38
27: ; preds = %24
%28 = load i32, i32* %6
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
%32 = load i32, i32* %3
%33 = load i32, i32* %3
%34 = call i32 @mpz_add_ui(i32 %32, i32 %33, i32 2)
%35 = load i32, i32* %3
%36 = load i32, i32* %4
%37 = call i32 @IsPrime(i32 %35, i32 %36)
store i32 %37, i32* %7
br label %24
38: ; preds = %24
%39 = load i32, i32* %7
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = load i32, i32* %3
%43 = call i8* @mpz_get_str(i32* null, i32 10, i32 %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %43)
br label %49
45: ; preds = %38
%46 = load i32, i32* %3
%47 = call i8* @mpz_get_str(i32* null, i32 10, i32 %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %45, %41
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"Trying new candidate (%i)\0A\00"
@.str.1 = [20 x i8] c"Probable prime:\0A%s\0A\00"
@.str.2 = [11 x i8] c"Prime:\0A%s\0A\00"
define void @FindNearbyPrime(i32 %0, i32 %1) {
%3 = tail call i32 @mpz_init(i32 undef)
%4 = tail call i32 @mpz_mod_ui(i32 undef, i32 %0, i32 2)
%5 = tail call i64 @mpz_size(i32 undef)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %2, %14
%8 = phi i32 [ 2, %14 ], [ 1, %2 ]
%9 = phi i32 [ %16, %14 ], [ 1, %2 ]
%10 = tail call i32 @mpz_add_ui(i32 %0, i32 %0, i32 %8)
br label %11
11: ; preds = %7, %2
%12 = phi i32 [ 1, %2 ], [ %9, %7 ]
%13 = tail call i32 @IsPrime(i32 %0, i32 %1)
switch i32 %13, label %18 [
i32 0, label %14
i32 1, label %17
]
14: ; preds = %11
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %12)
%16 = add nuw nsw i32 %12, 1
br label %7
17: ; preds = %11
br label %18
18: ; preds = %11, %17
%19 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %17 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), %11 ]
%20 = tail call i8* @mpz_get_str(i32* null, i32 10, i32 %0)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %19, i8* %20)
ret void
}