#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();
char *malloc(int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
double duracion_insertado_clasico(int iter, int pos_in, char *destino,
                                  char *origen) {
  int i, j, tam = 0;
  int time = 0;
  int tam_dest = strlen(destino), tam_src = strlen(origen);
  for (i = 0; i < iter; i++) {
    char *string = malloc((tam_dest + tam_src) * sizeof(char));
    get_time();
    strncpy(string, destino, pos_in);
    strncpy(string + pos_in, origen, tam_src);
    strncpy(string + pos_in + tam_src, destino + pos_in, tam_dest - pos_in + 1);
    time += get_time();
    free(string);
  }
  return time;
}


x86 assembly (clang, -O0):
<duracion_insertado_clasico>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    123a <duracion_insertado_clasico+0xea>
mov    -0x2c(%rbp),%eax
add    -0x30(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1060 <get_time@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x38(%rbp),%rdi
movslq -0x8(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x38(%rbp),%rdi
movslq -0x8(%rbp),%rax
add    %rax,%rdi
movslq -0x30(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x8(%rbp),%rax
add    %rax,%rsi
mov    -0x2c(%rbp),%edx
sub    -0x8(%rbp),%edx
add    $0x1,%edx
call   1040 <strncpy@plt>
mov    $0x0,%al
call   1060 <get_time@plt>
mov    %rax,%rcx
movslq -0x28(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1193 <duracion_insertado_clasico+0x43>
cvtsi2sdl -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<duracion_insertado_clasico>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r12
mov    %esi,%ebx
mov    %edi,%ebp
mov    %rdx,0x10(%rsp)
mov    %rdx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,0x4(%rsp)
test   %ebp,%ebp
jle    1229 <duracion_insertado_clasico+0xd9>
movslq %ebx,%rbx
mov    0x4(%rsp),%eax
movslq %eax,%rcx
mov    %rcx,0x20(%rsp)
add    %r14d,%eax
mov    %eax,0x8(%rsp)
mov    0x10(%rsp),%rax
add    %rbx,%rax
mov    %rax,0x18(%rsp)
sub    %ebx,%r14d
add    $0x1,%r14d
mov    %r14d,0xc(%rsp)
xor    %r13d,%r13d
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%edi
call   1070 <malloc@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1060 <get_time@plt>
mov    %r14,%rdi
mov    0x10(%rsp),%rsi
mov    %ebx,%edx
call   1040 <strncpy@plt>
lea    (%r14,%rbx,1),%r15
mov    %r15,%rdi
mov    %r12,%rsi
mov    0x4(%rsp),%edx
call   1040 <strncpy@plt>
add    0x20(%rsp),%r15
mov    %r15,%rdi
mov    0x18(%rsp),%rsi
mov    0xc(%rsp),%edx
call   1040 <strncpy@plt>
xor    %eax,%eax
call   1060 <get_time@plt>
add    %eax,%r13d
mov    %r14,%rdi
call   1030 <free@plt>
add    $0xffffffff,%ebp
jne    11c0 <duracion_insertado_clasico+0x70>
cvtsi2sd %r13d,%xmm0
jmp    122d <duracion_insertado_clasico+0xdd>
xorpd  %xmm0,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @duracion_insertado_clasico(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i32 0, i32* %11
store i32 0, i32* %12
%16 = load i8*, i8** %7
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %13
%18 = load i8*, i8** %8
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %14
store i32 0, i32* %9
br label %20
20: ; preds = %67, %4
%21 = load i32, i32* %9
%22 = load i32, i32* %5
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %70
24: ; preds = %20
%25 = load i32, i32* %13
%26 = load i32, i32* %14
%27 = add nsw i32 %25, %26
%28 = sext i32 %27 to i64
%29 = mul i64 %28, 1
%30 = trunc i64 %29 to i32
%31 = call i8* @malloc(i32 %30)
store i8* %31, i8** %15
%32 = call i64 (...) @get_time()
%33 = load i8*, i8** %15
%34 = load i8*, i8** %7
%35 = load i32, i32* %6
%36 = call i32 @strncpy(i8* %33, i8* %34, i32 %35)
%37 = load i8*, i8** %15
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8*, i8** %8
%42 = load i32, i32* %14
%43 = call i32 @strncpy(i8* %40, i8* %41, i32 %42)
%44 = load i8*, i8** %15
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i32, i32* %14
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = load i8*, i8** %7
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i32, i32* %13
%56 = load i32, i32* %6
%57 = sub nsw i32 %55, %56
%58 = add nsw i32 %57, 1
%59 = call i32 @strncpy(i8* %50, i8* %54, i32 %58)
%60 = call i64 (...) @get_time()
%61 = load i32, i32* %12
%62 = sext i32 %61 to i64
%63 = add nsw i64 %62, %60
%64 = trunc i64 %63 to i32
store i32 %64, i32* %12
%65 = load i8*, i8** %15
%66 = call i32 @free(i8* %65)
br label %67
67: ; preds = %24
%68 = load i32, i32* %9
%69 = add nsw i32 %68, 1
store i32 %69, i32* %9
br label %20
70: ; preds = %20
%71 = load i32, i32* %12
%72 = sitofp i32 %71 to double
ret double %72
}

LLVM IR (-O2):
define double @duracion_insertado_clasico(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = tail call i32 @strlen(i8* %2)
%6 = tail call i32 @strlen(i8* %3)
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %33
8: ; preds = %4
%9 = add nsw i32 %6, %5
%10 = sext i32 %1 to i64
%11 = sext i32 %6 to i64
%12 = getelementptr inbounds i8, i8* %2, i64 %10
%13 = sub i32 1, %1
%14 = add i32 %13, %5
br label %15
15: ; preds = %8, %15
%16 = phi i32 [ 0, %8 ], [ %29, %15 ]
%17 = phi i32 [ 0, %8 ], [ %27, %15 ]
%18 = tail call i8* @malloc(i32 %9)
%19 = tail call i64 (...) @get_time()
%20 = tail call i32 @strncpy(i8* %18, i8* %2, i32 %1)
%21 = getelementptr inbounds i8, i8* %18, i64 %10
%22 = tail call i32 @strncpy(i8* %21, i8* %3, i32 %6)
%23 = getelementptr inbounds i8, i8* %21, i64 %11
%24 = tail call i32 @strncpy(i8* %23, i8* %12, i32 %14)
%25 = tail call i64 (...) @get_time()
%26 = trunc i64 %25 to i32
%27 = add i32 %17, %26
%28 = tail call i32 @free(i8* %18)
%29 = add nuw nsw i32 %16, 1
%30 = icmp eq i32 %29, %0
br i1 %30, label %31, label %15
31: ; preds = %15
%32 = sitofp i32 %27 to double
br label %33
33: ; preds = %31, %4
%34 = phi double [ 0.000000e+00, %4 ], [ %32, %31 ]
ret double %34
}