#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 */
char *piece_replace(char *, int, char *, int);
char *piece_replace_quote_comma(char *, char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void test_piece_replace_quote_comma(void) {
  char source_destination[128];
  char destination[128];
  char *source;
  strcpy(source_destination,
         "\"1AAA\",\"stage\",\"2013-06-20\",\"2400\",\"5\"");
  piece_replace(source_destination, 1, "2013-06-21", 2);
  printf("returned = (%s)\n", source_destination);
  *source_destination = '\0';
  printf("got source_destination = (%s)\n", source_destination);
  printf("should be (\"zero\"): is (%s)\n",
         piece_replace(source_destination, 1, "zero", 0));
  source = "\"one\"";
  printf("got source = (%s)\n", source);
  printf("should be (\"zero\"): is (%s)\n",
         piece_replace_quote_comma(destination, source, "zero", 0));
  source = "\"zero\",\"two\"";
  printf("got source = (%s)\n", source);
  printf("should be (\"zero\",\"one\"): is (%s)\n",
         piece_replace_quote_comma(destination, source, "one", 1));
  source = "\"zero\",\"one\",\"three\"";
  printf("got source = (%s)\n", source);
  printf("should be (\"zero\",\"one\",\"two\"): is (%s)\n",
         piece_replace_quote_comma(destination, source, "two", 2));
}


x86 assembly (clang, -O0):
<test_piece_replace_quote_comma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    -0x80(%rbp),%rdi
lea    0xeaa(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x80(%rbp),%rdi
mov    $0x1,%esi
lea    0xebc(%rip),%rdx
mov    $0x2,%ecx
call   1050 <piece_replace@plt>
lea    -0x80(%rbp),%rsi
lea    0xeb2(%rip),%rdi
call   1040 <printf@plt>
movb   $0x0,-0x80(%rbp)
lea    -0x80(%rbp),%rsi
lea    0xeaf(%rip),%rdi
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    $0x1,%esi
lea    0xed6(%rip),%rdx
xor    %ecx,%ecx
call   1050 <piece_replace@plt>
mov    %rax,%rsi
lea    0xea8(%rip),%rdi
call   1040 <printf@plt>
lea    0xebe(%rip),%rax
mov    %rax,-0x108(%rbp)
mov    -0x108(%rbp),%rsi
lea    0xeaf(%rip),%rdi
call   1040 <printf@plt>
lea    -0x100(%rbp),%rdi
mov    -0x108(%rbp),%rsi
lea    0xe8a(%rip),%rdx
xor    %ecx,%ecx
call   1060 <piece_replace_quote_comma@plt>
mov    %rax,%rsi
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
lea    0xe8b(%rip),%rax
mov    %rax,-0x108(%rbp)
mov    -0x108(%rbp),%rsi
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
lea    -0x100(%rbp),%rdi
mov    -0x108(%rbp),%rsi
lea    0xe8c(%rip),%rdx
mov    $0x1,%ecx
call   1060 <piece_replace_quote_comma@plt>
mov    %rax,%rsi
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
lea    0xe70(%rip),%rax
mov    %rax,-0x108(%rbp)
mov    -0x108(%rbp),%rsi
lea    0xe14(%rip),%rdi
call   1040 <printf@plt>
lea    -0x100(%rbp),%rdi
mov    -0x108(%rbp),%rsi
lea    0xe7f(%rip),%rdx
mov    $0x2,%ecx
call   1060 <piece_replace_quote_comma@plt>
mov    %rax,%rsi
lea    0xe42(%rip),%rdi
call   1040 <printf@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_piece_replace_quote_comma>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100,%rsp
lea    0xea9(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xebe(%rip),%rdx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x2,%ecx
call   1050 <piece_replace@plt>
lea    0xeb0(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
movb   $0x0,(%rsp)
lea    0xeae(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xedb(%rip),%r15
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
xor    %ecx,%ecx
call   1050 <piece_replace@plt>
lea    0xea5(%rip),%r13
mov    %r13,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0xebb(%rip),%r14
lea    0xeae(%rip),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0x80(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
xor    %ecx,%ecx
call   1060 <piece_replace_quote_comma@plt>
mov    %r13,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0xe92(%rip),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xeb0(%rip),%rdx
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x1,%ecx
call   1060 <piece_replace_quote_comma@plt>
lea    0xe76(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0xe8e(%rip),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xeba(%rip),%rdx
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x2,%ecx
call   1060 <piece_replace_quote_comma@plt>
lea    0xe7a(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [39 x i8] c"\221AAA\22,\22stage\22,\222013-06-20\22,\222400\22,\225\22\00"
@.str.1 = [11 x i8] c"2013-06-21\00"
@.str.2 = [17 x i8] c"returned = (%s)\0A\00"
@.str.3 = [31 x i8] c"got source_destination = (%s)\0A\00"
@.str.4 = [29 x i8] c"should be (\22zero\22): is (%s)\0A\00"
@.str.5 = [5 x i8] c"zero\00"
@.str.6 = [6 x i8] c"\22one\22\00"
@.str.7 = [19 x i8] c"got source = (%s)\0A\00"
@.str.8 = [13 x i8] c"\22zero\22,\22two\22\00"
@.str.9 = [35 x i8] c"should be (\22zero\22,\22one\22): is (%s)\0A\00"
@.str.10 = [4 x i8] c"one\00"
@.str.11 = [21 x i8] c"\22zero\22,\22one\22,\22three\22\00"
@.str.12 = [41 x i8] c"should be (\22zero\22,\22one\22,\22two\22): is (%s)\0A\00"
@.str.13 = [4 x i8] c"two\00"
define void @test_piece_replace_quote_comma() {
%1 = alloca [128 x i8]
%2 = alloca [128 x i8]
%3 = alloca i8*
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%7 = call i8* @piece_replace(i8* %6, i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 2)
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%9 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
store i8 0, i8* %10
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%12 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%14 = call i8* @piece_replace(i8* %13, i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 0)
%15 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %14)
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8** %3
%16 = load i8*, i8** %3
%17 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%19 = load i8*, i8** %3
%20 = call i8* @piece_replace_quote_comma(i8* %18, i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 0)
%21 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %20)
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i8** %3
%22 = load i8*, i8** %3
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%25 = load i8*, i8** %3
%26 = call i8* @piece_replace_quote_comma(i8* %24, i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i32 1)
%27 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), i8* %26)
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i8** %3
%28 = load i8*, i8** %3
%29 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* %28)
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%31 = load i8*, i8** %3
%32 = call i8* @piece_replace_quote_comma(i8* %30, i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), i32 2)
%33 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.12, i64 0, i64 0), i8* %32)
ret void
}

LLVM IR (-O2):
@.str = [39 x i8] c"\221AAA\22,\22stage\22,\222013-06-20\22,\222400\22,\225\22\00"
@.str.1 = [11 x i8] c"2013-06-21\00"
@.str.2 = [17 x i8] c"returned = (%s)\0A\00"
@.str.3 = [31 x i8] c"got source_destination = (%s)\0A\00"
@.str.4 = [29 x i8] c"should be (\22zero\22): is (%s)\0A\00"
@.str.5 = [5 x i8] c"zero\00"
@.str.6 = [6 x i8] c"\22one\22\00"
@.str.7 = [19 x i8] c"got source = (%s)\0A\00"
@.str.8 = [13 x i8] c"\22zero\22,\22two\22\00"
@.str.9 = [35 x i8] c"should be (\22zero\22,\22one\22): is (%s)\0A\00"
@.str.10 = [4 x i8] c"one\00"
@.str.11 = [21 x i8] c"\22zero\22,\22one\22,\22three\22\00"
@.str.12 = [41 x i8] c"should be (\22zero\22,\22one\22,\22two\22): is (%s)\0A\00"
@.str.13 = [4 x i8] c"two\00"
define void @test_piece_replace_quote_comma() {
%1 = alloca [128 x i8]
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%6 = call i8* @piece_replace(i8* %3, i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 2)
%7 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %3)
store i8 0, i8* %3
%8 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%9 = call i8* @piece_replace(i8* %3, i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 0)
%10 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%12 = call i8* @piece_replace_quote_comma(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 0)
%13 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%15 = call i8* @piece_replace_quote_comma(i8* %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i32 1)
%16 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), i8* %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0))
%18 = call i8* @piece_replace_quote_comma(i8* %4, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), i32 2)
%19 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.12, i64 0, i64 0), i8* %18)
ret void
}