#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__ malloc(int);
char *realloc(char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void remplace_partie_string(char **chaine, char *debut, char *fin,
                            char *chaine_de_remplacement) {
  char *premiere_partie, *seconde_partie;
  premiere_partie = (char *)malloc(sizeof(char) * (strlen(*chaine) + 1));
  seconde_partie = (char *)malloc(sizeof(char) * (strlen(*chaine) + 1));
  strcpy(premiere_partie, *chaine);
  premiere_partie[strlen(*chaine) - strlen(debut)] = 0;
  strcpy(seconde_partie, &(fin[1]));
  *chaine = realloc(*chaine, sizeof(char) * (strlen(premiere_partie) +
                                             strlen(chaine_de_remplacement) +
                                             strlen(seconde_partie) + 1));
  (*chaine)[0] = 0;
  strcat(*chaine, premiere_partie);
  strcat(*chaine, chaine_de_remplacement);
  strcat(*chaine, seconde_partie);
  free(premiere_partie);
  free(seconde_partie);
}


x86 assembly (clang, -O0):
<remplace_partie_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x54(%rbp),%ecx
mov    %eax,%edx
mov    -0x50(%rbp),%rax
sub    %edx,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remplace_partie_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x10(%rsp)
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    (%rdi),%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    (%rbx),%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    (%rbx),%rsi
mov    %r15,%rdi
call   1040 <strcpy@plt>
mov    (%rbx),%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1050 <strlen@plt>
sub    %eax,%r14d
movslq %r14d,%rax
movb   $0x0,(%r15,%rax,1)
add    $0x1,%r13
mov    %r12,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    (%rbx),%rax
mov    %rax,0x8(%rsp)
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%r13d
mov    0x10(%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1050 <strlen@plt>
add    %r13d,%ebp
lea    (%rax,%rbp,1),%esi
add    $0x1,%esi
mov    0x8(%rsp),%rdi
call   1070 <realloc@plt>
mov    %rax,(%rbx)
movb   $0x0,(%rax)
mov    (%rbx),%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
mov    (%rbx),%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    (%rbx),%rdi
mov    %r12,%rsi
call   1080 <strcat@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @remplace_partie_string(i8** %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%11 = load i8**, i8*** %5
%12 = load i8*, i8** %11
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = mul i64 1, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %9
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %20
%22 = call i32 @strlen(i8* %21)
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = mul i64 1, %24
%26 = trunc i64 %25 to i32
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %10
%29 = load i8*, i8** %9
%30 = load i8**, i8*** %5
%31 = load i8*, i8** %30
%32 = call i32 @strcpy(i8* %29, i8* %31)
%33 = load i8*, i8** %9
%34 = load i8**, i8*** %5
%35 = load i8*, i8** %34
%36 = call i32 @strlen(i8* %35)
%37 = load i8*, i8** %6
%38 = call i32 @strlen(i8* %37)
%39 = sub nsw i32 %36, %38
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %33, i64 %40
store i8 0, i8* %41
%42 = load i8*, i8** %10
%43 = load i8*, i8** %7
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = call i32 @strcpy(i8* %42, i8* %44)
%46 = load i8**, i8*** %5
%47 = load i8*, i8** %46
%48 = load i8*, i8** %9
%49 = call i32 @strlen(i8* %48)
%50 = load i8*, i8** %8
%51 = call i32 @strlen(i8* %50)
%52 = add nsw i32 %49, %51
%53 = load i8*, i8** %10
%54 = call i32 @strlen(i8* %53)
%55 = add nsw i32 %52, %54
%56 = add nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = mul i64 1, %57
%59 = trunc i64 %58 to i32
%60 = call i8* @realloc(i8* %47, i32 %59)
%61 = load i8**, i8*** %5
store i8* %60, i8** %61
%62 = load i8**, i8*** %5
%63 = load i8*, i8** %62
%64 = getelementptr inbounds i8, i8* %63, i64 0
store i8 0, i8* %64
%65 = load i8**, i8*** %5
%66 = load i8*, i8** %65
%67 = load i8*, i8** %9
%68 = call i32 @strcat(i8* %66, i8* %67)
%69 = load i8**, i8*** %5
%70 = load i8*, i8** %69
%71 = load i8*, i8** %8
%72 = call i32 @strcat(i8* %70, i8* %71)
%73 = load i8**, i8*** %5
%74 = load i8*, i8** %73
%75 = load i8*, i8** %10
%76 = call i32 @strcat(i8* %74, i8* %75)
%77 = load i8*, i8** %9
%78 = call i32 @free(i8* %77)
%79 = load i8*, i8** %10
%80 = call i32 @free(i8* %79)
ret void
}

LLVM IR (-O2):
define void @remplace_partie_string(i8** nocapture %0, i8* %1, i8* %2, i8* %3) {
%5 = load i8*, i8** %0
%6 = tail call i32 @strlen(i8* %5)
%7 = add nsw i32 %6, 1
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = load i8*, i8** %0
%11 = tail call i32 @strlen(i8* %10)
%12 = add nsw i32 %11, 1
%13 = tail call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
%15 = load i8*, i8** %0
%16 = tail call i32 @strcpy(i8* %9, i8* %15)
%17 = load i8*, i8** %0
%18 = tail call i32 @strlen(i8* %17)
%19 = tail call i32 @strlen(i8* %1)
%20 = sub nsw i32 %18, %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %9, i64 %21
store i8 0, i8* %22
%23 = getelementptr inbounds i8, i8* %2, i64 1
%24 = tail call i32 @strcpy(i8* %14, i8* %23)
%25 = load i8*, i8** %0
%26 = tail call i32 @strlen(i8* %9)
%27 = tail call i32 @strlen(i8* %3)
%28 = tail call i32 @strlen(i8* %14)
%29 = add i32 %26, 1
%30 = add i32 %29, %27
%31 = add i32 %30, %28
%32 = tail call i8* @realloc(i8* %25, i32 %31)
store i8* %32, i8** %0
store i8 0, i8* %32
%33 = load i8*, i8** %0
%34 = tail call i32 @strcat(i8* %33, i8* %9)
%35 = load i8*, i8** %0
%36 = tail call i32 @strcat(i8* %35, i8* %3)
%37 = load i8*, i8** %0
%38 = tail call i32 @strcat(i8* %37, i8* %14)
%39 = tail call i32 @free(i8* %9)
%40 = tail call i32 @free(i8* %14)
ret void
}