#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 _getline(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ reverse(char *, int);
main() {
  char line[1024];
  int length;
  while ((length = _getline(line, 1024)) > 0) {
    if (line[length - 1] == '\n') {
      length--;
    }
    reverse(line, length);
    printf("%s", line);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
call   1050 <_getline@plt>
mov    %eax,-0x414(%rbp)
cmp    $0x0,%eax
jle    11b7 <main+0x87>
mov    -0x414(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    118d <main+0x5d>
mov    -0x414(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x414(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x414(%rbp),%esi
call   1030 <reverse@plt>
lea    -0x410(%rbp),%rsi
lea    0xe53(%rip),%rdi
call   1040 <printf@plt>
jmp    1142 <main+0x12>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsp,%rdi
mov    $0x400,%esi
call   1050 <_getline@plt>
test   %eax,%eax
jle    1190 <main+0x60>
mov    %rsp,%rbx
lea    0xeab(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x1(%rax),%ecx
cmpb   $0xa,(%rsp,%rcx,1)
cmove  %ecx,%eax
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <reverse@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
call   1050 <_getline@plt>
test   %eax,%eax
jg     1160 <main+0x30>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

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

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