#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_insert_quote_comma(char *, char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
void test_piece_insert_quote_comma(void) {
  char *source;
  char destination[128];
  source = "";
  printf("got source = (%s)\n", source);
  printf("should be (\"zero\"): is (%s)\n",
         piece_insert_quote_comma(destination, source, "zero", 0));
  source = "\"one\"";
  printf("got source = (%s)\n", source);
  printf("should be (\"zero\",\"one\"): is (%s)\n",
         piece_insert_quote_comma(destination, source, "zero", 0));
  source = "\"zero\",\"two\"";
  printf("got source = (%s)\n", source);
  printf("should be (\"zero\",\"one\",\"two\"): is (%s)\n",
         piece_insert_quote_comma(destination, source, "one", 1));
  source = "\"zero\",\"one\"";
  printf("got source = (%s)\n", source);
  printf("should be (\"zero\",\"one\",\"two\"): is (%s)\n",
         piece_insert_quote_comma(destination, source, "two", 2));
}


x86 assembly (clang, -O0):
<test_piece_insert_quote_comma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    0xee0(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xebf(%rip),%rdi
call   1030 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    0xed8(%rip),%rdx
xor    %ecx,%ecx
call   1040 <piece_insert_quote_comma@plt>
mov    %rax,%rsi
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
lea    0xf24(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    0xe95(%rip),%rdx
xor    %ecx,%ecx
call   1040 <piece_insert_quote_comma@plt>
mov    %rax,%rsi
lea    0xe89(%rip),%rdi
call   1030 <printf@plt>
lea    0xea0(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe39(%rip),%rdi
call   1030 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    0xeb0(%rip),%rdx
mov    $0x1,%ecx
call   1040 <piece_insert_quote_comma@plt>
mov    %rax,%rsi
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
lea    0xe94(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xdf3(%rip),%rdi
call   1030 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    0xe7b(%rip),%rdx
mov    $0x2,%ecx
call   1040 <piece_insert_quote_comma@plt>
mov    %rax,%rsi
lea    0xe2d(%rip),%rdi
call   1030 <printf@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_piece_insert_quote_comma>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
lea    0xecb(%rip),%r14
lea    0xed6(%rip),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
lea    0xee2(%rip),%r12
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
call   1040 <piece_insert_quote_comma@plt>
lea    0xeab(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
lea    0xf22(%rip),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
call   1040 <piece_insert_quote_comma@plt>
lea    0xe9c(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
lea    0xeb0(%rip),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
lea    0xed4(%rip),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x1,%ecx
call   1040 <piece_insert_quote_comma@plt>
lea    0xe94(%rip),%r12
mov    %r12,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
lea    0xeaf(%rip),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
lea    0xeaa(%rip),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x2,%ecx
call   1040 <piece_insert_quote_comma@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [19 x i8] c"got source = (%s)\0A\00"
@.str.2 = [29 x i8] c"should be (\22zero\22): is (%s)\0A\00"
@.str.3 = [5 x i8] c"zero\00"
@.str.4 = [6 x i8] c"\22one\22\00"
@.str.5 = [35 x i8] c"should be (\22zero\22,\22one\22): is (%s)\0A\00"
@.str.6 = [13 x i8] c"\22zero\22,\22two\22\00"
@.str.7 = [41 x i8] c"should be (\22zero\22,\22one\22,\22two\22): is (%s)\0A\00"
@.str.8 = [4 x i8] c"one\00"
@.str.9 = [13 x i8] c"\22zero\22,\22one\22\00"
@.str.10 = [4 x i8] c"two\00"
define void @test_piece_insert_quote_comma() {
%1 = alloca i8*
%2 = alloca [128 x i8]
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %1
%3 = load i8*, i8** %1
%4 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = load i8*, i8** %1
%7 = call i8* @piece_insert_quote_comma(i8* %5, i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 0)
%8 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %7)
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %1
%9 = load i8*, i8** %1
%10 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%12 = load i8*, i8** %1
%13 = call i8* @piece_insert_quote_comma(i8* %11, i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 0)
%14 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %13)
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8** %1
%15 = load i8*, i8** %1
%16 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%18 = load i8*, i8** %1
%19 = call i8* @piece_insert_quote_comma(i8* %17, i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 1)
%20 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i8* %19)
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i8** %1
%21 = load i8*, i8** %1
%22 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%24 = load i8*, i8** %1
%25 = call i8* @piece_insert_quote_comma(i8* %23, i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i32 2)
%26 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i8* %25)
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [19 x i8] c"got source = (%s)\0A\00"
@.str.2 = [29 x i8] c"should be (\22zero\22): is (%s)\0A\00"
@.str.3 = [5 x i8] c"zero\00"
@.str.4 = [6 x i8] c"\22one\22\00"
@.str.5 = [35 x i8] c"should be (\22zero\22,\22one\22): is (%s)\0A\00"
@.str.6 = [13 x i8] c"\22zero\22,\22two\22\00"
@.str.7 = [41 x i8] c"should be (\22zero\22,\22one\22,\22two\22): is (%s)\0A\00"
@.str.8 = [4 x i8] c"one\00"
@.str.9 = [13 x i8] c"\22zero\22,\22one\22\00"
@.str.10 = [4 x i8] c"two\00"
define void @test_piece_insert_quote_comma() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%4 = call i8* @piece_insert_quote_comma(i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 0)
%5 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%6 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%7 = call i8* @piece_insert_quote_comma(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 0)
%8 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %7)
%9 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%10 = call i8* @piece_insert_quote_comma(i8* %2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 1)
%11 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i8* %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%13 = call i8* @piece_insert_quote_comma(i8* %2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i32 2)
%14 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0), i8* %13)
ret void
}