#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*/ free(char *);
scalar_t__ get_time();
scalar_t__ malloc(int);
char *strdup(char *);
int strlen(char *);
double duracion_str_dup_clasico(int iter, char *origen) {
  int i;
  double time = 0;
  int tam_src = strlen(origen);
  for (i = 0; i < iter; i++) {
    char *temp = (char *)malloc(tam_src * sizeof(char));
    get_time();
    temp = strdup(origen);
    time += get_time();
    free(temp);
  }
  return time;
}


x86 assembly (clang, -O0):
<duracion_str_dup_clasico>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11da <duracion_str_dup_clasico+0x8a>
movslq -0x24(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1050 <get_time@plt>
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1050 <get_time@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117a <duracion_str_dup_clasico+0x2a>
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<duracion_str_dup_clasico>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
mov    %rsi,%rdi
call   1040 <strlen@plt>
test   %ebp,%ebp
jle    11c6 <duracion_str_dup_clasico+0x76>
mov    %eax,%r15d
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15d,%edi
call   1060 <malloc@plt>
xor    %eax,%eax
call   1050 <get_time@plt>
mov    %r14,%rdi
call   1070 <strdup@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <get_time@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0xffffffff,%ebp
jne    1180 <duracion_str_dup_clasico+0x30>
jmp    11cf <duracion_str_dup_clasico+0x7f>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
movsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @duracion_str_dup_clasico(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
store double 0.000000e+00, double* %6
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %7
store i32 0, i32* %5
br label %11
11: ; preds = %31, %2
%12 = load i32, i32* %5
%13 = load i32, i32* %3
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %34
15: ; preds = %11
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 1
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %8
%22 = call i64 (...) @get_time()
%23 = load i8*, i8** %4
%24 = call i8* @strdup(i8* %23)
store i8* %24, i8** %8
%25 = call i64 (...) @get_time()
%26 = sitofp i64 %25 to double
%27 = load double, double* %6
%28 = fadd double %27, %26
store double %28, double* %6
%29 = load i8*, i8** %8
%30 = call i32 @free(i8* %29)
br label %31
31: ; preds = %15
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %11
34: ; preds = %11
%35 = load double, double* %6
ret double %35
}

LLVM IR (-O2):
define double @duracion_str_dup_clasico(i32 %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %17
5: ; preds = %2, %5
%6 = phi i32 [ %15, %5 ], [ 0, %2 ]
%7 = phi double [ %13, %5 ], [ 0.000000e+00, %2 ]
%8 = tail call i64 @malloc(i32 %3)
%9 = tail call i64 (...) @get_time()
%10 = tail call i8* @strdup(i8* %1)
%11 = tail call i64 (...) @get_time()
%12 = sitofp i64 %11 to double
%13 = fadd double %7, %12
%14 = tail call i32 @free(i8* %10)
%15 = add nuw nsw i32 %6, 1
%16 = icmp eq i32 %15, %0
br i1 %16, label %17, label %5
17: ; preds = %5, %2
%18 = phi double [ 0.000000e+00, %2 ], [ %13, %5 ]
ret double %18
}