#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 invalid_mappings();
int map_unmap();
int modify_flags();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int r;
  if ((r = map_unmap())) {
    printf("map_unmap returned %d\n", r);
    return 1;
  }
  if ((r = modify_flags())) {
    printf("modify_flags returned %d\n", r);
    return 2;
  }
  if ((r = invalid_mappings())) {
    printf("invalid_mappings returned %d\n", r);
    return 3;
  }
  printf("nkmtest_all: all tests passed\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <map_unmap@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     117f <main+0x3f>
mov    -0x8(%rbp),%esi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f4 <main+0xb4>
mov    $0x0,%al
call   1060 <modify_flags@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     11af <main+0x6f>
mov    -0x8(%rbp),%esi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    11f4 <main+0xb4>
mov    $0x0,%al
call   1050 <invalid_mappings@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     11df <main+0x9f>
mov    -0x8(%rbp),%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    11f4 <main+0xb4>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1050 <map_unmap@plt>
test   %eax,%eax
je     1173 <main+0x23>
lea    0xe9d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebx
jmp    11c5 <main+0x75>
xor    %eax,%eax
call   1070 <modify_flags@plt>
test   %eax,%eax
je     1195 <main+0x45>
lea    0xe92(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2,%ebx
jmp    11c5 <main+0x75>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <invalid_mappings@plt>
test   %eax,%eax
je     11b9 <main+0x69>
lea    0xe88(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x3,%ebx
jmp    11c5 <main+0x75>
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"map_unmap returned %d\0A\00"
@.str.1 = [26 x i8] c"modify_flags returned %d\0A\00"
@.str.2 = [30 x i8] c"invalid_mappings returned %d\0A\00"
@.str.3 = [31 x i8] c"nkmtest_all: all tests passed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @map_unmap()
store i32 %3, i32* %2
%4 = icmp ne i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = load i32, i32* %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 1, i32* %1
br label %22
8: ; preds = %0
%9 = call i32 (...) @modify_flags()
store i32 %9, i32* %2
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %12)
store i32 2, i32* %1
br label %22
14: ; preds = %8
%15 = call i32 (...) @invalid_mappings()
store i32 %15, i32* %2
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %18)
store i32 3, i32* %1
br label %22
20: ; preds = %14
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %22
22: ; preds = %20, %17, %11, %5
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [23 x i8] c"map_unmap returned %d\0A\00"
@.str.1 = [26 x i8] c"modify_flags returned %d\0A\00"
@.str.2 = [30 x i8] c"invalid_mappings returned %d\0A\00"
@str = [30 x i8] c"nkmtest_all: all tests passed\00"
define i32 @main() {
%1 = tail call i32 (...) @map_unmap()
%2 = icmp eq i32 %1, 0
br i1 %2, label %5, label %3
3: ; preds = %0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %17
5: ; preds = %0
%6 = tail call i32 (...) @modify_flags()
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %6)
br label %17
10: ; preds = %5
%11 = tail call i32 (...) @invalid_mappings()
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %11)
br label %17
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %15, %13, %8, %3
%18 = phi i32 [ 1, %3 ], [ 2, %8 ], [ 3, %13 ], [ 0, %15 ]
ret i32 %18
}