#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 *, char *);
int htonl(unsigned int);
int htons(unsigned short);
int /*<<< orphan*/ sprintf(char *, char *, int);
void dump_ddata(FILE *pigsty, const char *field, const unsigned char *buffer,
                const size_t buffer_size) {
  char temp[20] = "";
  if (pigsty == NULL || field == NULL || buffer == NULL || buffer_size == 0) {
    return;
  }
  switch (buffer_size) {
  case sizeof(unsigned char):
    sprintf(temp, "%d", *(unsigned char *)buffer);
    break;
  case sizeof(unsigned short):
    sprintf(temp, "%d", htons(*(unsigned short *)buffer));
    break;
  case sizeof(unsigned int):
    sprintf(temp, "%d", htonl(*(unsigned int *)buffer));
    break;
  default:
    return;
  }
  fprintf(pigsty,
          "\n "
          "%s = %s",
          field, temp);
}


x86 assembly (clang, -O0):
<dump_ddata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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   1050 <memset@plt>
cmpq   $0x0,-0x8(%rbp)
je     11a4 <dump_ddata+0x54>
cmpq   $0x0,-0x10(%rbp)
je     11a4 <dump_ddata+0x54>
cmpq   $0x0,-0x18(%rbp)
je     11a4 <dump_ddata+0x54>
cmpq   $0x0,-0x20(%rbp)
jne    11a9 <dump_ddata+0x59>
jmp    1274 <dump_ddata+0x124>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
sub    $0x1,%rax
je     11e6 <dump_ddata+0x96>
jmp    11c0 <dump_ddata+0x70>
mov    -0x48(%rbp),%rax
sub    $0x2,%rax
je     1202 <dump_ddata+0xb2>
jmp    11d3 <dump_ddata+0x83>
mov    -0x48(%rbp),%rax
sub    $0x4,%rax
je     122d <dump_ddata+0xdd>
jmp    1257 <dump_ddata+0x107>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rax
movzbl (%rax),%edx
lea    0xe08(%rip),%rsi
call   1070 <sprintf@plt>
jmp    125c <dump_ddata+0x10c>
lea    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rax
movzwl (%rax),%edi
call   1030 <htons@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%edx
lea    0xddd(%rip),%rsi
call   1070 <sprintf@plt>
jmp    125c <dump_ddata+0x10c>
lea    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%edx
lea    0xdb3(%rip),%rsi
call   1070 <sprintf@plt>
jmp    125c <dump_ddata+0x10c>
jmp    1274 <dump_ddata+0x124>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    0xd94(%rip),%rsi
call   1060 <fprintf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_ddata>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
test   %rdi,%rdi
je     11c3 <dump_ddata+0x83>
mov    %rsi,%r14
test   %rsi,%rsi
je     11c3 <dump_ddata+0x83>
test   %rdx,%rdx
je     11c3 <dump_ddata+0x83>
test   %rcx,%rcx
je     11c3 <dump_ddata+0x83>
mov    %rdi,%rbx
cmp    $0x4,%rcx
je     1189 <dump_ddata+0x49>
cmp    $0x2,%rcx
je     1192 <dump_ddata+0x52>
cmp    $0x1,%rcx
jne    11c3 <dump_ddata+0x83>
movzbl (%rdx),%edx
jmp    119c <dump_ddata+0x5c>
mov    (%rdx),%edi
call   1040 <htonl@plt>
jmp    119a <dump_ddata+0x5a>
movzwl (%rdx),%edi
call   1030 <htons@plt>
mov    %eax,%edx
lea    0xe5d(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
call   1060 <sprintf@plt>
lea    0xe4e(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
call   1050 <fprintf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [10 x i8] c"\0A %s = %s\00"
define void @dump_ddata(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 %30, label %14
14: ; preds = %4
switch i64 %3, label %30 [
i64 1, label %15
i64 2, label %18
i64 4, label %22
]
15: ; preds = %14
%16 = load i8, i8* %2
%17 = zext i8 %16 to i32
br label %26
18: ; preds = %14
%19 = bitcast i8* %2 to i16*
%20 = load i16, i16* %19
%21 = tail call i32 @htons(i16 zeroext %20)
br label %26
22: ; preds = %14
%23 = bitcast i8* %2 to i32*
%24 = load i32, i32* %23
%25 = tail call i32 @htonl(i32 %24)
br label %26
26: ; preds = %22, %18, %15
%27 = phi i32 [ %25, %22 ], [ %21, %18 ], [ %17, %15 ]
%28 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %6)
br label %30
30: ; preds = %14, %4, %26
ret void
}