#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 */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char const);
void dump_xstring(FILE *pigsty, const char *field, const unsigned char *buffer,
                  const size_t buffer_size) {
  const unsigned char *bp = NULL;
  const unsigned char *bp_end = NULL;
  char temp[20] = "";
  if (pigsty == NULL || field == NULL || buffer == NULL || buffer_size == 0) {
    return;
  }
  bp = buffer;
  bp_end = bp + buffer_size;
  fprintf(pigsty,
          "\n "
          "%s = \"",
          field);
  while (bp != bp_end) {
    sprintf(temp, "\\x%.2x", *bp);
    fprintf(pigsty, "%s", temp);
    bp++;
  }
  fprintf(pigsty, "\"");
}


x86 assembly (clang, -O0):
<dump_xstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
cmpq   $0x0,-0x8(%rbp)
je     1194 <dump_xstring+0x64>
cmpq   $0x0,-0x10(%rbp)
je     1194 <dump_xstring+0x64>
cmpq   $0x0,-0x18(%rbp)
je     1194 <dump_xstring+0x64>
cmpq   $0x0,-0x20(%rbp)
jne    1199 <dump_xstring+0x69>
jmp    1221 <dump_xstring+0xf1>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     120f <dump_xstring+0xdf>
lea    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rax
lea    0xe29(%rip),%rsi
movzbl (%rax),%edx
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11c3 <dump_xstring+0x93>
mov    -0x8(%rbp),%rdi
lea    0xded(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_xstring>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
test   %rdi,%rdi
je     11df <dump_xstring+0x9f>
mov    %rdx,%r15
mov    %rsi,%rdx
test   %rsi,%rsi
je     11df <dump_xstring+0x9f>
test   %r15,%r15
je     11df <dump_xstring+0x9f>
mov    %rcx,%r14
test   %rcx,%rcx
je     11df <dump_xstring+0x9f>
mov    %rdi,%r13
lea    0xe7c(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe75(%rip),%r12
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%rbp,1),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <fputs@plt>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    11a0 <dump_xstring+0x60>
mov    $0x22,%edi
mov    %r13,%rsi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fputc@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"\0A %s = \22\00"
@.str.1 = [7 x i8] c"\\x%.2x\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [2 x i8] c"\22\00"
define void @dump_xstring(i32* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [20 x i8]
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
store i8* null, i8** %9
store i8* null, i8** %10
%12 = bitcast [20 x i8]* %11 to i8*
%13 = load i32*, i32** %5
%14 = icmp eq i32* %13, null
br i1 %14, label %24, label %15
15: ; preds = %4
%16 = load i8*, i8** %6
%17 = icmp eq i8* %16, null
br i1 %17, label %24, label %18
18: ; preds = %15
%19 = load i8*, i8** %7
%20 = icmp eq i8* %19, null
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i64, i64* %8
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %21, %18, %15, %4
br label %50
25: ; preds = %21
%26 = load i8*, i8** %7
store i8* %26, i8** %9
%27 = load i8*, i8** %9
%28 = load i64, i64* %8
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8* %29, i8** %10
%30 = load i32*, i32** %5
%31 = load i8*, i8** %6
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %37, %25
%34 = load i8*, i8** %9
%35 = load i8*, i8** %10
%36 = icmp ne i8* %34, %35
br i1 %36, label %37, label %47
37: ; preds = %33
%38 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%39 = load i8*, i8** %9
%40 = load i8, i8* %39
%41 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %40)
%42 = load i32*, i32** %5
%43 = getelementptr inbounds [20 x i8], [20 x i8]* %11, i64 0, i64 0
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %43)
%45 = load i8*, i8** %9
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %9
br label %33
47: ; preds = %33
%48 = load i32*, i32** %5
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %50
50: ; preds = %47, %24
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"\0A %s = \22\00"
@.str.1 = [7 x i8] c"\\x%.2x\00"
define void @dump_xstring(i32* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca [20 x i8]
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%7 = icmp eq i32* %0, null
%8 = icmp eq i8* %1, null
%9 = or i1 %7, %8
%10 = icmp eq i8* %2, null
%11 = or i1 %9, %10
%12 = icmp eq i64 %3, 0
%13 = or i1 %11, %12
br i1 %13, label %26, label %14
14: ; preds = %4
%15 = getelementptr inbounds i8, i8* %2, i64 %3
%16 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %17
17: ; preds = %14, %17
%18 = phi i8* [ %22, %17 ], [ %2, %14 ]
%19 = load i8, i8* %18
%20 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %19)
%21 = call i32 @fputs(i8* %6, i32* %0)
%22 = getelementptr inbounds i8, i8* %18, i64 1
%23 = icmp eq i8* %22, %15
br i1 %23, label %24, label %17
24: ; preds = %17
%25 = tail call i32 @fputc(i32 34, i32* %0)
br label %26
26: ; preds = %4, %24
ret void
}