#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
char *readline(int);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
main() {
  int fd = open("/etc/passwd", O_RDONLY);
  char *p;
  if (fd < 0)
    exit(1);
  while (p = readline(fd)) {
    write(1, ">>", 2);
    write(1, p, strlen(p));
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    118b <main+0x3b>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1190 <main+0x40>
mov    -0x8(%rbp),%edi
call   1050 <readline@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11e2 <main+0x92>
mov    $0x1,%edi
lea    0xe5a(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    1190 <main+0x40>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
lea    0xe9c(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11cf <main+0x7f>
mov    %eax,%ebp
mov    %eax,%edi
call   1050 <readline@plt>
test   %rax,%rax
je     11c8 <main+0x78>
mov    %rax,%rbx
lea    0xe87(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1050 <readline@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1190 <main+0x40>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/etc/passwd\00"
@O_RDONLY = global i32 0
@.str.1 = [3 x i8] c">>\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
br label %11
11: ; preds = %15, %10
%12 = load i32, i32* %2
%13 = call i8* @readline(i32 %12)
store i8* %13, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%17 = load i8*, i8** %3
%18 = load i8*, i8** %3
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @write(i32 1, i8* %17, i32 %19)
br label %11
21: ; preds = %11
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str = [12 x i8] c"/etc/passwd\00"
@O_RDONLY = global i32 0
@.str.1 = [3 x i8] c">>\00"
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %0
%5 = tail call i8* @readline(i32 %2)
%6 = icmp eq i8* %5, null
br i1 %6, label %16, label %9
7: ; preds = %0
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %4, %9
%10 = phi i8* [ %14, %9 ], [ %5, %4 ]
%11 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%12 = tail call i32 @strlen(i8* %10)
%13 = tail call i32 @write(i32 1, i8* %10, i32 %12)
%14 = tail call i8* @readline(i32 %2)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %9
16: ; preds = %9, %4
ret i32 0
}