#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*/ ft_putchar(char);
int /*<<< orphan*/ ft_putendl(int /*<<< orphan*/);
int /*<<< orphan*/ ft_putnbr(int);
int /*<<< orphan*/ ft_putstr(char *);
int get_next_line(int, char **);
int open(char *, int /*<<< orphan*/);
int main(void) {
  char **line;
  int fd;
  int nb_read;
  int tmp;
  fd = open("test", O_RDONLY);
  ft_putstr("fd = ");
  ft_putnbr(fd);
  ft_putchar('\n');
  tmp = get_next_line(fd, line);
  while (*line) {
    ft_putendl(*line++);
  }
  close(fd);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
lea    0xe67(%rip),%rdi
call   1080 <ft_putstr@plt>
mov    -0x14(%rbp),%edi
call   1060 <ft_putnbr@plt>
mov    $0xa,%edi
call   1050 <ft_putchar@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1090 <get_next_line@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     11f0 <main+0x80>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rax
mov    %eax,%edi
call   1030 <ft_putendl@plt>
jmp    11c4 <main+0x54>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
lea    0xe96(%rip),%rdi
call   1060 <ft_putstr@plt>
mov    %ebx,%edi
call   1040 <ft_putnbr@plt>
mov    $0xa,%edi
call   1030 <ft_putchar@plt>
mov    %ebx,%edi
call   1070 <get_next_line@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"test\00"
@O_RDONLY = global i32 0
@.str.1 = [6 x i8] c"fd = \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %3
%8 = call i32 @ft_putstr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* %3
%10 = call i32 @ft_putnbr(i32 %9)
%11 = call i32 @ft_putchar(i8 signext 10)
%12 = load i32, i32* %3
%13 = load i8**, i8*** %2
%14 = call i32 @get_next_line(i32 %12, i8** %13)
store i32 %14, i32* %5
br label %15
15: ; preds = %19, %0
%16 = load i8**, i8*** %2
%17 = load i8*, i8** %16
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = load i8**, i8*** %2
%21 = getelementptr inbounds i8*, i8** %20, i32 1
store i8** %21, i8*** %2
%22 = load i8*, i8** %20
%23 = ptrtoint i8* %22 to i32
%24 = call i32 @ft_putendl(i32 %23)
br label %15
25: ; preds = %15
%26 = load i32, i32* %3
%27 = call i32 @close(i32 %26)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"test\00"
@O_RDONLY = global i32 0
@.str.1 = [6 x i8] c"fd = \00"
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @ft_putstr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 @ft_putnbr(i32 %2)
%5 = tail call i32 @ft_putchar(i8 signext 10)
%6 = tail call i32 @get_next_line(i32 %2, i8** undef)
unreachable
}