#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 *prom_claim(void *, unsigned int);
void *prom_claim_chunk(void *virt, unsigned int size) {
  void *found, *addr;
  for (addr =
           (void *)((((unsigned)virt) + (0x100000) - 1) & (~((0x100000) - 1)));
       addr <= (void *)(0x10000000);
       addr = (void *)((unsigned)addr + 0x100000)) {
    found = prom_claim(addr, size);
    if (found != (void *)-1) {
      return found;
    }
  }
  return (void *)-1;
}


x86 assembly (clang, -O0):
<prom_claim_chunk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x100000,%eax
sub    $0x1,%eax
and    $0xfff00000,%eax
mov    %eax,%eax
mov    %rax,-0x28(%rbp)
mov    $0x10000000,%eax
cmp    %rax,-0x28(%rbp)
ja     118c <prom_claim_chunk+0x7c>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <prom_claim@plt>
mov    %rax,-0x20(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x20(%rbp)
je     1173 <prom_claim_chunk+0x63>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1197 <prom_claim_chunk+0x87>
jmp    1178 <prom_claim_chunk+0x68>
mov    -0x28(%rbp),%rax
add    $0x100000,%eax
mov    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    1136 <prom_claim_chunk+0x26>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prom_claim_chunk>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
add    $0xfffff,%ebx
and    $0xfff00000,%ebx
mov    $0xffffffffffffffff,%r14
cmp    $0x10000000,%rbx
ja     1163 <prom_claim_chunk+0x53>
mov    %esi,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <prom_claim@plt>
cmp    $0xffffffffffffffff,%rax
jne    1160 <prom_claim_chunk+0x50>
add    $0x100000,%ebx
cmp    $0x10000001,%ebx
jb     1140 <prom_claim_chunk+0x30>
jmp    1163 <prom_claim_chunk+0x53>
mov    %rax,%r14
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @prom_claim_chunk(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = ptrtoint i8* %8 to i32
%10 = add i32 %9, 1048576
%11 = sub i32 %10, 1
%12 = and i32 %11, -1048576
%13 = zext i32 %12 to i64
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %7
br label %15
15: ; preds = %27, %2
%16 = load i8*, i8** %7
%17 = icmp ule i8* %16, inttoptr (i64 268435456 to i8*)
br i1 %17, label %18, label %33
18: ; preds = %15
%19 = load i8*, i8** %7
%20 = load i32, i32* %5
%21 = call i8* @prom_claim(i8* %19, i32 %20)
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = icmp ne i8* %22, inttoptr (i64 -1 to i8*)
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = load i8*, i8** %6
store i8* %25, i8** %3
br label %34
26: ; preds = %18
br label %27
27: ; preds = %26
%28 = load i8*, i8** %7
%29 = ptrtoint i8* %28 to i32
%30 = add i32 %29, 1048576
%31 = zext i32 %30 to i64
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %7
br label %15
33: ; preds = %15
store i8* inttoptr (i64 -1 to i8*), i8** %3
br label %34
34: ; preds = %33, %24
%35 = load i8*, i8** %3
ret i8* %35
}

LLVM IR (-O2):
define i8* @prom_claim_chunk(i8* %0, i32 %1) {
%3 = ptrtoint i8* %0 to i64
%4 = add i64 %3, 1048575
%5 = and i64 %4, 4293918720
%6 = inttoptr i64 %5 to i8*
%7 = icmp ugt i8* %6, inttoptr (i64 268435456 to i8*)
br i1 %7, label %18, label %8
8: ; preds = %2, %13
%9 = phi i8* [ %16, %13 ], [ %6, %2 ]
%10 = phi i64 [ %15, %13 ], [ %5, %2 ]
%11 = tail call i8* @prom_claim(i8* %9, i32 %1)
%12 = icmp eq i8* %11, inttoptr (i64 -1 to i8*)
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = add nuw nsw i64 %10, 1048576
%15 = and i64 %14, 4294967295
%16 = inttoptr i64 %15 to i8*
%17 = icmp ugt i8* %16, inttoptr (i64 268435456 to i8*)
br i1 %17, label %18, label %8
18: ; preds = %8, %13, %2
%19 = phi i8* [ inttoptr (i64 -1 to i8*), %2 ], [ inttoptr (i64 -1 to i8*), %13 ], [ %11, %8 ]
ret i8* %19
}