#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 *);
size_t strlen(char *);
int /*<<< orphan*/ system(char *);
int mmain() {
  char name[50];
  char nome_invertido[50];
  int total_array_string = 0, counter = 0;
  printf("\nDigite uma string:\n");
  scanf("%[^\n]%*c", name);
  printf("Agora vamos inverter a string");
  total_array_string = strlen(name) - 1;
  for (counter = 0; name[counter] != '\0'; counter++) {
    nome_invertido[total_array_string] = name[counter];
    total_array_string--;
  }
  nome_invertido[strlen(name)] = '\0';
  printf("O nome invertido eh: %s", nome_invertido);
  printf("\n\n");
  system("PAUSE");
  return 0;
}


x86 assembly (clang, -O0):
<mmain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x84(%rbp)
movl   $0x0,-0x88(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xe9d(%rip),%rdi
call   1060 <scanf@plt>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%rax
mov    %eax,-0x84(%rbp)
movl   $0x0,-0x88(%rbp)
movslq -0x88(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11f6 <mmain+0xb6>
movslq -0x88(%rbp),%rax
mov    -0x40(%rbp,%rax,1),%cl
movslq -0x84(%rbp),%rax
mov    %cl,-0x80(%rbp,%rax,1)
mov    -0x84(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x84(%rbp)
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    11a8 <mmain+0x68>
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rsi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe2c(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmain>:
push   %rbx
sub    $0x80,%rsp
lea    0xee6(%rip),%rdi
call   1030 <puts@plt>
lea    0xe95(%rip),%rdi
lea    0x40(%rsp),%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0xe8a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    0x40(%rsp),%cl
test   %cl,%cl
je     11b4 <mmain+0x64>
lea    0x41(%rsp),%rdx
lea    -0x1(%rax),%esi
xchg   %ax,%ax
movslq %esi,%rsi
mov    %cl,(%rsp,%rsi,1)
movzbl (%rdx),%ecx
add    $0x1,%rdx
add    $0xffffffff,%esi
test   %cl,%cl
jne    11a0 <mmain+0x50>
movb   $0x0,(%rsp,%rax,1)
lea    0xe68(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
lea    0xe63(%rip),%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"\0ADigite uma string:\0A\00"
@.str.1 = [9 x i8] c"%[^\0A]%*c\00"
@.str.2 = [30 x i8] c"Agora vamos inverter a string\00"
@.str.3 = [24 x i8] c"O nome invertido eh: %s\00"
@.str.4 = [3 x i8] c"\0A\0A\00"
@.str.5 = [6 x i8] c"PAUSE\00"
define i32 @mmain() {
%1 = alloca [50 x i8]
%2 = alloca [50 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %3
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%7 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%10 = call i64 @strlen(i8* %9)
%11 = sub i64 %10, 1
%12 = trunc i64 %11 to i32
store i32 %12, i32* %3
store i32 0, i32* %4
br label %13
13: ; preds = %30, %0
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %13
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 %26
store i8 %24, i8* %27
%28 = load i32, i32* %3
%29 = add nsw i32 %28, -1
store i32 %29, i32* %3
br label %30
30: ; preds = %20
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %13
33: ; preds = %13
%34 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%35 = call i64 @strlen(i8* %34)
%36 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 %35
store i8 0, i8* %36
%37 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%40 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"%[^\0A]%*c\00"
@.str.2 = [30 x i8] c"Agora vamos inverter a string\00"
@.str.3 = [24 x i8] c"O nome invertido eh: %s\00"
@.str.5 = [6 x i8] c"PAUSE\00"
@str = [20 x i8] c"\0ADigite uma string:\00"
@str.6 = [2 x i8] c"\0A\00"
define i32 @mmain() {
%1 = alloca [50 x i8]
%2 = alloca [50 x i8]
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%8 = call i64 @strlen(i8* %3)
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 0
br i1 %10, label %24, label %11
11: ; preds = %0
%12 = trunc i64 %8 to i32
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %20, %13 ]
%15 = phi i8 [ %9, %11 ], [ %22, %13 ]
%16 = phi i32 [ %12, %11 ], [ %17, %13 ]
%17 = add i32 %16, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 %18
store i8 %15, i8* %19
%20 = add nuw nsw i64 %14, 1
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %13
24: ; preds = %13, %0
%25 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 %8
store i8 0, i8* %25
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.6, i64 0, i64 0))
%28 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}