#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 get_line(int const, char *);
char *malloc(int);
char *get_next_line(const int fd) {
  char *line;
  int i;
  int nb;
  i = 0;
  nb = 1;
  if ((line = malloc(sizeof(char) * 8096)) == NULL)
    return (NULL);
  nb = get_line(fd, line);
  if (nb == 0)
    return (NULL);
  while (line[i] != '\0')
    nb = get_line(fd, &line[++i]);
  line[++i] = '\0';
  return (line);
}


x86 assembly (clang, -O0):
<get_next_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    $0x1fa0,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    115e <get_next_line+0x3e>
movq   $0x0,-0x8(%rbp)
jmp    11dc <get_next_line+0xbc>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <get_line@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1184 <get_next_line+0x64>
movq   $0x0,-0x8(%rbp)
jmp    11dc <get_next_line+0xbc>
jmp    1189 <get_next_line+0x69>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11c0 <get_next_line+0xa0>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cltq
add    %rax,%rsi
call   1030 <get_line@plt>
mov    %eax,-0x20(%rbp)
jmp    1189 <get_next_line+0x69>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_line>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    $0x1fa0,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     117d <get_next_line+0x5d>
mov    %rax,%rbx
mov    %r14d,%edi
mov    %rax,%rsi
call   1030 <get_line@plt>
test   %eax,%eax
je     117d <get_next_line+0x5d>
cmpb   $0x0,(%rbx)
je     1181 <get_next_line+0x61>
mov    $0x1,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%rbp
lea    (%rbx,%rax,1),%rsi
mov    %r14d,%edi
call   1030 <get_line@plt>
lea    0x1(%rbp),%rax
cmpb   $0x0,(%rbx,%rbp,1)
jne    1160 <get_next_line+0x40>
mov    %eax,%eax
jmp    1186 <get_next_line+0x66>
xor    %ebx,%ebx
jmp    118a <get_next_line+0x6a>
mov    $0x1,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @get_next_line(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %5
store i32 1, i32* %6
%7 = call i8* @malloc(i32 8096)
store i8* %7, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* null, i8** %2
br label %41
10: ; preds = %1
%11 = load i32, i32* %3
%12 = load i8*, i8** %4
%13 = call i32 @get_line(i32 %11, i8* %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10
store i8* null, i8** %2
br label %41
17: ; preds = %10
br label %18
18: ; preds = %26, %17
%19 = load i8*, i8** %4
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %18
%27 = load i32, i32* %3
%28 = load i8*, i8** %4
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = call i32 @get_line(i32 %27, i8* %32)
store i32 %33, i32* %6
br label %18
34: ; preds = %18
%35 = load i8*, i8** %4
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
store i8 0, i8* %39
%40 = load i8*, i8** %4
store i8* %40, i8** %2
br label %41
41: ; preds = %34, %16, %9
%42 = load i8*, i8** %2
ret i8* %42
}

LLVM IR (-O2):
define i8* @get_next_line(i32 %0) {
%2 = tail call dereferenceable_or_null(8096) i8* @malloc(i32 8096)
%3 = icmp eq i8* %2, null
br i1 %3, label %23, label %4
4: ; preds = %1
%5 = tail call i32 @get_line(i32 %0, i8* %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %23, label %7
7: ; preds = %4
%8 = load i8, i8* %2
%9 = icmp eq i8 %8, 0
br i1 %9, label %20, label %10
10: ; preds = %7, %10
%11 = phi i64 [ %12, %10 ], [ 0, %7 ]
%12 = add nuw nsw i64 %11, 1
%13 = getelementptr inbounds i8, i8* %2, i64 %12
%14 = tail call i32 @get_line(i32 %0, i8* %13)
%15 = load i8, i8* %13
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %10
17: ; preds = %10
%18 = add nuw i64 %11, 2
%19 = and i64 %18, 4294967295
br label %20
20: ; preds = %17, %7
%21 = phi i64 [ 1, %7 ], [ %19, %17 ]
%22 = getelementptr inbounds i8, i8* %2, i64 %21
store i8 0, i8* %22
br label %23
23: ; preds = %4, %1, %20
%24 = phi i8* [ %2, %20 ], [ null, %1 ], [ null, %4 ]
ret i8* %24
}