#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 *s = buffer, 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    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
mov    $0x0,%al
call   1030 <get8@plt>
mov    %al,-0x19(%rbp)
mov    $0x0,%al
call   1040 <at_eof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1a(%rbp)
jne    116d <hdr_gettoken+0x4d>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
test   $0x1,%al
jne    117d <hdr_gettoken+0x5d>
jmp    11fa <hdr_gettoken+0xda>
mov    -0x19(%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    11eb <hdr_gettoken+0xcb>
jmp    11a7 <hdr_gettoken+0x87>
mov    $0x0,%al
call   1040 <at_eof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1b(%rbp)
jne    11d1 <hdr_gettoken+0xb1>
mov    $0x0,%al
call   1030 <get8@plt>
movsbl %al,%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x1b(%rbp)
mov    -0x1b(%rbp),%al
test   $0x1,%al
jne    11e1 <hdr_gettoken+0xc1>
jmp    11e6 <hdr_gettoken+0xc6>
jmp    11a7 <hdr_gettoken+0x87>
jmp    11fa <hdr_gettoken+0xda>
mov    $0x0,%al
call   1030 <get8@plt>
mov    %al,-0x19(%rbp)
jmp    1149 <hdr_gettoken+0x29>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x20,%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*
%5 = alloca i8
store i8* %0, i8** %2
store i32 0, i32* %3
%6 = load i8*, i8** %2
store i8* %6, i8** %4
store i8 0, i8* %5
%7 = call signext i8 (...) @get8()
store i8 %7, i8* %5
br label %8
8: ; preds = %38, %1
%9 = call i32 (...) @at_eof()
%10 = icmp ne i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = load i8, i8* %5
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 10
br label %15
15: ; preds = %11, %8
%16 = phi i1 [ false, %8 ], [ %14, %11 ]
br i1 %16, label %17, label %40
17: ; preds = %15
%18 = load i8, i8* %5
%19 = load i8*, i8** %2
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
store i8 %18, i8* %23
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 1023
br i1 %25, label %26, label %38
26: ; preds = %17
br label %27
27: ; preds = %36, %26
%28 = call i32 (...) @at_eof()
%29 = icmp ne i32 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %27
%31 = call signext i8 (...) @get8()
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 10
br label %34
34: ; preds = %30, %27
%35 = phi i1 [ false, %27 ], [ %33, %30 ]
br i1 %35, label %36, label %37
36: ; preds = %34
br label %27
37: ; preds = %34
br label %40
38: ; preds = %17
%39 = call signext i8 (...) @get8()
store i8 %39, i8* %5
br label %8
40: ; preds = %37, %15
%41 = load i8*, i8** %2
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 0, i8* %44
%45 = load i8*, i8** %2
ret i8* %45
}

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
}