#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 /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
double duracion_insert_over_clasica(int iter, int pos_in, char *destino,
                                    char *origen) {
  int i;
  double time = 0;
  int tam_string_origen = strlen(origen);
  int tam_string_destino = strlen(destino);
  int last_overwrite = pos_in + tam_string_origen;
  for (i = 0; i < iter; i++) {
    tam_string_origen = strlen(origen);
    tam_string_destino = strlen(destino);
    last_overwrite = pos_in + tam_string_origen;
    char *salida =
        malloc((tam_string_origen + tam_string_destino) * sizeof(char));
    get_time();
    strncpy(salida, destino, pos_in);
    strcpy(salida + pos_in, origen);
    if (tam_string_destino > pos_in + tam_string_origen)
      strncpy(salida + last_overwrite, destino + pos_in,
              tam_string_destino - pos_in + 1);
    time += get_time();
    free(salida);
  }
  return time;
}


x86 assembly (clang, -O0):
<duracion_insert_over_clasica>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1277 <duracion_insert_over_clasica+0x117>
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
add    -0x30(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1070 <get_time@plt>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x40(%rbp),%rdi
movslq -0x8(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x30(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    -0x2c(%rbp),%ecx
cmp    %ecx,%eax
jle    124a <duracion_insert_over_clasica+0xea>
mov    -0x40(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x8(%rbp),%rax
add    %rax,%rsi
mov    -0x30(%rbp),%edx
sub    -0x8(%rbp),%edx
add    $0x1,%edx
call   1040 <strncpy@plt>
mov    $0x0,%al
call   1070 <get_time@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a6 <duracion_insert_over_clasica+0x46>
movsd  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<duracion_insert_over_clasica>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%ebp
mov    %rcx,0x30(%rsp)
mov    %rcx,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
test   %ebp,%ebp
jle    1274 <duracion_insert_over_clasica+0x114>
movslq %r14d,%rax
mov    %rbx,0x28(%rsp)
lea    (%rbx,%rax,1),%rcx
mov    %rcx,0x18(%rsp)
mov    $0x1,%ecx
mov    %rax,0x20(%rsp)
sub    %eax,%ecx
mov    %ecx,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    0x30(%rsp),%r15
mov    0x28(%rsp),%r13
jmp    1200 <duracion_insert_over_clasica+0xa0>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <get_time@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x14(%rsp),%ebp
add    $0xffffffff,%ebp
je     127e <duracion_insert_over_clasica+0x11e>
mov    %ebp,0x14(%rsp)
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %eax,%r14d
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%r12d
lea    (%r12,%r14,1),%edi
mov    0x20(%rsp),%rbp
add    %ebp,%r14d
call   1080 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1070 <get_time@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1040 <strncpy@plt>
lea    (%rbx,%rbp,1),%rdi
mov    %r15,%rsi
call   1050 <strcpy@plt>
cmp    %r14d,%r12d
jle    11d0 <duracion_insert_over_clasica+0x70>
movslq %r14d,%rdi
add    %rbx,%rdi
add    0x10(%rsp),%r12d
mov    0x18(%rsp),%rsi
mov    %r12d,%edx
call   1040 <strncpy@plt>
jmp    11d0 <duracion_insert_over_clasica+0x70>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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