#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*/ bzero(char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strstr(char *, char *);
void replace_str(char *content, char *val_name, char *value) {
  char *buffer;
  char *p;
  buffer = (char *)malloc(4096 * sizeof(char));
  do {
    bzero(buffer, 4096);
    if (!(p = strstr(content, val_name)) || 0 == strcmp(val_name, value)) {
      break;
    }
    strcpy(buffer, p + strlen(val_name));
    sprintf(p, "%s%s", value, buffer);
  } while (p);
}


x86 assembly (clang, -O0):
<replace_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x1000,%esi
call   1070 <bzero@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11d6 <replace_str+0x66>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11db <replace_str+0x6b>
jmp    1229 <replace_str+0xb9>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdi
cltq
add    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xde7(%rip),%rsi
call   1080 <sprintf@plt>
cmpq   $0x0,-0x28(%rbp)
jne    1192 <replace_str+0x22>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1000,%esi
call   1070 <bzero@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     1217 <replace_str+0xa7>
mov    %rax,%rbp
lea    0xe48(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1217 <replace_str+0xa7>
mov    %r12,%rdi
call   1040 <strlen@plt>
movslq %eax,%rsi
add    %rbp,%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1070 <bzero@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1090 <strstr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11c0 <replace_str+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
define void @replace_str(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = call i64 @malloc(i32 4096)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %7
br label %11
11: ; preds = %36, %3
%12 = load i8*, i8** %7
%13 = call i32 @bzero(i8* %12, i32 4096)
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = call i8* @strstr(i8* %14, i8* %15)
store i8* %16, i8** %8
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %23
18: ; preds = %11
%19 = load i8*, i8** %5
%20 = load i8*, i8** %6
%21 = call i64 @strcmp(i8* %19, i8* %20)
%22 = icmp eq i64 0, %21
br i1 %22, label %23, label %24
23: ; preds = %18, %11
br label %39
24: ; preds = %18
%25 = load i8*, i8** %7
%26 = load i8*, i8** %8
%27 = load i8*, i8** %5
%28 = call i32 @strlen(i8* %27)
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
%31 = call i32 @strcpy(i8* %25, i8* %30)
%32 = load i8*, i8** %8
%33 = load i8*, i8** %6
%34 = load i8*, i8** %7
%35 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %33, i8* %34)
br label %36
36: ; preds = %24
%37 = load i8*, i8** %8
%38 = icmp ne i8* %37, null
br i1 %38, label %11, label %39
39: ; preds = %36, %23
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
define void @replace_str(i8* %0, i8* %1, i8* %2) {
%4 = tail call i64 @malloc(i32 4096)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @bzero(i8* %5, i32 4096)
%7 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %22, label %9
9: ; preds = %3, %13
%10 = phi i8* [ %20, %13 ], [ %7, %3 ]
%11 = tail call i64 @strcmp(i8* %1, i8* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %9
%14 = tail call i32 @strlen(i8* %1)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %10, i64 %15
%17 = tail call i32 @strcpy(i8* %5, i8* %16)
%18 = tail call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %5)
%19 = tail call i32 @bzero(i8* %5, i32 4096)
%20 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %9
22: ; preds = %9, %13, %3
ret void
}