#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 *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *voltea_string(char *);
int main(void) {
  char s[] = "Campos verdes";
  char *p = (char *)malloc(strlen(s) + 1);
  char *string_duplica;
  char *string_volteado;
  strcpy(p, s);
  string_duplica = duplica_string(p);
  string_volteado = voltea_string(p);
  printf("%s\n", string_duplica);
  printf("%s\n", string_volteado);
  free(string_duplica);
  free(p);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe7a(%rip),%rax
mov    %rax,-0x12(%rbp)
mov    0xe78(%rip),%eax
mov    %eax,-0xa(%rbp)
mov    0xe72(%rip),%ax
mov    %ax,-0x6(%rbp)
lea    -0x12(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x12(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1070 <duplica_string@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1090 <voltea_string@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe25(%rip),%rdi
call   1060 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xe15(%rip),%rdi
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movabs $0x73656472657620,%rax
mov    %rax,0xe(%rsp)
movabs $0x7620736f706d6143,%rax
73 20 76
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1070 <duplica_string@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1090 <voltea_string@plt>
mov    %rax,%r15
lea    0xe34(%rip),%r12
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.s = [14 x i8] c"Campos verdes\00"
@.str = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [14 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i32 0, i32* %1
%6 = bitcast [14 x i8]* %2 to i8*
%7 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%8 = call i64 @strlen(i8* %7)
%9 = add nsw i64 %8, 1
%10 = call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = load i8*, i8** %3
%16 = call i8* @duplica_string(i8* %15)
store i8* %16, i8** %4
%17 = load i8*, i8** %3
%18 = call i8* @voltea_string(i8* %17)
store i8* %18, i8** %5
%19 = load i8*, i8** %4
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %5
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %4
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %3
%26 = call i32 @free(i8* %25)
ret i32 0
}

LLVM IR (-O2):
@__const.main.s = [14 x i8] c"Campos verdes\00"
@.str = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [14 x i8]
%2 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%3 = call i64 @strlen(i8* %2)
%4 = add nsw i64 %3, 1
%5 = tail call i64 @malloc(i64 %4)
%6 = inttoptr i64 %5 to i8*
%7 = call i32 @strcpy(i8* %6, i8* %2)
%8 = call i8* @duplica_string(i8* %6)
%9 = call i8* @voltea_string(i8* %6)
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %8)
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9)
%12 = call i32 @free(i8* %8)
%13 = call i32 @free(i8* %6)
ret i32 0
}