#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 getchar();
int get_line(char *arr) {
  char c;
  int len = 0;
  while ((c = getchar()) != EOF) {
    if (c == '\n') {
      break;
    }
    arr[len++] = c;
  }
  return len;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%eax
mov    0x2eb1(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1171 <get_line+0x61>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
jne    1154 <get_line+0x44>
jmp    1171 <get_line+0x61>
mov    -0x9(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1123 <get_line+0x13>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
je     1158 <get_line+0x48>
mov    0x2ebc(%rip),%r15
cmp    (%r15),%al
je     1158 <get_line+0x48>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
je     1158 <get_line+0x48>
cmp    (%r15),%al
jne    1140 <get_line+0x30>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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