#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*/ close(int);
int /*<<< orphan*/ free(char *);
scalar_t__ get_next_line(int, char **);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  char *line;
  int fd;
  fd = open("Makefile", O_RDONLY);
  if (fd == -1)
    printf("fail\n");
  while (get_next_line(fd, &line) > 0) {
    printf("line : %s\n", line);
    free(line);
  }
  close(fd);
  return (0);
}


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,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    118f <main+0x3f>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1194 <main+0x44>
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1070 <get_next_line@plt>
cmp    $0x0,%rax
jle    11ca <main+0x7a>
mov    -0x10(%rbp),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    1194 <main+0x44>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1191 <main+0x31>
lea    0xe88(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1080 <get_next_line@plt>
test   %rax,%rax
jle    11d8 <main+0x78>
lea    0xe60(%rip),%r14
lea    0x8(%rsp),%r15
xchg   %ax,%ax
mov    0x8(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%edi
mov    %r15,%rsi
call   1080 <get_next_line@plt>
test   %rax,%rax
jg     11b0 <main+0x50>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"Makefile\00"
@O_RDONLY = global i32 0
@.str.1 = [6 x i8] c"fail\0A\00"
@.str.2 = [11 x i8] c"line : %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
br label %11
11: ; preds = %15, %10
%12 = load i32, i32* %3
%13 = call i64 @get_next_line(i32 %12, i8** %2)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i8*, i8** %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %2
%19 = call i32 @free(i8* %18)
br label %11
20: ; preds = %11
%21 = load i32, i32* %3
%22 = call i32 @close(i32 %21)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"Makefile\00"
@O_RDONLY = global i32 0
@.str.2 = [11 x i8] c"line : %s\0A\00"
@str = [5 x i8] c"fail\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 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 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i64 @get_next_line(i32 %4, i8** %1)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %8, %11
%12 = load i8*, i8** %1
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %1
%15 = call i32 @free(i8* %14)
%16 = call i64 @get_next_line(i32 %4, i8** %1)
%17 = icmp sgt i64 %16, 0
br i1 %17, label %11, label %18
18: ; preds = %11, %8
%19 = call i32 @close(i32 %4)
ret i32 0
}