#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 asprintf(char **, char *, char const *, ...);
int /*<<< orphan*/ free(char *);
int comma_append(char **dst, const char *key, const char *value, int quotes) {
  char *tmp;
  int result;
  if (*dst)
    if (value)
      if (quotes)
        result = asprintf(&tmp, "%s, %s=\"%s\"", *dst, key, value);
      else
        result = asprintf(&tmp, "%s, %s=%s", *dst, key, value);
    else
      result = asprintf(&tmp, "%s, %s", *dst, key);
  else if (value)
    if (quotes)
      result = asprintf(&tmp, "%s=\"%s\"", key, value);
    else
      result = asprintf(&tmp, "%s=%s", key, value);
  else
    result = asprintf(&tmp, "%s", key);
  if (result < 0)
    return result;
  if (*dst)
    free(*dst);
  *dst = tmp;
  return result;
}


x86 assembly (clang, -O0):
<comma_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     11d1 <comma_append+0xb1>
cmpq   $0x0,-0x20(%rbp)
je     11ac <comma_append+0x8c>
cmpl   $0x0,-0x24(%rbp)
je     1183 <comma_append+0x63>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    -0x30(%rbp),%rdi
lea    0xe8c(%rip),%rsi
mov    $0x0,%al
call   1040 <asprintf@plt>
mov    %eax,-0x34(%rbp)
jmp    11a7 <comma_append+0x87>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    -0x30(%rbp),%rdi
lea    0xe6f(%rip),%rsi
mov    $0x0,%al
call   1040 <asprintf@plt>
mov    %eax,-0x34(%rbp)
jmp    11cc <comma_append+0xac>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x30(%rbp),%rdi
lea    0xe54(%rip),%rsi
mov    $0x0,%al
call   1040 <asprintf@plt>
mov    %eax,-0x34(%rbp)
jmp    1248 <comma_append+0x128>
cmpq   $0x0,-0x20(%rbp)
je     122a <comma_append+0x10a>
cmpl   $0x0,-0x24(%rbp)
je     1208 <comma_append+0xe8>
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x30(%rbp),%rdi
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1040 <asprintf@plt>
mov    %eax,-0x34(%rbp)
jmp    1225 <comma_append+0x105>
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x30(%rbp),%rdi
lea    0xdf5(%rip),%rsi
mov    $0x0,%al
call   1040 <asprintf@plt>
mov    %eax,-0x34(%rbp)
jmp    1243 <comma_append+0x123>
mov    -0x18(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1040 <asprintf@plt>
mov    %eax,-0x34(%rbp)
jmp    1248 <comma_append+0x128>
cmpl   $0x0,-0x34(%rbp)
jge    125d <comma_append+0x13d>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1288 <comma_append+0x168>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1277 <comma_append+0x157>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<comma_append>:
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%r8
mov    %rsi,%rax
mov    %rdi,%rbx
mov    (%rdi),%rdx
test   %rdx,%rdx
je     1146 <comma_append+0x26>
test   %r8,%r8
je     1158 <comma_append+0x38>
test   %ecx,%ecx
je     1167 <comma_append+0x47>
lea    0xebc(%rip),%rsi
jmp    116e <comma_append+0x4e>
test   %r8,%r8
je     117d <comma_append+0x5d>
test   %ecx,%ecx
je     1193 <comma_append+0x73>
lea    0xeae(%rip),%rsi
jmp    119a <comma_append+0x7a>
lea    0xeb7(%rip),%rsi
mov    %rsp,%rdi
mov    %rax,%rcx
jmp    11a3 <comma_append+0x83>
lea    0xe9e(%rip),%rsi
mov    %rsp,%rdi
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <asprintf@plt>
jmp    11aa <comma_append+0x8a>
lea    0xe96(%rip),%rsi
mov    %rsp,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <asprintf@plt>
jmp    11aa <comma_append+0x8a>
lea    0xe76(%rip),%rsi
mov    %rsp,%rdi
mov    %rax,%rdx
mov    %r8,%rcx
xor    %eax,%eax
call   1040 <asprintf@plt>
mov    %eax,%ebp
test   %eax,%eax
js     11c4 <comma_append+0xa4>
mov    (%rbx),%rdi
test   %rdi,%rdi
je     11bd <comma_append+0x9d>
call   1030 <free@plt>
mov    (%rsp),%rax
mov    %rax,(%rbx)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%s, %s=\22%s\22\00"
@.str.1 = [10 x i8] c"%s, %s=%s\00"
@.str.2 = [7 x i8] c"%s, %s\00"
@.str.3 = [8 x i8] c"%s=\22%s\22\00"
@.str.4 = [6 x i8] c"%s=%s\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @comma_append(i8** %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i8** %0, i8*** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%12 = load i8**, i8*** %6
%13 = load i8*, i8** %12
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %40
15: ; preds = %4
%16 = load i8*, i8** %8
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %34
18: ; preds = %15
%19 = load i32, i32* %9
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i8**, i8*** %6
%23 = load i8*, i8** %22
%24 = load i8*, i8** %7
%25 = load i8*, i8** %8
%26 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %24, i8* %25)
store i32 %26, i32* %11
br label %33
27: ; preds = %18
%28 = load i8**, i8*** %6
%29 = load i8*, i8** %28
%30 = load i8*, i8** %7
%31 = load i8*, i8** %8
%32 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %30, i8* %31)
store i32 %32, i32* %11
br label %33
33: ; preds = %27, %21
br label %39
34: ; preds = %15
%35 = load i8**, i8*** %6
%36 = load i8*, i8** %35
%37 = load i8*, i8** %7
%38 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %36, i8* %37)
store i32 %38, i32* %11
br label %39
39: ; preds = %34, %33
br label %59
40: ; preds = %4
%41 = load i8*, i8** %8
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %55
43: ; preds = %40
%44 = load i32, i32* %9
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %43
%47 = load i8*, i8** %7
%48 = load i8*, i8** %8
%49 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %47, i8* %48)
store i32 %49, i32* %11
br label %54
50: ; preds = %43
%51 = load i8*, i8** %7
%52 = load i8*, i8** %8
%53 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %51, i8* %52)
store i32 %53, i32* %11
br label %54
54: ; preds = %50, %46
br label %58
55: ; preds = %40
%56 = load i8*, i8** %7
%57 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %56)
store i32 %57, i32* %11
br label %58
58: ; preds = %55, %54
br label %59
59: ; preds = %58, %39
%60 = load i32, i32* %11
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %59
%63 = load i32, i32* %11
store i32 %63, i32* %5
br label %76
64: ; preds = %59
%65 = load i8**, i8*** %6
%66 = load i8*, i8** %65
%67 = icmp ne i8* %66, null
br i1 %67, label %68, label %72
68: ; preds = %64
%69 = load i8**, i8*** %6
%70 = load i8*, i8** %69
%71 = call i32 @free(i8* %70)
br label %72
72: ; preds = %68, %64
%73 = load i8*, i8** %10
%74 = load i8**, i8*** %6
store i8* %73, i8** %74
%75 = load i32, i32* %11
store i32 %75, i32* %5
br label %76
76: ; preds = %72, %62
%77 = load i32, i32* %5
ret i32 %77
}

LLVM IR (-O2):
@.str = [12 x i8] c"%s, %s=\22%s\22\00"
@.str.1 = [10 x i8] c"%s, %s=%s\00"
@.str.2 = [7 x i8] c"%s, %s\00"
@.str.3 = [8 x i8] c"%s=\22%s\22\00"
@.str.4 = [6 x i8] c"%s=%s\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @comma_append(i8** nocapture %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
%7 = load i8*, i8** %0
%8 = icmp eq i8* %7, null
%9 = icmp eq i8* %2, null
br i1 %8, label %19, label %10
10: ; preds = %4
br i1 %9, label %17, label %11
11: ; preds = %10
%12 = icmp eq i32 %3, 0
br i1 %12, label %15, label %13
13: ; preds = %11
%14 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %1, i8* %2)
br label %28
15: ; preds = %11
%16 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %5, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %1, i8* %2)
br label %28
17: ; preds = %10
%18 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* %1)
br label %28
19: ; preds = %4
br i1 %9, label %26, label %20
20: ; preds = %19
%21 = icmp eq i32 %3, 0
br i1 %21, label %24, label %22
22: ; preds = %20
%23 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %2)
br label %28
24: ; preds = %20
%25 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %1, i8* %2)
br label %28
26: ; preds = %19
%27 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %1)
br label %28
28: ; preds = %26, %24, %22, %17, %15, %13
%29 = phi i32 [ %14, %13 ], [ %16, %15 ], [ %18, %17 ], [ %23, %22 ], [ %25, %24 ], [ %27, %26 ]
%30 = icmp slt i32 %29, 0
br i1 %30, label %38, label %31
31: ; preds = %28
%32 = load i8*, i8** %0
%33 = icmp eq i8* %32, null
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = call i32 @free(i8* %32)
br label %36
36: ; preds = %34, %31
%37 = load i8*, i8** %5
store i8* %37, i8** %0
br label %38
38: ; preds = %28, %36
ret i32 %29
}