#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 */
typedef int ssize_t;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ reverse(char *);
int /*<<< orphan*/ stdin;
int main(void) {
  char *buffer = NULL;
  size_t buffer_size = 0;
  ssize_t line_chars;
  while ((line_chars = getline(&buffer, &buffer_size, stdin)) != -1) {
    if (buffer[line_chars - 1] == '\n') {
      buffer[line_chars - 1] = '\0';
    }
    reverse(buffer);
    printf("%s\n", buffer);
  }
  if (buffer != NULL)
    free(buffer);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <getline@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     11ca <main+0x8a>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11ac <main+0x6c>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <reverse@plt>
mov    -0x10(%rbp),%rsi
lea    0xe40(%rip),%rdi
call   1050 <printf@plt>
jmp    115f <main+0x1f>
cmpq   $0x0,-0x10(%rbp)
je     11de <main+0x9e>
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2e84(%rip),%r12
mov    (%r12),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
je     11d0 <main+0x90>
lea    0xe7d(%rip),%r14
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%rbx
jmp    11b6 <main+0x76>
nop
call   1030 <reverse@plt>
mov    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    (%r12),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
je     11d0 <main+0x90>
mov    0x8(%rsp),%rdi
cltq
cmpb   $0xa,-0x1(%rax,%rdi,1)
jne    1190 <main+0x50>
movb   $0x0,-0x1(%rdi,%rax,1)
mov    0x8(%rsp),%rdi
jmp    1190 <main+0x50>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     11df <main+0x9f>
call   1040 <free@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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