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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2720,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x2720(%rbp),%rdi
mov    $0x2710,%esi
call   1050 <my_getline@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11ac <main+0x7c>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x2720(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1188 <main+0x58>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x2720(%rbp,%rax,1)
lea    -0x2720(%rbp),%rdi
call   1030 <reverse@plt>
lea    -0x2720(%rbp),%rsi
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
jmp    1142 <main+0x12>
xor    %eax,%eax
add    $0x2720,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x2718,%rsp
mov    %rsp,%rdi
mov    $0x2710,%esi
call   1050 <my_getline@plt>
test   %eax,%eax
jle    1193 <main+0x63>
mov    %rsp,%rbx
lea    0xeab(%rip),%r14
jmp    1184 <main+0x54>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <reverse@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x2710,%esi
call   1050 <my_getline@plt>
test   %eax,%eax
jle    1193 <main+0x63>
add    $0xffffffff,%eax
cmpb   $0xa,(%rsp,%rax,1)
jne    1160 <main+0x30>
movb   $0x0,(%rsp,%rax,1)
jmp    1160 <main+0x30>
xor    %eax,%eax
add    $0x2718,%rsp
pop    %rbx
pop    %r14
ret

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

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