#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 allocate_map();
int allocate_pid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ release_pid(int);
int main() {
  if (allocate_map() == -1) {
    printf("Map allocation failed\n");
    return -1;
  }
  for (int i = 1; i <= 300; ++i)
    printf("Allocated %d\n", allocate_pid());
  release_pid(500);
  printf("Allocated %d\n", allocate_pid());
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <allocate_map@plt>
cmp    $0xffffffff,%eax
jne    1179 <main+0x39>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11da <main+0x9a>
movl   $0x1,-0x8(%rbp)
cmpl   $0x12c,-0x8(%rbp)
jg     11b2 <main+0x72>
mov    $0x0,%al
call   1050 <allocate_pid@plt>
mov    %eax,%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1180 <main+0x40>
mov    $0x1f4,%edi
call   1060 <release_pid@plt>
mov    $0x0,%al
call   1050 <allocate_pid@plt>
mov    %eax,%esi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <allocate_map@plt>
cmp    $0xffffffff,%eax
je     11ad <main+0x5d>
mov    $0x12c,%ebp
lea    0xe95(%rip),%rbx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <allocate_pid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xffffffff,%ebp
jne    1170 <main+0x20>
mov    $0x1f4,%edi
call   1070 <release_pid@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <allocate_pid@plt>
lea    0xe5e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11be <main+0x6e>
lea    0xe5a(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Map allocation failed\0A\00"
@.str.1 = [14 x i8] c"Allocated %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @allocate_map()
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %21
7: ; preds = %0
store i32 1, i32* %2
br label %8
8: ; preds = %14, %7
%9 = load i32, i32* %2
%10 = icmp sle i32 %9, 300
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = call i32 (...) @allocate_pid()
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %11
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
store i32 %16, i32* %2
br label %8
17: ; preds = %8
%18 = call i32 @release_pid(i32 500)
%19 = call i32 (...) @allocate_pid()
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 0, i32* %1
br label %21
21: ; preds = %17, %5
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str.1 = [14 x i8] c"Allocated %d\0A\00"
@str = [22 x i8] c"Map allocation failed\00"
define i32 @main() {
%1 = tail call i32 (...) @allocate_map()
%2 = icmp eq i32 %1, -1
br i1 %2, label %3, label %9
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %15
5: ; preds = %9
%6 = tail call i32 @release_pid(i32 500)
%7 = tail call i32 (...) @allocate_pid()
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %7)
br label %15
9: ; preds = %0, %9
%10 = phi i32 [ %13, %9 ], [ 1, %0 ]
%11 = tail call i32 (...) @allocate_pid()
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = add nuw nsw i32 %10, 1
%14 = icmp eq i32 %13, 301
br i1 %14, label %5, label %9
15: ; preds = %5, %3
%16 = phi i32 [ -1, %3 ], [ 0, %5 ]
ret i32 %16
}