#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*/ exit(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getch();
int /*<<< orphan*/ gets(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int strlen(char *);
main(void) {
  char *s;
  int t;
  s = malloc(900);
  if (s == NULL) {
    printf("Falha na solicitação de memória. \n");
    exit(1);
  }
  gets(s);
  for (t = strlen(s) - 1; t >= 0; t--)
    putchar(s[t]);
  getch();
  free(s);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x384,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11be <main+0x3e>
lea    0xe51(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1070 <gets@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11ff <main+0x7f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <putchar@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11d6 <main+0x56>
mov    $0x0,%al
call   1090 <getch@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x384,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     11e0 <main+0x60>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <gets@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    11c7 <main+0x47>
mov    %eax,%ebx
add    $0x1,%rbx
lea    -0x2(%rbx),%eax
movsbl (%r14,%rax,1),%edi
call   1040 <putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     11b0 <main+0x30>
xor    %eax,%eax
call   1090 <getch@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe19(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"Falha na solicita\C3\A7\C3\A3o de mem\C3\B3ria. \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i8* @malloc(i32 900)
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i8*, i8** %2
%12 = call i32 @gets(i8* %11)
%13 = load i8*, i8** %2
%14 = call i32 @strlen(i8* %13)
%15 = sub nsw i32 %14, 1
store i32 %15, i32* %3
br label %16
16: ; preds = %26, %10
%17 = load i32, i32* %3
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %29
19: ; preds = %16
%20 = load i8*, i8** %2
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = call i32 @putchar(i8 signext %24)
br label %26
26: ; preds = %19
%27 = load i32, i32* %3
%28 = add nsw i32 %27, -1
store i32 %28, i32* %3
br label %16
29: ; preds = %16
%30 = call i32 (...) @getch()
%31 = load i8*, i8** %2
%32 = call i32 @free(i8* %31)
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@str = [37 x i8] c"Falha na solicita\C3\A7\C3\A3o de mem\C3\B3ria. \00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(900) i8* @malloc(i32 900)
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = tail call i32 @gets(i8* %1)
%8 = tail call i32 @strlen(i8* %1)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %6
%11 = zext i32 %8 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ %11, %10 ], [ %14, %12 ]
%14 = add nsw i64 %13, -1
%15 = and i64 %14, 4294967295
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = load i8, i8* %16
%18 = tail call i32 @putchar(i8 signext %17)
%19 = icmp ugt i64 %13, 1
br i1 %19, label %12, label %20
20: ; preds = %12, %6
%21 = tail call i32 (...) @getch()
%22 = tail call i32 @free(i8* %1)
ret i32 0
}