#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 *ft_strfjoin(char *, char *, int, int);
int ft_strlen(char *);
char *ft_strsub(char *, int, int);
char *ft_strinsert(char *a, char *b, int pos) {
  char *s1;
  char *s2;
  s1 = ft_strsub(a, 0, pos);
  s2 = ft_strsub(a, pos, ft_strlen(a));
  s1 = ft_strfjoin(s1, b, 1, 0);
  s1 = ft_strfjoin(s1, s2, 1, 1);
  return (s1);
}


x86 assembly (clang, -O0):
<ft_strinsert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1040 <ft_strsub@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    %eax,%edx
call   1040 <ft_strsub@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1050 <ft_strfjoin@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x1,%ecx
mov    %ecx,%edx
call   1050 <ft_strfjoin@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_strinsert>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %esi,%esi
call   1040 <ft_strsub@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <ft_strlen@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <ft_strsub@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1050 <ft_strfjoin@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    $0x1,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <ft_strfjoin@plt>

LLVM IR (-O0):
define i8* @ft_strinsert(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = load i32, i32* %6
%11 = call i8* @ft_strsub(i8* %9, i32 0, i32 %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %4
%13 = load i32, i32* %6
%14 = load i8*, i8** %4
%15 = call i32 @ft_strlen(i8* %14)
%16 = call i8* @ft_strsub(i8* %12, i32 %13, i32 %15)
store i8* %16, i8** %8
%17 = load i8*, i8** %7
%18 = load i8*, i8** %5
%19 = call i8* @ft_strfjoin(i8* %17, i8* %18, i32 1, i32 0)
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = load i8*, i8** %8
%22 = call i8* @ft_strfjoin(i8* %20, i8* %21, i32 1, i32 1)
store i8* %22, i8** %7
%23 = load i8*, i8** %7
ret i8* %23
}

LLVM IR (-O2):
define i8* @ft_strinsert(i8* %0, i8* %1, i32 %2) {
%4 = tail call i8* @ft_strsub(i8* %0, i32 0, i32 %2)
%5 = tail call i32 @ft_strlen(i8* %0)
%6 = tail call i8* @ft_strsub(i8* %0, i32 %2, i32 %5)
%7 = tail call i8* @ft_strfjoin(i8* %4, i8* %1, i32 1, i32 0)
%8 = tail call i8* @ft_strfjoin(i8* %7, i8* %6, i32 1, i32 1)
ret i8* %8
}