#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 */
void *frame_to_address(unsigned int);
void *get_next_available_frame() {
  unsigned int frame = 0;
  unsigned char *frames_ptr = (void *)0xC1400000;
  for (int i = 0; i < 0x100000 && !frame; i++) {
    if (!frames_ptr[i]) {
      frame = i;
    }
  }
  return frame_to_address(frame);
}


x86 assembly (clang, -O0):
<get_next_available_frame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xc1400000,%eax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x100000,-0x14(%rbp)
mov    %al,-0x15(%rbp)
jge    114d <get_next_available_frame+0x3d>
cmpl   $0x0,-0x4(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    115d <get_next_available_frame+0x4d>
jmp    1188 <get_next_available_frame+0x78>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    1175 <get_next_available_frame+0x65>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117a <get_next_available_frame+0x6a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112f <get_next_available_frame+0x1f>
mov    -0x4(%rbp),%edi
call   1030 <frame_to_address@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_available_frame>:
xor    %eax,%eax
mov    $0xc1400000,%ecx
nopw   0x0(%rax,%rax,1)
cmpb   $0x0,(%rax,%rcx,1)
mov    %eax,%edi
je     112a <get_next_available_frame+0x1a>
xor    %edi,%edi
cmp    $0xffffe,%rax
ja     113a <get_next_available_frame+0x2a>
add    $0x1,%rax
test   %edi,%edi
je     1120 <get_next_available_frame+0x10>
jmp    1030 <frame_to_address@plt>

LLVM IR (-O0):
define i8* @get_next_available_frame() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
store i32 0, i32* %1
store i8* inttoptr (i64 3242196992 to i8*), i8** %2
store i32 0, i32* %3
br label %4
4: ; preds = %23, %0
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 1048576
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = load i32, i32* %1
%9 = icmp ne i32 %8, 0
%10 = xor i1 %9, true
br label %11
11: ; preds = %7, %4
%12 = phi i1 [ false, %4 ], [ %10, %7 ]
br i1 %12, label %13, label %26
13: ; preds = %11
%14 = load i8*, i8** %2
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %13
%21 = load i32, i32* %3
store i32 %21, i32* %1
br label %22
22: ; preds = %20, %13
br label %23
23: ; preds = %22
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %4
26: ; preds = %11
%27 = load i32, i32* %1
%28 = call i8* @frame_to_address(i32 %27)
ret i8* %28
}

LLVM IR (-O2):
define i8* @get_next_available_frame() {
br label %3
1: ; preds = %3
%2 = tail call i8* @frame_to_address(i32 %9)
ret i8* %2
3: ; preds = %0, %3
%4 = phi i64 [ 0, %0 ], [ %10, %3 ]
%5 = getelementptr inbounds i8, i8* inttoptr (i64 3242196992 to i8*), i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
%8 = trunc i64 %4 to i32
%9 = select i1 %7, i32 %8, i32 0
%10 = add nuw nsw i64 %4, 1
%11 = icmp ult i64 %4, 1048575
%12 = icmp eq i32 %9, 0
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %3, label %1
}