#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int ac, char **av) {
  FILE *fH = fopen("/proc/self/maps", "r");
  char line[128];
  while (fgets(line, sizeof line, fH) != NULL)
    fputs(line, stdout);
  fclose(fH);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea0(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11a9 <main+0x69>
lea    -0xa0(%rbp),%rdi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
jmp    1170 <main+0x30>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
lea    0xead(%rip),%rdi
lea    0xeb6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11b0 <main+0x70>
mov    0x2e62(%rip),%r15
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15),%esi
mov    %rbx,%rdi
call   1040 <fputs@plt>
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1190 <main+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/proc/self/maps\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %6
br label %9
9: ; preds = %14, %2
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%11 = load i32*, i32** %6
%12 = call i32* @fgets(i8* %10, i32 128, i32* %11)
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%16 = load i32, i32* @stdout
%17 = call i32 @fputs(i8* %15, i32 %16)
br label %9
18: ; preds = %9
%19 = load i32*, i32** %6
%20 = call i32 @fclose(i32* %19)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"/proc/self/maps\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = call i32* @fgets(i8* %5, i32 128, i32* %4)
%7 = icmp eq i32* %6, null
br i1 %7, label %13, label %8
8: ; preds = %2, %8
%9 = load i32, i32* @stdout
%10 = call i32 @fputs(i8* %5, i32 %9)
%11 = call i32* @fgets(i8* %5, i32 128, i32* %4)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %8
13: ; preds = %8, %2
%14 = call i32 @fclose(i32* %4)
ret i32 0
}