#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void print_procmap(void) {
  int fd, rd;
  char buf[1024];
  if ((fd = open("/proc/self/maps", O_RDONLY)) == -1)
    err(1, "open()");
  while ((rd = read(fd, buf, sizeof(buf))) > 0)
    write(1, buf, rd);
  if (rd == -1)
    err(1, "read()");
  close(fd);
}


x86 assembly (clang, -O0):
<print_procmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
jne    118d <print_procmap+0x3d>
mov    $0x1,%edi
lea    0xe88(%rip),%rsi
call   1060 <err@plt>
jmp    1192 <print_procmap+0x42>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11cb <print_procmap+0x7b>
lea    -0x410(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    1192 <print_procmap+0x42>
cmpl   $0xffffffff,-0x8(%rbp)
jne    11e6 <print_procmap+0x96>
mov    $0x1,%edi
lea    0xe36(%rip),%rsi
call   1060 <err@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_procmap>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
lea    0xe97(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1186 <print_procmap+0x36>
lea    0xe94(%rip),%rsi
mov    $0x1,%edi
call   1060 <err@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x400,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11c2 <print_procmap+0x72>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
test   %eax,%eax
jg     11a0 <print_procmap+0x50>
cmp    $0xffffffff,%eax
jne    11d8 <print_procmap+0x88>
lea    0xe49(%rip),%rsi
mov    $0x1,%edi
call   1060 <err@plt>
mov    %ebp,%edi
add    $0x408,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <close@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"/proc/self/maps\00"
@O_RDONLY = global i32 0
@.str.1 = [7 x i8] c"open()\00"
@.str.2 = [7 x i8] c"read()\00"
define void @print_procmap() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %1
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
br label %10
10: ; preds = %15, %9
%11 = load i32, i32* %1
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 1024)
store i32 %13, i32* %2
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%17 = load i32, i32* %2
%18 = call i32 @write(i32 1, i8* %16, i32 %17)
br label %10
19: ; preds = %10
%20 = load i32, i32* %2
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
%25 = load i32, i32* %1
%26 = call i32 @close(i32 %25)
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"/proc/self/maps\00"
@O_RDONLY = global i32 0
@.str.1 = [7 x i8] c"open()\00"
@.str.2 = [7 x i8] c"read()\00"
define void @print_procmap() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i32 @read(i32 %4, i8* %2, i32 1024)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %8, %11
%12 = phi i32 [ %14, %11 ], [ %9, %8 ]
%13 = call i32 @write(i32 1, i8* %2, i32 %12)
%14 = call i32 @read(i32 %4, i8* %2, i32 1024)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %11, label %16
16: ; preds = %11, %8
%17 = phi i32 [ %9, %8 ], [ %14, %11 ]
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
%22 = tail call i32 @close(i32 %4)
ret void
}