#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 EXIT_SUCCESS;
int gtline(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ reverse(char *, int);
int main(int argc, char **argv) {
  int len, max;
  char line[1000];
  while ((len = gtline(line, 1000)) > 0) {
    reverse(line, len);
    if (line[len - 1] == '\n')
      printf("%s", line);
    else
      printf("%s\n", line);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1050 <gtline@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    11be <main+0x8e>
lea    -0x400(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <reverse@plt>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x400(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    11a6 <main+0x76>
lea    -0x400(%rbp),%rsi
lea    0xe64(%rip),%rdi
call   1040 <printf@plt>
jmp    11b9 <main+0x89>
lea    -0x400(%rbp),%rsi
lea    0xe4f(%rip),%rdi
call   1040 <printf@plt>
jmp    1149 <main+0x19>
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3e8,%rsp
mov    %rsp,%rdi
mov    $0x3e8,%esi
call   1050 <gtline@plt>
test   %eax,%eax
jle    11a3 <main+0x73>
mov    %eax,%ebx
mov    %rsp,%r14
lea    0xea5(%rip),%r15
lea    0xea1(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <reverse@plt>
add    $0xffffffff,%ebx
cmpb   $0xa,(%rsp,%rbx,1)
mov    %r12,%rdi
cmove  %r15,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x3e8,%esi
call   1050 <gtline@plt>
mov    %eax,%ebx
test   %eax,%eax
jg     1170 <main+0x40>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = call i32 @gtline(i8* %4, i32 1000)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %2, %7
%8 = phi i32 [ %17, %7 ], [ %5, %2 ]
%9 = call i32 @reverse(i8* %4, i32 %8)
%10 = add nsw i32 %8, -1
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 10
%15 = select i1 %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%16 = call i32 @printf(i8* %15, i8* %4)
%17 = call i32 @gtline(i8* %4, i32 1000)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %7, label %19
19: ; preds = %7, %2
%20 = load i32, i32* @EXIT_SUCCESS
ret i32 %20
}