#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 */
int /*<<< orphan*/ at_eof();
char get8();
char *hdr_gettoken(char *buffer) {
  int len = 0;
  char c = '\0';
  c = get8();
  while (!at_eof() && c != '\n') {
    buffer[len++] = c;
    if (len == 1024 - 1) {
      while (!at_eof() && get8() != '\n')
        ;
      break;
    }
    c = get8();
  }
  buffer[len] = 0;
  return buffer;
}


x86 assembly (clang, -O0):
<hdr_gettoken>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movb   $0x0,-0xd(%rbp)
mov    $0x0,%al
call   1030 <get8@plt>
mov    %al,-0xd(%rbp)
mov    $0x0,%al
call   1040 <at_eof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xe(%rbp)
jne    1165 <hdr_gettoken+0x45>
movsbl -0xd(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%al
test   $0x1,%al
jne    1175 <hdr_gettoken+0x55>
jmp    11f2 <hdr_gettoken+0xd2>
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)
cmpl   $0x3ff,-0xc(%rbp)
jne    11e3 <hdr_gettoken+0xc3>
jmp    119f <hdr_gettoken+0x7f>
mov    $0x0,%al
call   1040 <at_eof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xf(%rbp)
jne    11c9 <hdr_gettoken+0xa9>
mov    $0x0,%al
call   1030 <get8@plt>
movsbl %al,%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0xf(%rbp)
mov    -0xf(%rbp),%al
test   $0x1,%al
jne    11d9 <hdr_gettoken+0xb9>
jmp    11de <hdr_gettoken+0xbe>
jmp    119f <hdr_gettoken+0x7f>
jmp    11f2 <hdr_gettoken+0xd2>
mov    $0x0,%al
call   1030 <get8@plt>
mov    %al,-0xd(%rbp)
jmp    1141 <hdr_gettoken+0x21>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hdr_gettoken>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <get8@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <at_eof@plt>
test   %eax,%eax
jne    11a6 <hdr_gettoken+0x86>
cmp    $0xa,%bpl
je     11a6 <hdr_gettoken+0x86>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %bpl,(%r14,%rbx,1)
cmp    $0x3fe,%rbx
je     117d <hdr_gettoken+0x5d>
xor    %eax,%eax
call   1030 <get8@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <at_eof@plt>
add    $0x1,%rbx
test   %eax,%eax
jne    11a6 <hdr_gettoken+0x86>
cmp    $0xa,%bpl
jne    1150 <hdr_gettoken+0x30>
jmp    11a6 <hdr_gettoken+0x86>
mov    $0x3ff,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <at_eof@plt>
test   %eax,%eax
jne    11a6 <hdr_gettoken+0x86>
xor    %eax,%eax
call   1030 <get8@plt>
cmp    $0xa,%al
jne    1190 <hdr_gettoken+0x70>
movb   $0x0,(%r14,%rbx,1)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @hdr_gettoken(i8* returned writeonly %0) {
%2 = tail call signext i8 (...) @get8()
%3 = tail call i32 (...) @at_eof()
%4 = icmp eq i32 %3, 0
%5 = icmp ne i8 %2, 10
%6 = select i1 %4, i1 %5, i1 false
br i1 %6, label %7, label %28
7: ; preds = %1, %19
%8 = phi i64 [ %10, %19 ], [ 0, %1 ]
%9 = phi i8 [ %20, %19 ], [ %2, %1 ]
%10 = add nuw nsw i64 %8, 1
%11 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 %9, i8* %11
%12 = icmp eq i64 %10, 1023
br i1 %12, label %13, label %19
13: ; preds = %7, %16
%14 = tail call i32 (...) @at_eof()
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %13
%17 = tail call signext i8 (...) @get8()
%18 = icmp eq i8 %17, 10
br i1 %18, label %28, label %13
19: ; preds = %7
%20 = tail call signext i8 (...) @get8()
%21 = tail call i32 (...) @at_eof()
%22 = icmp eq i32 %21, 0
%23 = icmp ne i8 %20, 10
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %7, label %25
25: ; preds = %19
%26 = shl i64 %10, 32
%27 = ashr exact i64 %26, 32
br label %28
28: ; preds = %16, %13, %25, %1
%29 = phi i64 [ 0, %1 ], [ %27, %25 ], [ 1023, %13 ], [ 1023, %16 ]
%30 = getelementptr inbounds i8, i8* %0, i64 %29
store i8 0, i8* %30
ret i8* %0
}