#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*/ ft_free(char *);
char *ft_strdup(char *);
char *ft_strjoin(char *, char *);
int ft_strlen(char *);
char *ft_strsub(char *, int, int);
char *insert_a_char(char *result, char *c, int i) {
  char *new;
  char *tmp;
  char *end;
  tmp = ft_strsub(result, 0, i);
  end = ft_strsub(result, i, ft_strlen(result));
  new = ft_strdup(tmp);
  ft_free(tmp);
  tmp = ft_strjoin(new, c);
  ft_free(result);
  result = ft_strjoin(tmp, end);
  ft_free(end);
  ft_free(tmp);
  ft_free(c);
  return (result);
}


x86 assembly (clang, -O0):
<insert_a_char>:
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   1050 <ft_strsub@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    %eax,%edx
call   1050 <ft_strsub@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <ft_strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <ft_free@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <ft_strjoin@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ft_free@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <ft_strjoin@plt>
mov    %rax,-0x8(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <ft_free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <ft_free@plt>
mov    -0x10(%rbp),%rdi
call   1040 <ft_free@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert_a_char>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %esi,%esi
call   1050 <ft_strsub@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <ft_strlen@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1050 <ft_strsub@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1060 <ft_strdup@plt>
mov    %rax,%rbp
mov    %r15,%rdi
call   1040 <ft_free@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1070 <ft_strjoin@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <ft_free@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1070 <ft_strjoin@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1040 <ft_free@plt>
mov    %rbp,%rdi
call   1040 <ft_free@plt>
mov    %r14,%rdi
call   1040 <ft_free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @insert_a_char(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %4
%11 = load i32, i32* %6
%12 = call i8* @ft_strsub(i8* %10, i32 0, i32 %11)
store i8* %12, i8** %8
%13 = load i8*, i8** %4
%14 = load i32, i32* %6
%15 = load i8*, i8** %4
%16 = call i32 @ft_strlen(i8* %15)
%17 = call i8* @ft_strsub(i8* %13, i32 %14, i32 %16)
store i8* %17, i8** %9
%18 = load i8*, i8** %8
%19 = call i8* @ft_strdup(i8* %18)
store i8* %19, i8** %7
%20 = load i8*, i8** %8
%21 = call i32 @ft_free(i8* %20)
%22 = load i8*, i8** %7
%23 = load i8*, i8** %5
%24 = call i8* @ft_strjoin(i8* %22, i8* %23)
store i8* %24, i8** %8
%25 = load i8*, i8** %4
%26 = call i32 @ft_free(i8* %25)
%27 = load i8*, i8** %8
%28 = load i8*, i8** %9
%29 = call i8* @ft_strjoin(i8* %27, i8* %28)
store i8* %29, i8** %4
%30 = load i8*, i8** %9
%31 = call i32 @ft_free(i8* %30)
%32 = load i8*, i8** %8
%33 = call i32 @ft_free(i8* %32)
%34 = load i8*, i8** %5
%35 = call i32 @ft_free(i8* %34)
%36 = load i8*, i8** %4
ret i8* %36
}

LLVM IR (-O2):
define i8* @insert_a_char(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_strdup(i8* %4)
%8 = tail call i32 @ft_free(i8* %4)
%9 = tail call i8* @ft_strjoin(i8* %7, i8* %1)
%10 = tail call i32 @ft_free(i8* %0)
%11 = tail call i8* @ft_strjoin(i8* %9, i8* %6)
%12 = tail call i32 @ft_free(i8* %6)
%13 = tail call i32 @ft_free(i8* %9)
%14 = tail call i32 @ft_free(i8* %1)
ret i8* %11
}