#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 cmml_snprintf(char *, int, char *, char *);
char *escape_chars(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int cmml_snprint_pcdata(char *buf, int n, char *data) {
  int n_written;
  char *unesc;
  if (data == NULL)
    return 0;
  unesc = escape_chars(data, 0);
  n_written = cmml_snprintf(buf, n, "%s", unesc);
  if (unesc) {
    free(unesc);
    unesc = 0;
  };
  return n_written;
}


x86 assembly (clang, -O0):
<cmml_snprint_pcdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    115a <cmml_snprint_pcdata+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    11a5 <cmml_snprint_pcdata+0x75>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1050 <escape_chars@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%rcx
lea    0xe85(%rip),%rdx
call   1040 <cmml_snprintf@plt>
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     119f <cmml_snprint_pcdata+0x6f>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmml_snprint_pcdata>:
push   %rbp
push   %r14
push   %rbx
test   %rdx,%rdx
je     1172 <cmml_snprint_pcdata+0x42>
mov    %esi,%r14d
mov    %rdi,%rbp
mov    %rdx,%rdi
xor    %esi,%esi
call   1050 <escape_chars@plt>
mov    %rax,%rbx
lea    0xead(%rip),%rdx
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %rax,%rcx
call   1040 <cmml_snprintf@plt>
mov    %eax,%ebp
test   %rbx,%rbx
je     1174 <cmml_snprint_pcdata+0x44>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1174 <cmml_snprint_pcdata+0x44>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i32 @cmml_snprint_pcdata(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%10 = load i8*, i8** %7
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 0, i32* %4
br label %27
13: ; preds = %3
%14 = load i8*, i8** %7
%15 = call i8* @escape_chars(i8* %14, i32 0)
store i8* %15, i8** %9
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = load i8*, i8** %9
%19 = call i32 @cmml_snprintf(i8* %16, i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 %19, i32* %8
%20 = load i8*, i8** %9
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %13
%23 = load i8*, i8** %9
%24 = call i32 @free(i8* %23)
store i8* null, i8** %9
br label %25
25: ; preds = %22, %13
%26 = load i32, i32* %8
store i32 %26, i32* %4
br label %27
27: ; preds = %25, %12
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i32 @cmml_snprint_pcdata(i8* %0, i32 %1, i8* %2) {
%4 = icmp eq i8* %2, null
br i1 %4, label %11, label %5
5: ; preds = %3
%6 = tail call i8* @escape_chars(i8* %2, i32 0)
%7 = tail call i32 @cmml_snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = icmp eq i8* %6, null
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @free(i8* %6)
br label %11
11: ; preds = %5, %9, %3
%12 = phi i32 [ 0, %3 ], [ %7, %9 ], [ %7, %5 ]
ret i32 %12
}