#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 uint32_t;

/* Variables and functions */
char EOF;
int EXIT_SUCCESS;
int /*<<< orphan*/ free(char *);
char getchar();
int /*<<< orphan*/ printf(char *, char *);
char *realloc(char *, int);
int /*<<< orphan*/ reverse(char *);
int main(void) {
  char *buffer = NULL;
  uint32_t buffer_length = 0;
  char character = 0;
  bool finished_inputting = false;
  while (finished_inputting == false) {
    character = getchar();
    if (character == '\n' || (character == EOF && buffer_length > 0)) {
      buffer = realloc(buffer, ++buffer_length * sizeof(char));
      buffer[buffer_length - 1] = '\0';
      reverse(buffer);
      printf("%s\n", buffer);
      free(buffer);
      buffer = NULL;
      buffer_length = 0;
    } else {
      buffer = realloc(buffer, ++buffer_length * sizeof(char));
      buffer[buffer_length - 1] = character;
    }
    finished_inputting = (character == EOF);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1270 <main+0x120>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%eax
cmp    $0xa,%eax
je     11ba <main+0x6a>
movsbl -0x15(%rbp),%eax
mov    0x2e43(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    121f <main+0xcf>
cmpl   $0x0,-0x14(%rbp)
jle    121f <main+0xcf>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%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    0xe03(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
jmp    1250 <main+0x100>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x15(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movsbl -0x15(%rbp),%eax
mov    0x2d8d(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
jmp    1179 <main+0x29>
mov    0x2d61(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%r14
mov    0x2e7f(%rip),%r12
xor    %ebp,%ebp
xor    %r15d,%r15d
jmp    11ab <main+0x5b>
add    $0x1,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
call   1070 <realloc@plt>
mov    %rax,%rbp
movb   $0x0,(%rax,%r13,1)
mov    %rax,%rdi
call   1030 <reverse@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
xor    %r15d,%r15d
xor    %ebp,%ebp
cmp    (%r12),%bl
je     11df <main+0x8f>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %eax,%ebx
movslq %ebp,%r13
cmp    $0xa,%al
je     1170 <main+0x20>
test   %ebp,%ebp
jle    11c5 <main+0x75>
cmp    (%r12),%bl
je     1170 <main+0x20>
add    $0x1,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
call   1070 <realloc@plt>
mov    %rax,%r15
mov    %bl,(%rax,%r13,1)
cmp    (%r12),%bl
jne    11ab <main+0x5b>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i8 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 i32
%4 = alloca i8
%5 = alloca i32
store i32 0, i32* %1
store i8* null, i8** %2
store i32 0, i32* %3
store i8 0, i8* %4
store i32 0, i32* %5
br label %6
6: ; preds = %56, %0
%7 = load i32, i32* %5
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %63
9: ; preds = %6
%10 = call signext i8 (...) @getchar()
store i8 %10, i8* %4
%11 = load i8, i8* %4
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 10
br i1 %13, label %23, label %14
14: ; preds = %9
%15 = load i8, i8* %4
%16 = sext i8 %15 to i32
%17 = load i8, i8* @EOF
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %16, %18
br i1 %19, label %20, label %42
20: ; preds = %14
%21 = load i32, i32* %3
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %42
23: ; preds = %20, %9
%24 = load i8*, i8** %2
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
%27 = sext i32 %26 to i64
%28 = mul i64 %27, 1
%29 = trunc i64 %28 to i32
%30 = call i8* @realloc(i8* %24, i32 %29)
store i8* %30, i8** %2
%31 = load i8*, i8** %2
%32 = load i32, i32* %3
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
store i8 0, i8* %35
%36 = load i8*, i8** %2
%37 = call i32 @reverse(i8* %36)
%38 = load i8*, i8** %2
%39 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %38)
%40 = load i8*, i8** %2
%41 = call i32 @free(i8* %40)
store i8* null, i8** %2
store i32 0, i32* %3
br label %56
42: ; preds = %20, %14
%43 = load i8*, i8** %2
%44 = load i32, i32* %3
%45 = add nsw i32 %44, 1
store i32 %45, i32* %3
%46 = sext i32 %45 to i64
%47 = mul i64 %46, 1
%48 = trunc i64 %47 to i32
%49 = call i8* @realloc(i8* %43, i32 %48)
store i8* %49, i8** %2
%50 = load i8, i8* %4
%51 = load i8*, i8** %2
%52 = load i32, i32* %3
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %51, i64 %54
store i8 %50, i8* %55
br label %56
56: ; preds = %42, %23
%57 = load i8, i8* %4
%58 = sext i8 %57 to i32
%59 = load i8, i8* @EOF
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %58, %60
%62 = zext i1 %61 to i32
store i32 %62, i32* %5
br label %6
63: ; preds = %6
%64 = load i32, i32* @EXIT_SUCCESS
ret i32 %64
}

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