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

/* Variables and functions */
scalar_t__ probablePrime(int, int);
int rand();
int randPrime(int n) {
  int prime = rand() % n;
  n += n % 2;
  prime += 1 - prime % 2;
  while (1) {
    if (probablePrime(prime, 5))
      return prime;
    prime = (prime + 2) % n;
  }
}


x86 assembly (clang, -O0):
<randPrime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
cltd
idivl  -0x4(%rbp)
mov    %edx,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    -0x4(%rbp),%edx
mov    %edx,-0x4(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    $0x1,%eax
sub    %edx,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   1030 <probablePrime@plt>
cmp    $0x0,%rax
je     1182 <randPrime+0x62>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret
mov    -0x8(%rbp),%eax
add    $0x2,%eax
cltd
idivl  -0x4(%rbp)
mov    %edx,-0x8(%rbp)
jmp    1162 <randPrime+0x42>

x86 assembly (clang, -O2):
<randPrime>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
xor    %eax,%eax
call   1040 <rand@plt>
cltd
idiv   %r14d
mov    %edx,%ebx
shr    $0x1f,%ebx
add    %edx,%ebx
or     $0x1,%ebx
mov    %ebx,%edi
mov    $0x5,%esi
call   1030 <probablePrime@plt>
test   %rax,%rax
jne    118b <randPrime+0x6b>
mov    %r14d,%eax
shr    $0x1f,%eax
add    %r14d,%eax
and    $0xfffffffe,%eax
mov    %r14d,%ebp
sub    %eax,%ebp
add    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x2,%ebx
mov    %ebx,%eax
cltd
idiv   %ebp
mov    %edx,%ebx
mov    %edx,%edi
mov    $0x5,%esi
call   1030 <probablePrime@plt>
test   %rax,%rax
je     1170 <randPrime+0x50>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @randPrime(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 (...) @rand()
%5 = load i32, i32* %2
%6 = srem i32 %4, %5
store i32 %6, i32* %3
%7 = load i32, i32* %2
%8 = srem i32 %7, 2
%9 = load i32, i32* %2
%10 = add nsw i32 %9, %8
store i32 %10, i32* %2
%11 = load i32, i32* %3
%12 = srem i32 %11, 2
%13 = sub nsw i32 1, %12
%14 = load i32, i32* %3
%15 = add nsw i32 %14, %13
store i32 %15, i32* %3
br label %16
16: ; preds = %1, %22
%17 = load i32, i32* %3
%18 = call i64 @probablePrime(i32 %17, i32 5)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i32, i32* %3
ret i32 %21
22: ; preds = %16
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 2
%25 = load i32, i32* %2
%26 = srem i32 %24, %25
store i32 %26, i32* %3
br label %16
}

LLVM IR (-O2):
define i32 @randPrime(i32 %0) {
%2 = tail call i32 (...) @rand()
%3 = srem i32 %2, %0
%4 = srem i32 %0, 2
%5 = add nsw i32 %4, %0
%6 = srem i32 %3, 2
%7 = add i32 %3, 1
%8 = sub i32 %7, %6
%9 = tail call i64 @probablePrime(i32 %8, i32 5)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %13, %1
%12 = phi i32 [ %8, %1 ], [ %16, %13 ]
ret i32 %12
13: ; preds = %1, %13
%14 = phi i32 [ %16, %13 ], [ %8, %1 ]
%15 = add nsw i32 %14, 2
%16 = srem i32 %15, %5
%17 = tail call i64 @probablePrime(i32 %16, i32 5)
%18 = icmp eq i64 %17, 0
br i1 %18, label %13, label %11
}