#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 cmn_getline(int /*<<< orphan*/, char **);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  char *line;
  int retval = 0, i;
  while ((retval = cmn_getline(stdin, &line)) >= 0) {
    for (i = retval - 1; i >= 0; i--)
      putc(line[i], stdout);
    printf("\n");
    free(line);
    line = NULL;
  }
  if (retval != -1) {
    printf("rev: malloc/realloc error\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1060 <cmn_getline@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jl     11da <main+0x9a>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     11b8 <main+0x78>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    0x2e38(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1050 <putc@plt>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1184 <main+0x44>
lea    0xe5a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
jmp    115d <main+0x1d>
cmpl   $0xffffffff,-0x1c(%rbp)
je     11fc <main+0xbc>
lea    0xe15(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1203 <main+0xc3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2e89(%rip),%r14
mov    (%r14),%edi
mov    %rsp,%rsi
call   1070 <cmn_getline@plt>
test   %eax,%eax
js     11e0 <main+0x90>
mov    %rsp,%r15
mov    0x2e60(%rip),%r12
jmp    11aa <main+0x5a>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
movq   $0x0,(%rsp)
mov    (%r14),%edi
mov    %r15,%rsi
call   1070 <cmn_getline@plt>
test   %eax,%eax
js     11e0 <main+0x90>
test   %eax,%eax
je     1180 <main+0x30>
mov    %eax,%ebx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    -0x2(%rbx),%eax
mov    (%rsp),%rcx
movsbl (%rcx,%rax,1),%edi
mov    (%r12),%esi
call   1060 <putc@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     11c0 <main+0x70>
jmp    1180 <main+0x30>
cmp    $0xffffffff,%eax
je     11f8 <main+0xa8>
lea    0xe14(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%eax
jmp    11fa <main+0xaa>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@stdin = global i32 0
@stdout = global i32 0
@str = [26 x i8] c"rev: malloc/realloc error\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = load i32, i32* @stdin
%6 = call i32 @cmn_getline(i32 %5, i8** %3)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %30
8: ; preds = %2, %23
%9 = phi i32 [ %28, %23 ], [ %6, %2 ]
%10 = icmp eq i32 %9, 0
br i1 %10, label %23, label %11
11: ; preds = %8
%12 = zext i32 %9 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ %12, %11 ], [ %15, %13 ]
%15 = add nsw i64 %14, -1
%16 = load i8*, i8** %3
%17 = and i64 %15, 4294967295
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i8, i8* %18
%20 = load i32, i32* @stdout
%21 = call i32 @putc(i8 signext %19, i32 %20)
%22 = icmp ugt i64 %14, 1
br i1 %22, label %13, label %23
23: ; preds = %13, %8
%24 = call i32 @putchar(i32 10)
%25 = load i8*, i8** %3
%26 = call i32 @free(i8* %25)
store i8* null, i8** %3
%27 = load i32, i32* @stdin
%28 = call i32 @cmn_getline(i32 %27, i8** %3)
%29 = icmp sgt i32 %28, -1
br i1 %29, label %8, label %30
30: ; preds = %23, %2
%31 = phi i32 [ %6, %2 ], [ %28, %23 ]
%32 = icmp eq i32 %31, -1
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %35
35: ; preds = %30, %33
%36 = phi i32 [ 1, %33 ], [ 0, %30 ]
ret i32 %36
}