#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 */
int quickE(unsigned long, unsigned long, unsigned long);
unsigned long rand();
unsigned long int chooseGenerator(unsigned long int p) {
  unsigned long int g;
  while (g = rand() % p - 1) {
    if (quickE(g, (p - 1) / 2, p) != 1 && quickE(g, (p - 1) / 4, p) != 1 &&
        quickE(g, (p - 1) * 3 / 4, p) != 1) {
      return g;
    }
  }
}


x86 assembly (clang, -O0):
<chooseGenerator>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
sub    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
cmp    $0x0,%rdx
je     11c9 <chooseGenerator+0xa9>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
sub    $0x1,%rsi
shr    $0x1,%rsi
mov    -0x10(%rbp),%rdx
call   1040 <quickE@plt>
cmp    $0x1,%eax
je     11c4 <chooseGenerator+0xa4>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
sub    $0x1,%rsi
shr    $0x2,%rsi
mov    -0x10(%rbp),%rdx
call   1040 <quickE@plt>
cmp    $0x1,%eax
je     11c4 <chooseGenerator+0xa4>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
imul   $0x3,%rax,%rsi
shr    $0x2,%rsi
mov    -0x10(%rbp),%rdx
call   1040 <quickE@plt>
cmp    $0x1,%eax
je     11c4 <chooseGenerator+0xa4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c9 <chooseGenerator+0xa9>
jmp    112c <chooseGenerator+0xc>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chooseGenerator>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r12
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rcx
or     %r12,%rcx
shr    $0x20,%rcx
je     1152 <chooseGenerator+0x32>
xor    %edx,%edx
div    %r12
mov    %rdx,%rbx
add    $0xffffffffffffffff,%rbx
jne    1163 <chooseGenerator+0x43>
jmp    11f8 <chooseGenerator+0xd8>
xor    %edx,%edx
div    %r12d
mov    %edx,%ebx
add    $0xffffffffffffffff,%rbx
je     11f8 <chooseGenerator+0xd8>
lea    -0x1(%r12),%r14
lea    (%r14,%r14,2),%r15
shr    $0x2,%r15
mov    %r14,%r13
shr    %r13
shr    $0x2,%r14
jmp    11bd <chooseGenerator+0x9d>
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rcx
or     %r12,%rcx
shr    $0x20,%rcx
je     11b0 <chooseGenerator+0x90>
xor    %edx,%edx
div    %r12
mov    %rdx,%rbx
add    $0xffffffffffffffff,%rbx
jne    11bd <chooseGenerator+0x9d>
jmp    11f8 <chooseGenerator+0xd8>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %edx,%edx
div    %r12d
mov    %edx,%ebx
add    $0xffffffffffffffff,%rbx
je     11f8 <chooseGenerator+0xd8>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1040 <quickE@plt>
cmp    $0x1,%eax
je     1180 <chooseGenerator+0x60>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1040 <quickE@plt>
cmp    $0x1,%eax
je     1180 <chooseGenerator+0x60>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <quickE@plt>
cmp    $0x1,%eax
je     1180 <chooseGenerator+0x60>
jmp    11fa <chooseGenerator+0xda>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @chooseGenerator(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
br label %5
5: ; preds = %38, %1
%6 = call i64 (...) @rand()
%7 = load i64, i64* %3
%8 = urem i64 %6, %7
%9 = sub i64 %8, 1
store i64 %9, i64* %4
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %39
11: ; preds = %5
%12 = load i64, i64* %4
%13 = load i64, i64* %3
%14 = sub i64 %13, 1
%15 = udiv i64 %14, 2
%16 = load i64, i64* %3
%17 = call i32 @quickE(i64 %12, i64 %15, i64 %16)
%18 = icmp ne i32 %17, 1
br i1 %18, label %19, label %38
19: ; preds = %11
%20 = load i64, i64* %4
%21 = load i64, i64* %3
%22 = sub i64 %21, 1
%23 = udiv i64 %22, 4
%24 = load i64, i64* %3
%25 = call i32 @quickE(i64 %20, i64 %23, i64 %24)
%26 = icmp ne i32 %25, 1
br i1 %26, label %27, label %38
27: ; preds = %19
%28 = load i64, i64* %4
%29 = load i64, i64* %3
%30 = sub i64 %29, 1
%31 = mul i64 %30, 3
%32 = udiv i64 %31, 4
%33 = load i64, i64* %3
%34 = call i32 @quickE(i64 %28, i64 %32, i64 %33)
%35 = icmp ne i32 %34, 1
br i1 %35, label %36, label %38
36: ; preds = %27
%37 = load i64, i64* %4
store i64 %37, i64* %2
br label %39
38: ; preds = %27, %19, %11
br label %5
39: ; preds = %36, %5
%40 = load i64, i64* %2
ret i64 %40
}

LLVM IR (-O2):
define i64 @chooseGenerator(i64 %0) {
%2 = add i64 %0, -1
%3 = mul i64 %2, 3
%4 = lshr i64 %3, 2
%5 = tail call i64 (...) @rand()
%6 = urem i64 %5, %0
%7 = add i64 %6, -1
%8 = icmp eq i64 %7, 0
br i1 %8, label %27, label %9
9: ; preds = %1
%10 = lshr i64 %2, 1
%11 = lshr i64 %2, 2
br label %12
12: ; preds = %9, %22
%13 = phi i64 [ %7, %9 ], [ %25, %22 ]
%14 = tail call i32 @quickE(i64 %13, i64 %10, i64 %0)
%15 = icmp eq i32 %14, 1
br i1 %15, label %22, label %16
16: ; preds = %12
%17 = tail call i32 @quickE(i64 %13, i64 %11, i64 %0)
%18 = icmp eq i32 %17, 1
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = tail call i32 @quickE(i64 %13, i64 %4, i64 %0)
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %27
22: ; preds = %19, %16, %12
%23 = tail call i64 (...) @rand()
%24 = urem i64 %23, %0
%25 = add i64 %24, -1
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %12
27: ; preds = %19, %22, %1
%28 = phi i64 [ 0, %1 ], [ 0, %22 ], [ %13, %19 ]
ret i64 %28
}