#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 isValueInArray(int, int *, int);
int rand();
int prandOne(int max, int *arr, int size) {
  bool isthere;
  int newnum = rand() % max;
  if (newnum == 0) {
    newnum = prandOne(max, arr, size);
  }
  isthere = isValueInArray(newnum, arr, size);
  if (isthere) {
    newnum = prandOne(max, arr, size);
  }
  return newnum;
}


x86 assembly (clang, -O0):
<prandOne>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cltd
idivl  -0x4(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    116c <prandOne+0x3c>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <prandOne@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <isValueInArray@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     119a <prandOne+0x6a>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <prandOne@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prandOne>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,%ebp
jmp    1161 <prandOne+0x31>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <isValueInArray@plt>
test   %eax,%eax
je     1182 <prandOne+0x52>
xor    %eax,%eax
call   1050 <rand@plt>
cltd
idiv   %ebp
mov    %edx,%ebx
test   %edx,%edx
jne    1150 <prandOne+0x20>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <prandOne@plt>
mov    %eax,%ebx
jmp    1150 <prandOne+0x20>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @prandOne(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%9 = call i32 (...) @rand()
%10 = load i32, i32* %4
%11 = srem i32 %9, %10
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %3
%15 = load i32, i32* %4
%16 = load i32*, i32** %5
%17 = load i32, i32* %6
%18 = call i32 @prandOne(i32 %15, i32* %16, i32 %17)
store i32 %18, i32* %8
br label %19
19: ; preds = %14, %3
%20 = load i32, i32* %8
%21 = load i32*, i32** %5
%22 = load i32, i32* %6
%23 = call i32 @isValueInArray(i32 %20, i32* %21, i32 %22)
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %19
%27 = load i32, i32* %4
%28 = load i32*, i32** %5
%29 = load i32, i32* %6
%30 = call i32 @prandOne(i32 %27, i32* %28, i32 %29)
store i32 %30, i32* %8
br label %31
31: ; preds = %26, %19
%32 = load i32, i32* %8
ret i32 %32
}

LLVM IR (-O2):
define i32 @prandOne(i32 %0, i32* %1, i32 %2) {
br label %4
4: ; preds = %10, %3
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, %0
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @prandOne(i32 %0, i32* %1, i32 %2)
br label %10
10: ; preds = %8, %4
%11 = phi i32 [ %9, %8 ], [ %6, %4 ]
%12 = tail call i32 @isValueInArray(i32 %11, i32* %1, i32 %2)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %4
14: ; preds = %10
ret i32 %11
}