#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__ IsConnectionArrFull(int);
int rand();
int RandomRoomWithinRange(int lowerBound, int upperBound) {
  int roomIndex;
  do {
    roomIndex = rand() % upperBound + lowerBound;
  } while (IsConnectionArrFull(roomIndex) == 0 && roomIndex <= upperBound &&
           roomIndex >= lowerBound);
  return roomIndex;
}


x86 assembly (clang, -O0):
<RandomRoomWithinRange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
cltd
idivl  -0x8(%rbp)
add    -0x4(%rbp),%edx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <IsConnectionArrFull@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0xd(%rbp)
jne    1176 <RandomRoomWithinRange+0x56>
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
cmp    -0x8(%rbp),%ecx
mov    %al,-0xd(%rbp)
jg     1176 <RandomRoomWithinRange+0x56>
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
setge  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    112e <RandomRoomWithinRange+0xe>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RandomRoomWithinRange>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%r14d
nopl   (%rax)
xor    %eax,%eax
call   1040 <rand@plt>
cltd
idiv   %r15d
mov    %edx,%ebx
lea    (%rbx,%r14,1),%ebp
mov    %ebp,%edi
call   1030 <IsConnectionArrFull@plt>
test   %rax,%rax
jne    1156 <RandomRoomWithinRange+0x36>
cmp    %r15d,%ebp
jg     1156 <RandomRoomWithinRange+0x36>
test   %ebx,%ebx
jns    1130 <RandomRoomWithinRange+0x10>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @RandomRoomWithinRange(i32 %0, i32 %1) {
br label %3
3: ; preds = %3, %2
%4 = tail call i32 (...) @rand()
%5 = srem i32 %4, %1
%6 = add nsw i32 %5, %0
%7 = tail call i64 @IsConnectionArrFull(i32 %6)
%8 = icmp ne i64 %7, 0
%9 = icmp sgt i32 %6, %1
%10 = or i1 %8, %9
%11 = icmp slt i32 %5, 0
%12 = select i1 %10, i1 true, i1 %11
br i1 %12, label %13, label %3
13: ; preds = %3
ret i32 %6
}