#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 *);
int /*<<< orphan*/ printf(char *, ...);
char *zmWordsReplace(char *, char *, char *);
int main(int argc, const char *argv[]) {
  if (argc != 4) {
    printf("Arguments error.For example:./zmreplacewords \"This is test "
           "cases.\" is are\n");
    return 0;
  }
  char *rawString = (char *)argv[1];
  char *old = (char *)argv[2];
  char *new = (char *)argv[3];
  char *newString = zmWordsReplace(rawString, old, new);
  char *retString = newString;
  printf("%s\n", retString);
  if (rawString != retString) {
    free(retString);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     116a <main+0x3a>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11db <main+0xab>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <zmWordsReplace@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
cmp    -0x38(%rbp),%rax
je     11d4 <main+0xa4>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x4,%edi
jne    116a <main+0x3a>
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rax
mov    0x18(%rsi),%rdx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <zmWordsReplace@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <puts@plt>
cmp    %rbx,%r14
je     1176 <main+0x46>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1176 <main+0x46>
lea    0xe8f(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [75 x i8] c"Arguments error.For example:./zmreplacewords \22This is test cases.\22 is are\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 4
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %39
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
store i8* %21, i8** %7
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 3
%24 = load i8*, i8** %23
store i8* %24, i8** %8
%25 = load i8*, i8** %6
%26 = load i8*, i8** %7
%27 = load i8*, i8** %8
%28 = call i8* @zmWordsReplace(i8* %25, i8* %26, i8* %27)
store i8* %28, i8** %9
%29 = load i8*, i8** %9
store i8* %29, i8** %10
%30 = load i8*, i8** %10
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %6
%33 = load i8*, i8** %10
%34 = icmp ne i8* %32, %33
br i1 %34, label %35, label %38
35: ; preds = %15
%36 = load i8*, i8** %10
%37 = call i32 @free(i8* %36)
br label %38
38: ; preds = %35, %15
store i32 0, i32* %3
br label %39
39: ; preds = %38, %13
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@str = [74 x i8] c"Arguments error.For example:./zmreplacewords \22This is test cases.\22 is are\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str, i64 0, i64 0))
br label %18
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 3
%12 = load i8*, i8** %11
%13 = tail call i8* @zmWordsReplace(i8* %8, i8* %10, i8* %12)
%14 = tail call i32 @puts(i8* dereferenceable(1) %13)
%15 = icmp eq i8* %8, %13
br i1 %15, label %18, label %16
16: ; preds = %6
%17 = tail call i32 @free(i8* %13)
br label %18
18: ; preds = %6, %16, %4
ret i32 0
}