#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 */
scalar_t__ getchar();
char *next_line(void) {
  static char buf[512];
  unsigned long ptr = 0;
  char c;
  while (c = (char)getchar(), c != '\n')
    buf[ptr++] = c;
  buf[ptr] = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<next_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
je     1158 <next_line+0x48>
mov    -0x9(%rbp),%dl
mov    -0x8(%rbp),%rcx
mov    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
lea    0x2ef0(%rip),%rax
mov    %dl,(%rax,%rcx,1)
jmp    1120 <next_line+0x10>
mov    -0x8(%rbp),%rcx
lea    0x2edd(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2ed2(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_line>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
je     1143 <next_line+0x33>
lea    0x2f18(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %al,(%rbx,%r14,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
jne    1130 <next_line+0x20>
lea    0x2ef6(%rip),%rax
movb   $0x0,(%rbx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@next_line.buf = internal global [512 x i8] zeroinitializer
define i8* @next_line() {
%1 = alloca i64
%2 = alloca i8
store i64 0, i64* %1
br label %3
3: ; preds = %9, %0
%4 = call i64 (...) @getchar()
%5 = trunc i64 %4 to i8
store i8 %5, i8* %2
%6 = load i8, i8* %2
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 10
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = load i8, i8* %2
%11 = load i64, i64* %1
%12 = add i64 %11, 1
store i64 %12, i64* %1
%13 = getelementptr inbounds [512 x i8], [512 x i8]* @next_line.buf, i64 0, i64 %11
store i8 %10, i8* %13
br label %3
14: ; preds = %3
%15 = load i64, i64* %1
%16 = getelementptr inbounds [512 x i8], [512 x i8]* @next_line.buf, i64 0, i64 %15
store i8 0, i8* %16
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @next_line.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@next_line.buf = internal global [512 x i8] zeroinitializer
define i8* @next_line() {
%1 = tail call i64 (...) @getchar()
%2 = trunc i64 %1 to i8
%3 = icmp eq i8 %2, 10
br i1 %3, label %12, label %4
4: ; preds = %0, %4
%5 = phi i8 [ %10, %4 ], [ %2, %0 ]
%6 = phi i64 [ %7, %4 ], [ 0, %0 ]
%7 = add i64 %6, 1
%8 = getelementptr inbounds [512 x i8], [512 x i8]* @next_line.buf, i64 0, i64 %6
store i8 %5, i8* %8
%9 = tail call i64 (...) @getchar()
%10 = trunc i64 %9 to i8
%11 = icmp eq i8 %10, 10
br i1 %11, label %12, label %4
12: ; preds = %4, %0
%13 = phi i64 [ 0, %0 ], [ %7, %4 ]
%14 = getelementptr inbounds [512 x i8], [512 x i8]* @next_line.buf, i64 0, i64 %13
store i8 0, i8* %14
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @next_line.buf, i64 0, i64 0)
}