#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 EOF;
int getchar();
int htoi(char *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  char str[0x1000];
  int c;
  int i = 0;
  while ((c = getchar()) != EOF) {
    if (i > 0x1000)
      break;
    if (c == '\n') {
      str[i] = 0;
      printf("%x\n", htoi(str));
      i = 0;
    } else {
      str[i] = c;
      i++;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1018(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x1014(%rbp)
mov    0x2e88(%rip),%rcx
cmp    (%rcx),%eax
je     11ec <main+0xbc>
cmpl   $0x1000,-0x1018(%rbp)
jle    117d <main+0x4d>
jmp    11ec <main+0xbc>
cmpl   $0xa,-0x1014(%rbp)
jne    11c2 <main+0x92>
movslq -0x1018(%rbp),%rax
movb   $0x0,-0x1010(%rbp,%rax,1)
lea    -0x1010(%rbp),%rdi
call   1050 <htoi@plt>
mov    %eax,%esi
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x1018(%rbp)
jmp    11e7 <main+0xb7>
mov    -0x1014(%rbp),%eax
mov    %al,%cl
movslq -0x1018(%rbp),%rax
mov    %cl,-0x1010(%rbp,%rax,1)
mov    -0x1018(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1018(%rbp)
jmp    114c <main+0x1c>
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1008,%rsp
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2e9c(%rip),%r12
cmp    (%r12),%eax
je     11ab <main+0x7b>
mov    %rsp,%r14
lea    0xea4(%rip),%r15
xor    %ebx,%ebx
xchg   %ax,%ax
movslq %ebx,%rbx
cmp    $0xa,%eax
jne    1190 <main+0x60>
movb   $0x0,(%rsp,%rbx,1)
mov    %r14,%rdi
call   1050 <htoi@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %ebx,%ebx
jmp    1196 <main+0x66>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %al,(%rsp,%rbx,1)
add    $0x1,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    (%r12),%eax
je     11ab <main+0x7b>
cmp    $0x1001,%ebx
jl     1160 <main+0x30>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [4 x i8] c"%x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4096 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
br label %5
5: ; preds = %31, %0
%6 = call i32 (...) @getchar()
store i32 %6, i32* %3
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %6, %7
br i1 %8, label %9, label %32
9: ; preds = %5
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 4096
br i1 %11, label %12, label %13
12: ; preds = %9
br label %32
13: ; preds = %9
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 10
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 %18
store i8 0, i8* %19
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%21 = call i32 @htoi(i8* %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 0, i32* %4
br label %31
23: ; preds = %13
%24 = load i32, i32* %3
%25 = trunc i32 %24 to i8
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 %27
store i8 %25, i8* %28
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %31
31: ; preds = %23, %16
br label %5
32: ; preds = %12, %5
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [4 x i8] c"%x\0A\00"
define i32 @main() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%3 = call i32 (...) @getchar()
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %27, label %6
6: ; preds = %0, %20
%7 = phi i32 [ %22, %20 ], [ %3, %0 ]
%8 = phi i32 [ %21, %20 ], [ 0, %0 ]
%9 = icmp eq i32 %7, 10
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = sext i32 %8 to i64
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %11
store i8 0, i8* %12
%13 = call i32 @htoi(i8* %2)
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %20
15: ; preds = %6
%16 = trunc i32 %7 to i8
%17 = sext i32 %8 to i64
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %17
store i8 %16, i8* %18
%19 = add nsw i32 %8, 1
br label %20
20: ; preds = %15, %10
%21 = phi i32 [ 0, %10 ], [ %19, %15 ]
%22 = call i32 (...) @getchar()
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
%25 = icmp sgt i32 %21, 4096
%26 = select i1 %24, i1 true, i1 %25
br i1 %26, label %27, label %6
27: ; preds = %20, %0
ret i32 0
}