#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*/ printf(char *, char *);
int /*<<< orphan*/ reverse(char *, int, int);
int main() {
  char userinput[1000];
  int c, i, j, f;
  for (i = 0, j = 0; (c = getchar()) != EOF && i < 1000; i++) {
    userinput[i] = c;
    if (c == '\n') {
      reverse(userinput, i - 1, j);
      j += i + 1;
    }
  }
  printf("%s\n", userinput);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x3f8(%rbp)
movl   $0x0,-0x3fc(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x3f4(%rbp)
xor    %eax,%eax
mov    0x2e7a(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x401(%rbp)
je     118f <main+0x5f>
cmpl   $0x3e8,-0x3f8(%rbp)
setl   %al
mov    %al,-0x401(%rbp)
mov    -0x401(%rbp),%al
test   $0x1,%al
jne    11a2 <main+0x72>
jmp    120e <main+0xde>
mov    -0x3f4(%rbp),%eax
mov    %al,%cl
movslq -0x3f8(%rbp),%rax
mov    %cl,-0x3f0(%rbp,%rax,1)
cmpl   $0xa,-0x3f4(%rbp)
jne    11f5 <main+0xc5>
lea    -0x3f0(%rbp),%rdi
mov    -0x3f8(%rbp),%esi
sub    $0x1,%esi
mov    -0x3fc(%rbp),%edx
call   1030 <reverse@plt>
mov    -0x3f8(%rbp),%eax
add    $0x1,%eax
add    -0x3fc(%rbp),%eax
mov    %eax,-0x3fc(%rbp)
jmp    11fa <main+0xca>
mov    -0x3f8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3f8(%rbp)
jmp    1156 <main+0x26>
lea    -0x3f0(%rbp),%rsi
lea    0xde4(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f0,%rsp
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e9a(%rip),%r15
cmp    (%r15),%eax
je     119c <main+0x6c>
mov    %rsp,%r14
xor    %ebx,%ebx
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
mov    %al,(%rsp,%rbx,1)
cmp    $0xa,%eax
jne    1180 <main+0x50>
lea    -0x1(%rbx),%esi
mov    %r14,%rdi
mov    %r12d,%edx
call   1030 <reverse@plt>
lea    0x1(%rbx),%r13
add    %r13d,%r12d
jmp    1184 <main+0x54>
nop
lea    0x1(%rbx),%r13
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r15),%eax
je     119c <main+0x6c>
cmp    $0x3e7,%rbx
mov    %r13,%rbx
jb     1160 <main+0x30>
lea    0xe5d(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@EOF = global i32 0
@.str = [4 x i8] c"%s\0A\00"
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 %30, label %6
6: ; preds = %0, %22
%7 = phi i64 [ %23, %22 ], [ 0, %0 ]
%8 = phi i32 [ %25, %22 ], [ %3, %0 ]
%9 = phi i32 [ %24, %22 ], [ 0, %0 ]
%10 = trunc i32 %8 to i8
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %7
store i8 %10, i8* %11
%12 = icmp eq i32 %8, 10
br i1 %12, label %15, label %13
13: ; preds = %6
%14 = add nuw nsw i64 %7, 1
br label %22
15: ; preds = %6
%16 = trunc i64 %7 to i32
%17 = add i32 %16, -1
%18 = call i32 @reverse(i8* %2, i32 %17, i32 %9)
%19 = add nuw nsw i64 %7, 1
%20 = trunc i64 %19 to i32
%21 = add nsw i32 %9, %20
br label %22
22: ; preds = %13, %15
%23 = phi i64 [ %14, %13 ], [ %19, %15 ]
%24 = phi i32 [ %9, %13 ], [ %21, %15 ]
%25 = call i32 (...) @getchar()
%26 = load i32, i32* @EOF
%27 = icmp ne i32 %25, %26
%28 = icmp ult i64 %7, 999
%29 = select i1 %27, i1 %28, i1 false
br i1 %29, label %6, label %30
30: ; preds = %22, %0
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
ret i32 0
}