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


x86 assembly (clang, -O0):
<cmml_snprint_attribute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     115d <cmml_snprint_attribute+0x2d>
cmpq   $0x0,-0x28(%rbp)
jne    1169 <cmml_snprint_attribute+0x39>
movl   $0x0,-0x4(%rbp)
jmp    11bb <cmml_snprint_attribute+0x8b>
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
call   1050 <escape_chars@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    -0x38(%rbp),%r8
lea    0xe6f(%rip),%rdx
call   1040 <cmml_snprintf@plt>
mov    %eax,-0x2c(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11b5 <cmml_snprint_attribute+0x85>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmml_snprint_attribute>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %ebp,%ebp
test   %rdx,%rdx
je     1184 <cmml_snprint_attribute+0x54>
test   %rcx,%rcx
je     1184 <cmml_snprint_attribute+0x54>
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%r15
mov    %rcx,%rdi
mov    $0x1,%esi
call   1050 <escape_chars@plt>
mov    %rax,%r12
lea    0xe9c(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rbx,%rcx
mov    %rax,%r8
call   1040 <cmml_snprintf@plt>
mov    %eax,%ebp
test   %r12,%r12
je     1184 <cmml_snprint_attribute+0x54>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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