#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 /*<<< orphan*/ free(char *);
size_t getline(char **, size_t *, int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ reverse(char *, char *, size_t);
int /*<<< orphan*/ stdin;
int main(int argc, char const *argv[]) {
  char *line = NULL;
  size_t len = 0;
  size_t read;
  char *reversed;
  while ((read = getline(&line, &len, stdin)) != -1) {
    if (read > 0) {
      line[read - 1] = '\0';
      reversed = (char *)malloc(sizeof(char) * (read));
      reverse(line, reversed, read - 1);
      printf("%s\n", reversed);
      free(reversed);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <getline@plt>
mov    %rax,-0x28(%rbp)
cmp    $0xffffffffffffffff,%rax
je     11fb <main+0xab>
cmpq   $0x0,-0x28(%rbp)
jbe    11f6 <main+0xa6>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
sub    $0x1,%rdx
call   1030 <reverse@plt>
mov    -0x30(%rbp),%rsi
lea    0xe18(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
jmp    1176 <main+0x26>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2e71(%rip),%rbp
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%r12
lea    0xe78(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%edx
mov    %r14,%rdi
mov    %r12,%rsi
call   1070 <getline@plt>
test   %rax,%rax
je     1190 <main+0x40>
cmp    $0xffffffffffffffff,%rax
je     11e9 <main+0x99>
mov    0x8(%rsp),%rcx
mov    %rax,%rbx
add    $0xffffffffffffffff,%rbx
movb   $0x0,-0x1(%rcx,%rax,1)
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%r13
mov    0x8(%rsp),%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1030 <reverse@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1050 <printf@plt>
mov    %r13,%rdi
call   1040 <free@plt>
jmp    1190 <main+0x40>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
br label %7
7: ; preds = %10, %2
%8 = load i32, i32* @stdin
%9 = call i64 @getline(i8** %3, i64* %4, i32 %8)
switch i64 %9, label %11 [
i64 -1, label %22
i64 0, label %10
]
10: ; preds = %7, %11
br label %7
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = add i64 %9, -1
%14 = getelementptr inbounds i8, i8* %12, i64 %13
store i8 0, i8* %14
%15 = trunc i64 %9 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
%18 = load i8*, i8** %3
%19 = call i32 @reverse(i8* %18, i8* %17, i64 %13)
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %17)
%21 = call i32 @free(i8* %17)
br label %10
22: ; preds = %7
ret i32 0
}