#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *get_next_line(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main(int __attribute__((unused)) ac, char __attribute__((unused)) * *av) {
  char *s;
  int fd;
  s = NULL;
  if ((fd = open("./gcc", O_RDONLY)) == -1) {
    fprintf(stderr, "Open failed");
    return (EXIT_FAILURE);
  }
  while ((s = get_next_line(fd))) {
    write(STDOUT_FILENO, s, strlen(s));
    write(STDOUT_FILENO, "\n", sizeof(char) * 1);
    free(s);
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
lea    0xe72(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    11c5 <main+0x65>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    123f <main+0xdf>
jmp    11ca <main+0x6a>
mov    -0x1c(%rbp),%edi
call   1080 <get_next_line@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1233 <main+0xd3>
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xdf7(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    11ca <main+0x6a>
mov    0x2d86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11f3 <main+0x93>
mov    %eax,%r15d
mov    %eax,%edi
call   1080 <get_next_line@plt>
mov    0x2e2a(%rip),%r12
test   %rax,%rax
je     120f <main+0xaf>
mov    %rax,%rbx
mov    0x2e4b(%rip),%r13
lea    0xe66(%rip),%r14
nopl   0x0(%rax)
mov    0x0(%r13),%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    0x0(%r13),%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15d,%edi
call   1080 <get_next_line@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11b0 <main+0x50>
jmp    120f <main+0xaf>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2db9(%rip),%r12
mov    (%r12),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"./gcc\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [12 x i8] c"Open failed\00"
@EXIT_FAILURE = global i32 0
@STDOUT_FILENO = global i32 0
@.str.2 = [2 x i8] c"\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %7
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %3
br label %32
15: ; preds = %2
br label %16
16: ; preds = %20, %15
%17 = load i32, i32* %7
%18 = call i8* @get_next_line(i32 %17)
store i8* %18, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = load i32, i32* @STDOUT_FILENO
%22 = load i8*, i8** %6
%23 = load i8*, i8** %6
%24 = call i32 @strlen(i8* %23)
%25 = call i32 @write(i32 %21, i8* %22, i32 %24)
%26 = load i32, i32* @STDOUT_FILENO
%27 = call i32 @write(i32 %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%28 = load i8*, i8** %6
%29 = call i32 @free(i8* %28)
br label %16
30: ; preds = %16
%31 = load i32, i32* @EXIT_SUCCESS
store i32 %31, i32* %3
br label %32
32: ; preds = %30, %11
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [6 x i8] c"./gcc\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [12 x i8] c"Open failed\00"
@EXIT_FAILURE = global i32 0
@STDOUT_FILENO = global i32 0
@.str.2 = [2 x i8] c"\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i8* @get_next_line(i32 %4)
%8 = icmp eq i8* %7, null
br i1 %8, label %22, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %22
12: ; preds = %6, %12
%13 = phi i8* [ %20, %12 ], [ %7, %6 ]
%14 = load i32, i32* @STDOUT_FILENO
%15 = tail call i32 @strlen(i8* %13)
%16 = tail call i32 @write(i32 %14, i8* %13, i32 %15)
%17 = load i32, i32* @STDOUT_FILENO
%18 = tail call i32 @write(i32 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%19 = tail call i32 @free(i8* %13)
%20 = tail call i8* @get_next_line(i32 %4)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %12
22: ; preds = %12, %6, %9
%23 = phi i32* [ @EXIT_FAILURE, %9 ], [ @EXIT_SUCCESS, %6 ], [ @EXIT_SUCCESS, %12 ]
%24 = load i32, i32* %23
ret i32 %24
}