#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char **);
int main() {
  int i, tam = 0;
  char string[10];
  printf("Digite uma frase\n");
  scanf("%[^\n]s", &string);
  for (i = 0; string[i] != '\0'; i++) {
    tam++;
  }
  for (i = tam - 1; i >= 0; i--) {
    printf("%c", string[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x16(%rbp),%rsi
lea    0xec3(%rip),%rdi
call   1040 <scanf@plt>
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rax
movsbl -0x16(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     1184 <main+0x64>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115b <main+0x3b>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11bc <main+0x9c>
movslq -0x8(%rbp),%rax
movsbl -0x16(%rbp,%rax,1),%esi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    118d <main+0x6d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xecb(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb8(%rip),%rdi
lea    0x6(%rsp),%rsi
call   1050 <scanf@plt>
cmpb   $0x0,0x6(%rsp)
je     1194 <main+0x64>
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,0x7(%rsp,%rax,1)
lea    0x1(%rax),%rax
jne    1160 <main+0x30>
test   %eax,%eax
jle    1194 <main+0x64>
mov    %eax,%ebx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl 0x4(%rsp,%rbx,1),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1180 <main+0x50>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str.1 = [7 x i8] c"%[^\0A]s\00"
@str = [17 x i8] c"Digite uma frase\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%4 = bitcast [10 x i8]* %1 to i8**
%5 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %4)
%6 = load i8, i8* %2
%7 = icmp eq i8 %6, 0
br i1 %7, label %27, label %13
8: ; preds = %13
%9 = trunc i64 %15 to i32
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = and i64 %15, 4294967295
br label %19
13: ; preds = %0, %13
%14 = phi i64 [ %15, %13 ], [ 0, %0 ]
%15 = add nuw nsw i64 %14, 1
%16 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %8, label %13
19: ; preds = %11, %19
%20 = phi i64 [ %12, %11 ], [ %21, %19 ]
%21 = add nsw i64 %20, -1
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = call i32 @putchar(i32 %24)
%26 = icmp ugt i64 %20, 1
br i1 %26, label %19, label %27
27: ; preds = %19, %0, %8
ret i32 0
}