#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 */
char *duplica_string(char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int /*<<< orphan*/ voltea_string(char *);
int main(void) {
  char *s;
  char *s_duplicado;
  s = malloc(sizeof(char) * strlen(s));
  printf("Enter tu string (los espacios deben ser representado por _ ) : ");
  scanf("%s", s);
  printf("\n----Duplicado----\n\n ");
  s_duplicado = duplica_string(s);
  printf("%s\n", s_duplicado);
  printf("\n");
  printf("----Volteado----\n\n");
  voltea_string(s);
  printf("\n");
  free(s_duplicado);
  free(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe8e(%rip),%rdi
call   1080 <scanf@plt>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <duplica_string@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1090 <voltea_string@plt>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
call   1060 <strlen@plt>
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
lea    0xe56(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe88(%rip),%rdi
mov    %rbx,%rsi
call   10a0 <scanf@plt>
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1080 <duplica_string@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xe67(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   10b0 <voltea_string@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [64 x i8] c"Enter tu string (los espacios deben ser representado por _ ) : \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [22 x i8] c"\0A----Duplicado----\0A\0A \00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [19 x i8] c"----Volteado----\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
%6 = sext i32 %5 to i64
%7 = mul i64 1, %6
%8 = trunc i64 %7 to i32
%9 = call i8* @malloc(i32 %8)
store i8* %9, i8** %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %2
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%14 = load i8*, i8** %2
%15 = call i8* @duplica_string(i8* %14)
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%20 = load i8*, i8** %2
%21 = call i32 @voltea_string(i8* %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%23 = load i8*, i8** %3
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %2
%26 = call i32 @free(i8* %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [64 x i8] c"Enter tu string (los espacios deben ser representado por _ ) : \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [22 x i8] c"\0A----Duplicado----\0A\0A \00"
@str = [18 x i8] c"----Volteado----\0A\00"
define i32 @main() {
%1 = tail call i32 @strlen(i8* undef)
%2 = tail call i8* @malloc(i32 %1)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i8* @duplica_string(i8* %2)
%7 = tail call i32 @puts(i8* dereferenceable(1) %6)
%8 = tail call i32 @putchar(i32 10)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @voltea_string(i8* %2)
%11 = tail call i32 @putchar(i32 10)
%12 = tail call i32 @free(i8* %6)
%13 = tail call i32 @free(i8* %2)
ret i32 0
}