#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*/ PrintSubTitles(char *);
int /*<<< orphan*/ PrintTitles(char *);
char *duplica_string(char *);
int /*<<< orphan*/ free(char *);
char *malloc(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strlen(char *);
char *voltea_string(char *);
int main(void) {
  char *s = "Campos verdes";
  char *s_duplicado = malloc(strlen(s));
  char *s_volteado = malloc(strlen(s_duplicado));
  PrintTitles(" Tarea 04 - Ejercicio 4");
  PrintSubTitles("Inciso a - Duplicado");
  s_duplicado = duplica_string(s);
  s_volteado = voltea_string(s);
  printf("%s\n", s_duplicado);
  PrintSubTitles("Inciso b - Volteado");
  printf("%s\n", s_volteado);
  free(s_duplicado);
  free(s_volteado);
  PrintTitles(" By Gabs");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xe45(%rip),%rdi
call   1090 <PrintTitles@plt>
lea    0xe51(%rip),%rdi
call   1050 <PrintSubTitles@plt>
mov    -0x10(%rbp),%rdi
call   1070 <duplica_string@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <voltea_string@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe3c(%rip),%rdi
call   1060 <printf@plt>
lea    0xe34(%rip),%rdi
call   1050 <PrintSubTitles@plt>
mov    -0x20(%rbp),%rsi
lea    0xe20(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
lea    0xe1a(%rip),%rdi
call   1090 <PrintTitles@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xe74(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0xe64(%rip),%rdi
call   1090 <PrintTitles@plt>
lea    0xe70(%rip),%rdi
call   1050 <PrintSubTitles@plt>
mov    %r14,%rdi
call   1070 <duplica_string@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   10a0 <voltea_string@plt>
mov    %rax,%rbx
lea    0xe63(%rip),%r14
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <printf@plt>
lea    0xe55(%rip),%rdi
call   1050 <PrintSubTitles@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe42(%rip),%rdi
call   1090 <PrintTitles@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Campos verdes\00"
@.str.1 = [24 x i8] c" Tarea 04 - Ejercicio 4\00"
@.str.2 = [21 x i8] c"Inciso a - Duplicado\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [20 x i8] c"Inciso b - Volteado\00"
@.str.5 = [9 x i8] c" By Gabs\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = call i8* @malloc(i32 %6)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %4
%11 = call i32 @PrintTitles(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @PrintSubTitles(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%13 = load i8*, i8** %2
%14 = call i8* @duplica_string(i8* %13)
store i8* %14, i8** %3
%15 = load i8*, i8** %2
%16 = call i8* @voltea_string(i8* %15)
store i8* %16, i8** %4
%17 = load i8*, i8** %3
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%19 = call i32 @PrintSubTitles(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%20 = load i8*, i8** %4
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %3
%23 = call i32 @free(i8* %22)
%24 = load i8*, i8** %4
%25 = call i32 @free(i8* %24)
%26 = call i32 @PrintTitles(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"Campos verdes\00"
@.str.1 = [24 x i8] c" Tarea 04 - Ejercicio 4\00"
@.str.2 = [21 x i8] c"Inciso a - Duplicado\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [20 x i8] c"Inciso b - Volteado\00"
@.str.5 = [9 x i8] c" By Gabs\00"
define i32 @main() {
%1 = tail call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%2 = tail call i8* @malloc(i32 %1)
%3 = tail call i32 @strlen(i8* %2)
%4 = tail call i32 @PrintTitles(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @PrintSubTitles(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i8* @duplica_string(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%7 = tail call i8* @voltea_string(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%9 = tail call i32 @PrintSubTitles(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%10 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%11 = tail call i32 @free(i8* %6)
%12 = tail call i32 @free(i8* %7)
%13 = tail call i32 @PrintTitles(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}