#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 getnextline(char ret[]) {
  char c;
  int i = 0;
  while ((c = getchar()) != '\n') {
    if (c == EOF) {
      return -1;
    }
    ret[i] = c;
    i++;
  }
  ret[i] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<getnextline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     1177 <getnextline+0x67>
movsbl -0x11(%rbp),%eax
mov    0x2ea4(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    115b <getnextline+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    118a <getnextline+0x7a>
mov    -0x11(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1123 <getnextline+0x13>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getnextline>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
jne    112d <getnextline+0x1d>
xor    %eax,%eax
jmp    115b <getnextline+0x4b>
mov    0x2eb4(%rip),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
cmp    (%r12),%al
je     1162 <getnextline+0x52>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
jne    1140 <getnextline+0x30>
mov    %ebx,%eax
movb   $0x0,(%r15,%rax,1)
jmp    1168 <getnextline+0x58>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i8 0
define i32 @getnextline(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
br label %6
6: ; preds = %17, %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* %4
%12 = sext i8 %11 to i32
%13 = load i8, i8* @EOF
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %12, %14
br i1 %15, label %16, label %17
16: ; preds = %10
store i32 -1, i32* %2
br label %30
17: ; preds = %10
%18 = load i8, i8* %4
%19 = load i8*, i8** %3
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 %18, i8* %22
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %6
25: ; preds = %6
%26 = load i8*, i8** %3
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 0, i8* %29
store i32 0, i32* %2
br label %30
30: ; preds = %25, %16
%31 = load i32, i32* %2
ret i32 %31
}

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