#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ find_escape_character(char const);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const);
int dump_arg(FILE *out, const char *start, int count, bool close) {
  int l = 0;
  while (count) {
    if (start[l] == '|') {
      if (count > 1) {
        fprintf(out, "%c", ',');
      } else if (close) {
        fprintf(out, "%c", ')');
      }
      count--;
    } else {
      if (find_escape_character(start[l])) {
        fprintf(out, "%c", '%');
      }
      fprintf(out, "%c", start[l]);
    }
    l++;
  }
  return l;
}


x86 assembly (clang, -O0):
<dump_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     120c <dump_arg+0xec>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7c,%eax
jne    11b2 <dump_arg+0x92>
cmpl   $0x1,-0x14(%rbp)
jle    1180 <dump_arg+0x60>
mov    -0x8(%rbp),%rdi
lea    0xe8f(%rip),%rsi
mov    $0x2c,%edx
call   1040 <fprintf@plt>
jmp    11a4 <dump_arg+0x84>
cmpl   $0x0,-0x18(%rbp)
je     119f <dump_arg+0x7f>
mov    -0x8(%rbp),%rdi
lea    0xe6b(%rip),%rsi
mov    $0x29,%edx
call   1040 <fprintf@plt>
jmp    11a4 <dump_arg+0x84>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11fe <dump_arg+0xde>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <find_escape_character@plt>
cmp    $0x0,%rax
je     11e2 <dump_arg+0xc2>
mov    -0x8(%rbp),%rdi
lea    0xe28(%rip),%rsi
mov    $0x25,%edx
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
lea    0xe0b(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113d <dump_arg+0x1d>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_arg>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
je     11a9 <dump_arg+0x89>
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%r12
xor    %ebx,%ebx
jmp    1161 <dump_arg+0x41>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
cmp    $0x2,%ebp
setge  %al
lea    (%rax,%rax,2),%edi
add    $0x29,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
add    $0xffffffff,%ebp
add    $0x1,%rbx
test   %ebp,%ebp
je     11ab <dump_arg+0x8b>
movzbl (%r15,%rbx,1),%eax
cmp    $0x7c,%al
jne    1180 <dump_arg+0x60>
cmp    $0x1,%ebp
jg     1140 <dump_arg+0x20>
test   %r14d,%r14d
je     1156 <dump_arg+0x36>
jmp    1140 <dump_arg+0x20>
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   1040 <find_escape_character@plt>
test   %rax,%rax
je     119a <dump_arg+0x7a>
mov    $0x25,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
movsbl (%r15,%rbx,1),%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
jmp    1159 <dump_arg+0x39>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define i32 @dump_arg(i32* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %10
10: ; preds = %56, %4
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %59
13: ; preds = %10
%14 = load i8*, i8** %6
%15 = load i32, i32* %9
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 124
br i1 %20, label %21, label %37
21: ; preds = %13
%22 = load i32, i32* %7
%23 = icmp sgt i32 %22, 1
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32*, i32** %5
%26 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext 44)
br label %34
27: ; preds = %21
%28 = load i32, i32* %8
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32*, i32** %5
%32 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext 41)
br label %33
33: ; preds = %30, %27
br label %34
34: ; preds = %33, %24
%35 = load i32, i32* %7
%36 = add nsw i32 %35, -1
store i32 %36, i32* %7
br label %56
37: ; preds = %13
%38 = load i8*, i8** %6
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = call i64 @find_escape_character(i8 signext %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %37
%46 = load i32*, i32** %5
%47 = call i32 @fprintf(i32* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext 37)
br label %48
48: ; preds = %45, %37
%49 = load i32*, i32** %5
%50 = load i8*, i8** %6
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = call i32 @fprintf(i32* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %54)
br label %56
56: ; preds = %48, %34
%57 = load i32, i32* %9
%58 = add nsw i32 %57, 1
store i32 %58, i32* %9
br label %10
59: ; preds = %10
%60 = load i32, i32* %9
ret i32 %60
}

LLVM IR (-O2):
define i32 @dump_arg(i32* nocapture %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %2, 0
br i1 %5, label %37, label %6
6: ; preds = %4
%7 = icmp ne i32 %3, 0
br label %8
8: ; preds = %6, %31
%9 = phi i64 [ 0, %6 ], [ %33, %31 ]
%10 = phi i32 [ %2, %6 ], [ %32, %31 ]
%11 = getelementptr inbounds i8, i8* %1, i64 %9
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 124
br i1 %13, label %14, label %22
14: ; preds = %8
%15 = icmp sgt i32 %10, 1
%16 = or i1 %15, %7
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = select i1 %15, i32 44, i32 41
%19 = tail call i32 @fputc(i32 %18, i32* %0)
br label %20
20: ; preds = %14, %17
%21 = add nsw i32 %10, -1
br label %31
22: ; preds = %8
%23 = tail call i64 @find_escape_character(i8 signext %12)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = tail call i32 @fputc(i32 37, i32* %0)
br label %27
27: ; preds = %25, %22
%28 = load i8, i8* %11
%29 = sext i8 %28 to i32
%30 = tail call i32 @fputc(i32 %29, i32* %0)
br label %31
31: ; preds = %27, %20
%32 = phi i32 [ %21, %20 ], [ %10, %27 ]
%33 = add nuw i64 %9, 1
%34 = icmp eq i32 %32, 0
br i1 %34, label %35, label %8
35: ; preds = %31
%36 = trunc i64 %33 to i32
br label %37
37: ; preds = %35, %4
%38 = phi i32 [ 0, %4 ], [ %36, %35 ]
ret i32 %38
}