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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1040 <getaline@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    119c <main+0x6c>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1178 <main+0x48>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    -0x400(%rbp),%rdi
call   1030 <reverse@plt>
lea    -0x400(%rbp),%rsi
lea    0xe6e(%rip),%rdi
call   1050 <printf@plt>
jmp    1149 <main+0x19>
cmpl   $0x3e8,-0xc(%rbp)
jle    11b5 <main+0x85>
movl   $0x1,-0x4(%rbp)
jmp    11bc <main+0x8c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x3f0,%rsp
mov    %rsp,%rdi
mov    $0x3e8,%esi
call   1040 <getaline@plt>
test   %eax,%eax
jle    1196 <main+0x66>
xor    %ebp,%ebp
mov    %rsp,%rbx
lea    0xea8(%rip),%r14
nopl   0x0(%rax,%rax,1)
cmp    %ebp,%eax
cmovg  %eax,%ebp
mov    %rbx,%rdi
call   1030 <reverse@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1040 <getaline@plt>
test   %eax,%eax
jg     1160 <main+0x30>
xor    %eax,%eax
cmp    $0x3e9,%ebp
setae  %al
jmp    1198 <main+0x68>
xor    %eax,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\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 @getaline(i8* %2, i32 1000)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %17
5: ; preds = %0, %5
%6 = phi i32 [ %12, %5 ], [ %3, %0 ]
%7 = phi i32 [ %9, %5 ], [ 0, %0 ]
%8 = icmp sgt i32 %6, %7
%9 = select i1 %8, i32 %6, i32 %7
%10 = call i32 @reverse(i8* %2)
%11 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%12 = call i32 @getaline(i8* %2, i32 1000)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %5, label %14
14: ; preds = %5
%15 = icmp ugt i32 %9, 1000
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %14, %0
%18 = phi i32 [ 0, %0 ], [ %16, %14 ]
ret i32 %18
}