#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 /*<<< orphan*/ reverse_string(char *);
int main(void) {
  char line[1000];
  int character;
  int index = 0;
  while ((character = getchar()) != EOF) {
    if (character != '\n') {
      line[index] = character;
      index++;
    } else {
      line[index] = '\0';
      index = 0;
      reverse_string(line);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x3f8(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x3f4(%rbp)
mov    0x2e98(%rip),%rcx
cmp    (%rcx),%eax
je     11b9 <main+0x99>
cmpl   $0xa,-0x3f4(%rbp)
je     118f <main+0x6f>
mov    -0x3f4(%rbp),%eax
mov    %al,%cl
movslq -0x3f8(%rbp),%rax
mov    %cl,-0x3f0(%rbp,%rax,1)
mov    -0x3f8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3f8(%rbp)
jmp    11b4 <main+0x94>
movslq -0x3f8(%rbp),%rax
movb   $0x0,-0x3f0(%rbp,%rax,1)
movl   $0x0,-0x3f8(%rbp)
lea    -0x3f0(%rbp),%rdi
call   1030 <reverse_string@plt>
jmp    113c <main+0x1c>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x3f0,%rsp
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2eae(%rip),%r15
cmp    (%r15),%eax
jne    114e <main+0x2e>
xor    %eax,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rsp,%r14
xor    %ebx,%ebx
jmp    117d <main+0x5d>
cs nopw 0x0(%rax,%rax,1)
nop
movslq %ebx,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
call   1030 <reverse_string@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    (%r15),%eax
je     113f <main+0x1f>
cmp    $0xa,%eax
je     1160 <main+0x40>
movslq %ebx,%rbx
mov    %al,(%rsp,%rbx,1)
add    $0x1,%ebx
jmp    1171 <main+0x51>

LLVM IR (-O0):
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
br label %5
5: ; preds = %26, %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 %27
9: ; preds = %5
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 10
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i32, i32* %3
%14 = trunc i32 %13 to i8
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %16
store i8 %14, i8* %17
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %26
20: ; preds = %9
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %22
store i8 0, i8* %23
store i32 0, i32* %4
%24 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%25 = call i32 @reverse_string(i8* %24)
br label %26
26: ; preds = %20, %12
br label %5
27: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 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 %24, label %6
6: ; preds = %0, %19
%7 = phi i32 [ %21, %19 ], [ %3, %0 ]
%8 = phi i32 [ %20, %19 ], [ 0, %0 ]
%9 = icmp eq i32 %7, 10
br i1 %9, label %15, label %10
10: ; preds = %6
%11 = trunc i32 %7 to i8
%12 = sext i32 %8 to i64
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %12
store i8 %11, i8* %13
%14 = add nsw i32 %8, 1
br label %19
15: ; preds = %6
%16 = sext i32 %8 to i64
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %16
store i8 0, i8* %17
%18 = call i32 @reverse_string(i8* %2)
br label %19
19: ; preds = %15, %10
%20 = phi i32 [ %14, %10 ], [ 0, %15 ]
%21 = call i32 (...) @getchar()
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %6
24: ; preds = %19, %0
ret i32 0
}