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


x86 assembly (clang, -O0):
<dump_xdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1194 <dump_xdata+0x64>
cmpq   $0x0,-0x10(%rbp)
je     1194 <dump_xdata+0x64>
cmpq   $0x0,-0x18(%rbp)
je     1194 <dump_xdata+0x64>
cmpq   $0x0,-0x20(%rbp)
jne    1199 <dump_xdata+0x69>
jmp    120b <dump_xdata+0xdb>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe58(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x50(%rbp),%rax
je     120b <dump_xdata+0xdb>
lea    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rax
lea    0xe2c(%rip),%rsi
movzbl (%rax),%edx
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xe1a(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    11c1 <dump_xdata+0x91>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_xdata>:
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     11b4 <dump_xdata+0x84>
mov    %rdx,%r15
mov    %rsi,%rdx
test   %rsi,%rsi
je     11b4 <dump_xdata+0x84>
test   %r15,%r15
je     11b4 <dump_xdata+0x84>
mov    %rcx,%r14
test   %rcx,%rcx
je     11b4 <dump_xdata+0x84>
mov    %rdi,%r13
lea    0xe8c(%rip),%rsi
call   1040 <fprintf@plt>
xor    %ebp,%ebp
lea    0xe88(%rip),%r12
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r15,%rbp,1),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <fputs@plt>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1190 <dump_xdata+0x60>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"\0A %s = 0x\00"
@.str.1 = [5 x i8] c"%.2X\00"
@.str.2 = [3 x i8] c"%s\00"
define void @dump_xdata(i32* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca [20 x i8]
%10 = alloca i8*
%11 = alloca i8*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%12 = bitcast [20 x i8]* %9 to i8*
store i8* null, i8** %10
store i8* null, i8** %11
%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 %47
25: ; preds = %21
%26 = load i32*, i32** %5
%27 = load i8*, i8** %6
%28 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = load i8*, i8** %7
store i8* %29, i8** %10
%30 = load i8*, i8** %10
%31 = load i64, i64* %8
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8* %32, i8** %11
br label %33
33: ; preds = %37, %25
%34 = load i8*, i8** %10
%35 = load i8*, i8** %11
%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]* %9, i64 0, i64 0
%39 = load i8*, i8** %10
%40 = load i8, i8* %39
%41 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 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]* %9, i64 0, i64 0
%44 = call i32 @fprintf(i32* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %43)
%45 = load i8*, i8** %10
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %10
br label %33
47: ; preds = %24, %33
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"\0A %s = 0x\00"
@.str.1 = [5 x i8] c"%.2X\00"
define void @dump_xdata(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 %24, label %14
14: ; preds = %4
%15 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %1)
%16 = getelementptr inbounds i8, i8* %2, i64 %3
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 ([5 x i8], [5 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, %16
br i1 %23, label %24, label %17
24: ; preds = %17, %4
ret void
}