#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 EOF;
char *expand_array(char *);
int get_array_size(char *);
char getchar();
int get_line(char line[]) {
  int line_length = 0;
  char current_char = EOF;
  while ((current_char = getchar()) != '\n') {
    if (get_array_size(line) < line_length) {
      line = expand_array(line);
    }
    line[line_length++] = current_char;
  }
  line[line_length] = '\0';
  return line_length;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%al
mov    %al,-0xd(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0xd(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     11a1 <get_line+0x71>
mov    -0x8(%rbp),%rdi
call   1050 <get_array_size@plt>
cmp    -0xc(%rbp),%eax
jge    1184 <get_line+0x54>
mov    -0x8(%rbp),%rdi
call   1030 <expand_array@plt>
mov    %rax,-0x8(%rbp)
mov    -0xd(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0xc(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    114f <get_line+0x1f>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
jne    1152 <get_line+0x22>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %eax,%ebp
xor    %ebx,%ebx
jmp    1175 <get_line+0x45>
nopl   0x0(%rax,%rax,1)
mov    %bpl,(%r14,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebp
cmp    $0xa,%al
je     1144 <get_line+0x14>
mov    %r14,%rdi
call   1050 <get_array_size@plt>
cltq
cmp    %rax,%rbx
jle    1160 <get_line+0x30>
mov    %r14,%rdi
call   1030 <expand_array@plt>
mov    %rax,%r14
jmp    1160 <get_line+0x30>

LLVM IR (-O0):
@EOF = global i8 0
define i32 @get_line(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8, i8* @EOF
store i8 %5, i8* %4
br label %6
6: ; preds = %18, %1
%7 = call signext i8 (...) @getchar()
store i8 %7, i8* %4
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 10
br i1 %9, label %10, label %25
10: ; preds = %6
%11 = load i8*, i8** %2
%12 = call i32 @get_array_size(i8* %11)
%13 = load i32, i32* %3
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i8*, i8** %2
%17 = call i8* @expand_array(i8* %16)
store i8* %17, i8** %2
br label %18
18: ; preds = %15, %10
%19 = load i8, i8* %4
%20 = load i8*, i8** %2
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8 %19, i8* %24
br label %6
25: ; preds = %6
%26 = load i8*, i8** %2
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 0, i8* %29
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@EOF = global i8 0
define i32 @get_line(i8* %0) {
%2 = tail call signext i8 (...) @getchar()
%3 = icmp eq i8 %2, 10
br i1 %3, label %21, label %4
4: ; preds = %1, %13
%5 = phi i64 [ %15, %13 ], [ 0, %1 ]
%6 = phi i8 [ %17, %13 ], [ %2, %1 ]
%7 = phi i8* [ %14, %13 ], [ %0, %1 ]
%8 = tail call i32 @get_array_size(i8* %7)
%9 = sext i32 %8 to i64
%10 = icmp sgt i64 %5, %9
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = tail call i8* @expand_array(i8* %7)
br label %13
13: ; preds = %11, %4
%14 = phi i8* [ %12, %11 ], [ %7, %4 ]
%15 = add nuw i64 %5, 1
%16 = getelementptr inbounds i8, i8* %14, i64 %5
store i8 %6, i8* %16
%17 = tail call signext i8 (...) @getchar()
%18 = icmp eq i8 %17, 10
br i1 %18, label %19, label %4
19: ; preds = %13
%20 = trunc i64 %15 to i32
br label %21
21: ; preds = %19, %1
%22 = phi i8* [ %0, %1 ], [ %14, %19 ]
%23 = phi i32 [ 0, %1 ], [ %20, %19 ]
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 0, i8* %25
ret i32 %23
}