#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 */
char *enlarge_buffer(char *, int, int);
char in_char(int);
char *malloc(int);
char *in_line(int fd) {
  char *rtn;
  char cur;
  int it;
  it = 0;
  cur = in_char(fd);
  if ((rtn = malloc(1024)) == NULL)
    return (NULL);
  while (cur != -1 && cur != '\n') {
    rtn[it++] = cur;
    if ((it % 1024 == 0) &&
        ((rtn = enlarge_buffer(rtn, it, it + 1024)) == NULL))
      return (NULL);
    cur = in_char(fd);
  }
  rtn[it] = '\0';
  return (rtn);
}


x86 assembly (clang, -O0):
<in_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <in_char@plt>
mov    %al,-0x19(%rbp)
mov    $0x400,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1172 <in_line+0x42>
movq   $0x0,-0x8(%rbp)
jmp    1226 <in_line+0xf6>
jmp    1177 <in_line+0x47>
movsbl -0x19(%rbp),%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x21(%rbp)
je     1196 <in_line+0x66>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11a6 <in_line+0x76>
jmp    1212 <in_line+0xe2>
mov    -0x19(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x20(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1202 <in_line+0xd2>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x20(%rbp),%edx
add    $0x400,%edx
call   1030 <enlarge_buffer@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1202 <in_line+0xd2>
movq   $0x0,-0x8(%rbp)
jmp    1226 <in_line+0xf6>
mov    -0xc(%rbp),%edi
call   1050 <in_char@plt>
mov    %al,-0x19(%rbp)
jmp    1177 <in_line+0x47>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<in_line>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
call   1050 <in_char@plt>
mov    %eax,%ebx
mov    $0x400,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     119f <in_line+0x6f>
mov    %rax,%r15
xor    %edx,%edx
jmp    116d <in_line+0x3d>
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
call   1050 <in_char@plt>
mov    %eax,%ebx
mov    %rbp,%rdx
cmp    $0xff,%bl
je     11a4 <in_line+0x74>
cmp    $0xa,%bl
je     11a4 <in_line+0x74>
mov    %bl,(%r15,%rdx,1)
lea    0x1(%rdx),%rbp
test   $0x3ff,%ebp
jne    1160 <in_line+0x30>
add    $0x401,%edx
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <enlarge_buffer@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1160 <in_line+0x30>
xor    %r15d,%r15d
jmp    11a9 <in_line+0x79>
movb   $0x0,(%r15,%rdx,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @in_line(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %6
%7 = load i32, i32* %3
%8 = call signext i8 @in_char(i32 %7)
store i8 %8, i8* %5
%9 = call i8* @malloc(i32 1024)
store i8* %9, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i8* null, i8** %2
br label %50
12: ; preds = %1
br label %13
13: ; preds = %41, %12
%14 = load i8, i8* %5
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i8, i8* %5
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 10
br label %21
21: ; preds = %17, %13
%22 = phi i1 [ false, %13 ], [ %20, %17 ]
br i1 %22, label %23, label %44
23: ; preds = %21
%24 = load i8, i8* %5
%25 = load i8*, i8** %4
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
store i8 %24, i8* %29
%30 = load i32, i32* %6
%31 = srem i32 %30, 1024
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %41
33: ; preds = %23
%34 = load i8*, i8** %4
%35 = load i32, i32* %6
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1024
%38 = call i8* @enlarge_buffer(i8* %34, i32 %35, i32 %37)
store i8* %38, i8** %4
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %41
40: ; preds = %33
store i8* null, i8** %2
br label %50
41: ; preds = %33, %23
%42 = load i32, i32* %3
%43 = call signext i8 @in_char(i32 %42)
store i8 %43, i8* %5
br label %13
44: ; preds = %21
%45 = load i8*, i8** %4
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 0, i8* %48
%49 = load i8*, i8** %4
store i8* %49, i8** %2
br label %50
50: ; preds = %44, %40, %11
%51 = load i8*, i8** %2
ret i8* %51
}

LLVM IR (-O2):
define i8* @in_line(i32 %0) {
%2 = tail call signext i8 @in_char(i32 %0)
%3 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%4 = icmp eq i8* %3, null
br i1 %4, label %27, label %5
5: ; preds = %1, %21
%6 = phi i64 [ %11, %21 ], [ 0, %1 ]
%7 = phi i8* [ %22, %21 ], [ %3, %1 ]
%8 = phi i8 [ %23, %21 ], [ %2, %1 ]
%9 = phi i32 [ %12, %21 ], [ 0, %1 ]
switch i8 %8, label %10 [
i8 -1, label %24
i8 10, label %24
]
10: ; preds = %5
%11 = add nuw i64 %6, 1
%12 = add nuw nsw i32 %9, 1
%13 = getelementptr inbounds i8, i8* %7, i64 %6
store i8 %8, i8* %13
%14 = trunc i64 %11 to i32
%15 = and i32 %14, 1023
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = add nuw nsw i32 %9, 1025
%19 = tail call i8* @enlarge_buffer(i8* %7, i32 %14, i32 %18)
%20 = icmp eq i8* %19, null
br i1 %20, label %27, label %21
21: ; preds = %17, %10
%22 = phi i8* [ %19, %17 ], [ %7, %10 ]
%23 = tail call signext i8 @in_char(i32 %0)
br label %5
24: ; preds = %5, %5
%25 = and i64 %6, 4294967295
%26 = getelementptr inbounds i8, i8* %7, i64 %25
store i8 0, i8* %26
br label %27
27: ; preds = %17, %1, %24
%28 = phi i8* [ %7, %24 ], [ null, %1 ], [ null, %17 ]
ret i8* %28
}