#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 *);
char *malloc(int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *insertado(int tam_dest, int tam_src, int pos_in, char *destino,
                char *origen) {
  char *string = malloc((tam_dest + tam_src) * sizeof(char));
  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);
  free(string);
}


x86 assembly (clang, -O0):
<insertado>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x30(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x30(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    -0xc(%rbp),%edx
sub    -0x14(%rbp),%edx
add    $0x1,%edx
call   1040 <strncpy@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insertado>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,(%rsp)
mov    %rcx,%r14
mov    %edx,%r13d
mov    %esi,%r12d
mov    %edi,%ebx
lea    (%r12,%rbx,1),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r13d,%edx
call   1040 <strncpy@plt>
movslq %r13d,%rbp
lea    (%r15,%rbp,1),%r13
mov    %r13,%rdi
mov    (%rsp),%rsi
mov    %r12d,%edx
call   1040 <strncpy@plt>
movslq %r12d,%rdi
add    %r13,%rdi
add    %rbp,%r14
sub    %ebp,%ebx
add    $0x1,%ebx
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <strncpy@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define i8* @insertado(i32 %0, i32 %1, i32 %2, i8* %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%13 = load i32, i32* %7
%14 = load i32, i32* %8
%15 = add nsw i32 %13, %14
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 1
%18 = trunc i64 %17 to i32
%19 = call i8* @malloc(i32 %18)
store i8* %19, i8** %12
%20 = load i8*, i8** %12
%21 = load i8*, i8** %10
%22 = load i32, i32* %9
%23 = call i32 @strncpy(i8* %20, i8* %21, i32 %22)
%24 = load i8*, i8** %12
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8*, i8** %11
%29 = load i32, i32* %8
%30 = call i32 @strncpy(i8* %27, i8* %28, i32 %29)
%31 = load i8*, i8** %12
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8*, i8** %10
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i32, i32* %7
%43 = load i32, i32* %9
%44 = sub nsw i32 %42, %43
%45 = add nsw i32 %44, 1
%46 = call i32 @strncpy(i8* %37, i8* %41, i32 %45)
%47 = load i8*, i8** %12
%48 = call i32 @free(i8* %47)
%49 = load i8*, i8** %6
ret i8* %49
}

LLVM IR (-O2):
define noalias i8* @insertado(i32 %0, i32 %1, i32 %2, i8* %3, i8* %4) {
%6 = add nsw i32 %1, %0
%7 = tail call i8* @malloc(i32 %6)
%8 = tail call i32 @strncpy(i8* %7, i8* %3, i32 %2)
%9 = sext i32 %2 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = tail call i32 @strncpy(i8* %10, i8* %4, i32 %1)
%12 = sext i32 %1 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = getelementptr inbounds i8, i8* %3, i64 %9
%15 = add i32 %0, 1
%16 = sub i32 %15, %2
%17 = tail call i32 @strncpy(i8* %13, i8* %14, i32 %16)
%18 = tail call i32 @free(i8* %7)
ret i8* undef
}