#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*/ printf(char *, ...);
int replacStrAtNew(char **, char **, char *, int);
int main(int argc, const char *argv[]) {
  if (argc == 1) {
    printf("replace <Quark File Path>\n");
  }
  char *qfilepath = (char *)argv[1];
  int count = 3;
  char *org_list[3];
  char *new_list[3];
  org_list[0] = "coamorous";
  org_list[1] = "MG_7556";
  org_list[2] = "copy";
  new_list[0] = "coamor123";
  new_list[1] = "MG_2014";
  new_list[2] = "move";
  int ret = replacStrAtNew(org_list, new_list, qfilepath, count);
  if (ret >= 0) {
    printf("replace successfully.\n");
    printf("replace result : %d item(s) replaced\n", ret);
  } else {
    printf("error code : %d", ret);
  }
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    114e <main+0x2e>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x3,-0x1c(%rbp)
lea    0xeb3(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xeb2(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xeaf(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xea9(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xea8(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xea5(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1040 <replacStrAtNew@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jl     11e8 <main+0xc8>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x64(%rbp),%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f9 <main+0xd9>
mov    -0x64(%rbp),%esi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x64(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jne    1149 <main+0x19>
lea    0xf36(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%rdx
lea    0xeac(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xeaa(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xea6(%rip),%rax
mov    %rax,0x30(%rsp)
lea    0xe9f(%rip),%rax
mov    %rax,(%rsp)
lea    0xe9e(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xe9a(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0x20(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x3,%ecx
call   1050 <replacStrAtNew@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11c1 <main+0x91>
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6f(%rip),%rdi
jmp    11c8 <main+0x98>
lea    0xe8c(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [27 x i8] c"replace <Quark File Path>\0A\00"
@.str.1 = [10 x i8] c"coamorous\00"
@.str.2 = [8 x i8] c"MG_7556\00"
@.str.3 = [5 x i8] c"copy\00"
@.str.4 = [10 x i8] c"coamor123\00"
@.str.5 = [8 x i8] c"MG_2014\00"
@.str.6 = [5 x i8] c"move\00"
@.str.7 = [23 x i8] c"replace successfully.\0A\00"
@.str.8 = [38 x i8] c"replace result : %d item(s) replaced\0A\00"
@.str.9 = [16 x i8] c"error code : %d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [3 x i8*]
%9 = alloca [3 x i8*]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %6
store i32 3, i32* %7
%19 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %19
%20 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %20
%21 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %21
%22 = getelementptr inbounds [3 x i8*], [3 x i8*]* %9, i64 0, i64 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8** %22
%23 = getelementptr inbounds [3 x i8*], [3 x i8*]* %9, i64 0, i64 1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %23
%24 = getelementptr inbounds [3 x i8*], [3 x i8*]* %9, i64 0, i64 2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8** %24
%25 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
%26 = getelementptr inbounds [3 x i8*], [3 x i8*]* %9, i64 0, i64 0
%27 = load i8*, i8** %6
%28 = load i32, i32* %7
%29 = call i32 @replacStrAtNew(i8** %25, i8** %26, i8* %27, i32 %28)
store i32 %29, i32* %10
%30 = load i32, i32* %10
%31 = icmp sge i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %15
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%34 = load i32, i32* %10
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i32 %34)
br label %39
36: ; preds = %15
%37 = load i32, i32* %10
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %36, %32
%40 = load i32, i32* %10
ret i32 %40
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"coamorous\00"
@.str.2 = [8 x i8] c"MG_7556\00"
@.str.3 = [5 x i8] c"copy\00"
@.str.4 = [10 x i8] c"coamor123\00"
@.str.5 = [8 x i8] c"MG_2014\00"
@.str.6 = [5 x i8] c"move\00"
@.str.8 = [38 x i8] c"replace result : %d item(s) replaced\0A\00"
@.str.9 = [16 x i8] c"error code : %d\00"
@str = [22 x i8] c"replace successfully.\00"
@str.10 = [26 x i8] c"replace <Quark File Path>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [3 x i8*]
%4 = alloca [3 x i8*]
%5 = icmp eq i32 %0, 1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.10, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = bitcast [3 x i8*]* %3 to i8*
%12 = bitcast [3 x i8*]* %4 to i8*
%13 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %14
%15 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %15
%16 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8** %16
%17 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %17
%18 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8** %18
%19 = call i32 @replacStrAtNew(i8** %13, i8** %16, i8* %10, i32 3)
%20 = icmp sgt i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %8
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %23
23: ; preds = %8, %21
%24 = phi i8* [ getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), %21 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), %8 ]
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %24, i32 %19)
ret i32 %19
}