#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 /*<<< orphan*/ server_log(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char);
size_t strlen(char *);
void hexdump(char *str, size_t size) {
  size_t i;
  size_t len = (size) ? size : strlen(str);
  char buff1[3 * 16 + 1 + 5];
  char buff2[17];
  char *ptr = buff1;
  server_log(0, "HEXDUMP size: %d", len);
  for (i = 0; i < len; i++) {
    if (i != 0 && i % 16 == 0) {
      server_log(0, "%s\t%s", buff1, buff2);
      buff1[0] = 0x00;
      ptr = buff1;
    }
    if ((str[i] >= (int)*"a" && str[i] <= (int)*"z") ||
        (str[i] >= (int)*"A" && str[i] <= (int)*"Z") ||
        (str[i] == (int)*"[" || str[i] == (int)*"]") ||
        (str[i] >= (int)*"0" && str[i] <= (int)*"9")) {
      buff2[i % 16] = str[i];
    } else {
      buff2[i % 16] = *".";
    }
    buff2[(i % 16) + 1] = 0x00;
    sprintf(ptr, "%02x ", str[i] & 0xff);
    ptr += 3;
  }
  if (i % 16 != 0)
    server_log(0, "%s\t%s", buff1, buff2);
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     115e <hexdump+0x2e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x90(%rbp)
jmp    116e <hexdump+0x3e>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x20(%rbp),%rdx
xor    %edi,%edi
lea    0xe6f(%rip),%rsi
mov    $0x0,%al
call   1040 <server_log@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    134f <hexdump+0x21f>
cmpq   $0x0,-0x18(%rbp)
je     11f2 <hexdump+0xc2>
mov    -0x18(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    11f2 <hexdump+0xc2>
lea    -0x60(%rbp),%rdx
lea    -0x80(%rbp),%rcx
xor    %edi,%edi
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1040 <server_log@plt>
movb   $0x0,-0x60(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl 0xe12(%rip),%ecx
cmp    %ecx,%eax
jl     1228 <hexdump+0xf8>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl 0xdf9(%rip),%ecx
cmp    %ecx,%eax
jle    12ca <hexdump+0x19a>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl 0xde0(%rip),%ecx
cmp    %ecx,%eax
jl     125e <hexdump+0x12e>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl 0xdc7(%rip),%ecx
cmp    %ecx,%eax
jle    12ca <hexdump+0x19a>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl 0xdae(%rip),%ecx
cmp    %ecx,%eax
je     12ca <hexdump+0x19a>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl 0xd95(%rip),%ecx
cmp    %ecx,%eax
je     12ca <hexdump+0x19a>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl 0xd7c(%rip),%ecx
cmp    %ecx,%eax
jl     12e6 <hexdump+0x1b6>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl 0xd63(%rip),%ecx
cmp    %ecx,%eax
jg     12e6 <hexdump+0x1b6>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x18(%rbp),%rax
and    $0xf,%rax
mov    %cl,-0x80(%rbp,%rax,1)
jmp    12f8 <hexdump+0x1c8>
mov    0xd3b(%rip),%cl
mov    -0x18(%rbp),%rax
and    $0xf,%rax
mov    %cl,-0x80(%rbp,%rax,1)
mov    -0x18(%rbp),%rax
and    $0xf,%rax
movb   $0x0,-0x7f(%rbp,%rax,1)
mov    -0x88(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
lea    0xd05(%rip),%rsi
movsbl %al,%edx
call   1050 <sprintf@plt>
mov    -0x88(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x88(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11a0 <hexdump+0x70>
mov    -0x18(%rbp),%rax
and    $0xf,%rax
cmp    $0x0,%rax
je     1379 <hexdump+0x249>
lea    -0x60(%rbp),%rdx
lea    -0x80(%rbp),%rcx
xor    %edi,%edi
lea    0xc9f(%rip),%rsi
mov    $0x0,%al
call   1040 <server_log@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%r14
test   %rsi,%rsi
je     115e <hexdump+0x2e>
mov    %rsi,%r13
lea    0xeb0(%rip),%rsi
xor    %edi,%edi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <server_log@plt>
jmp    1185 <hexdump+0x55>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
lea    0xe90(%rip),%rsi
xor    %edi,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <server_log@plt>
test   %r13,%r13
je     124c <hexdump+0x11c>
lea    0x20(%rsp),%r15
mov    %rsp,%rbx
xor    %r12d,%r12d
jmp    11c8 <hexdump+0x98>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %cl,0x0(%rbp,%rbx,1)
movb   $0x0,0x1(%rbp,%rbx,1)
movsbl %al,%edx
mov    %r15,%rdi
lea    0xe61(%rip),%rsi
call   1050 <sprintf@plt>
add    $0x3,%r15
add    $0x1,%r12
cmp    %r12,%r13
je     122e <hexdump+0xfe>
mov    %r12d,%ebp
and    $0xf,%ebp
test   %r12,%r12
je     11f8 <hexdump+0xc8>
test   %rbp,%rbp
jne    11f8 <hexdump+0xc8>
xor    %edi,%edi
lea    0xe30(%rip),%rsi
lea    0x20(%rsp),%r15
mov    %r15,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <server_log@plt>
movb   $0x0,0x20(%rsp)
movzbl (%r14,%r12,1),%eax
mov    %eax,%edx
and    $0xdf,%dl
add    $0xbf,%dl
mov    %eax,%ecx
cmp    $0x1a,%dl
jb     11a0 <hexdump+0x70>
mov    %eax,%ecx
cmp    $0x5b,%al
je     11a0 <hexdump+0x70>
mov    %eax,%ecx
cmp    $0x5d,%al
je     11a0 <hexdump+0x70>
lea    -0x30(%rax),%ecx
cmp    $0xa,%cl
movzbl %al,%ecx
mov    $0x2e,%edx
cmovae %edx,%ecx
jmp    11a0 <hexdump+0x70>
test   $0xf,%r13b
je     124c <hexdump+0x11c>
lea    0xdd6(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %rsp,%rcx
xor    %edi,%edi
xor    %eax,%eax
call   1040 <server_log@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"HEXDUMP size: %d\00"
@.str.1 = [6 x i8] c"%s\09%s\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [2 x i8] c"z\00"
@.str.4 = [2 x i8] c"A\00"
@.str.5 = [2 x i8] c"Z\00"
@.str.6 = [2 x i8] c"[\00"
@.str.7 = [2 x i8] c"]\00"
@.str.8 = [2 x i8] c"0\00"
@.str.9 = [2 x i8] c"9\00"
@.str.10 = [2 x i8] c".\00"
@.str.11 = [6 x i8] c"%02x \00"
define void @hexdump(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca [54 x i8]
%8 = alloca [17 x i8]
%9 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%10 = load i64, i64* %4
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i64, i64* %4
br label %17
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = call i64 @strlen(i8* %15)
br label %17
17: ; preds = %14, %12
%18 = phi i64 [ %13, %12 ], [ %16, %14 ]
store i64 %18, i64* %6
%19 = getelementptr inbounds [54 x i8], [54 x i8]* %7, i64 0, i64 0
store i8* %19, i8** %9
%20 = load i64, i64* %6
%21 = call i32 (i32, i8*, ...) @server_log(i32 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %20)
store i64 0, i64* %5
br label %22
22: ; preds = %140, %17
%23 = load i64, i64* %5
%24 = load i64, i64* %6
%25 = icmp ult i64 %23, %24
br i1 %25, label %26, label %143
26: ; preds = %22
%27 = load i64, i64* %5
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %39
29: ; preds = %26
%30 = load i64, i64* %5
%31 = urem i64 %30, 16
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = getelementptr inbounds [54 x i8], [54 x i8]* %7, i64 0, i64 0
%35 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%36 = call i32 (i32, i8*, ...) @server_log(i32 0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %34, i8* %35)
%37 = getelementptr inbounds [54 x i8], [54 x i8]* %7, i64 0, i64 0
store i8 0, i8* %37
%38 = getelementptr inbounds [54 x i8], [54 x i8]* %7, i64 0, i64 0
store i8* %38, i8** %9
br label %39
39: ; preds = %33, %29, %26
%40 = load i8*, i8** %3
%41 = load i64, i64* %5
%42 = getelementptr inbounds i8, i8* %40, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%46 = sext i8 %45 to i32
%47 = icmp sge i32 %44, %46
br i1 %47, label %48, label %57
48: ; preds = %39
%49 = load i8*, i8** %3
%50 = load i64, i64* %5
%51 = getelementptr inbounds i8, i8* %49, i64 %50
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
%55 = sext i8 %54 to i32
%56 = icmp sle i32 %53, %55
br i1 %56, label %111, label %57
57: ; preds = %48, %39
%58 = load i8*, i8** %3
%59 = load i64, i64* %5
%60 = getelementptr inbounds i8, i8* %58, i64 %59
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0)
%64 = sext i8 %63 to i32
%65 = icmp sge i32 %62, %64
br i1 %65, label %66, label %75
66: ; preds = %57
%67 = load i8*, i8** %3
%68 = load i64, i64* %5
%69 = getelementptr inbounds i8, i8* %67, i64 %68
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0)
%73 = sext i8 %72 to i32
%74 = icmp sle i32 %71, %73
br i1 %74, label %111, label %75
75: ; preds = %66, %57
%76 = load i8*, i8** %3
%77 = load i64, i64* %5
%78 = getelementptr inbounds i8, i8* %76, i64 %77
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0)
%82 = sext i8 %81 to i32
%83 = icmp eq i32 %80, %82
br i1 %83, label %111, label %84
84: ; preds = %75
%85 = load i8*, i8** %3
%86 = load i64, i64* %5
%87 = getelementptr inbounds i8, i8* %85, i64 %86
%88 = load i8, i8* %87
%89 = sext i8 %88 to i32
%90 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0)
%91 = sext i8 %90 to i32
%92 = icmp eq i32 %89, %91
br i1 %92, label %111, label %93
93: ; preds = %84
%94 = load i8*, i8** %3
%95 = load i64, i64* %5
%96 = getelementptr inbounds i8, i8* %94, i64 %95
%97 = load i8, i8* %96
%98 = sext i8 %97 to i32
%99 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0)
%100 = sext i8 %99 to i32
%101 = icmp sge i32 %98, %100
br i1 %101, label %102, label %119
102: ; preds = %93
%103 = load i8*, i8** %3
%104 = load i64, i64* %5
%105 = getelementptr inbounds i8, i8* %103, i64 %104
%106 = load i8, i8* %105
%107 = sext i8 %106 to i32
%108 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0)
%109 = sext i8 %108 to i32
%110 = icmp sle i32 %107, %109
br i1 %110, label %111, label %119
111: ; preds = %102, %84, %75, %66, %48
%112 = load i8*, i8** %3
%113 = load i64, i64* %5
%114 = getelementptr inbounds i8, i8* %112, i64 %113
%115 = load i8, i8* %114
%116 = load i64, i64* %5
%117 = urem i64 %116, 16
%118 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %117
store i8 %115, i8* %118
br label %124
119: ; preds = %102, %93
%120 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0)
%121 = load i64, i64* %5
%122 = urem i64 %121, 16
%123 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %122
store i8 %120, i8* %123
br label %124
124: ; preds = %119, %111
%125 = load i64, i64* %5
%126 = urem i64 %125, 16
%127 = add i64 %126, 1
%128 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %127
store i8 0, i8* %128
%129 = load i8*, i8** %9
%130 = load i8*, i8** %3
%131 = load i64, i64* %5
%132 = getelementptr inbounds i8, i8* %130, i64 %131
%133 = load i8, i8* %132
%134 = sext i8 %133 to i32
%135 = and i32 %134, 255
%136 = trunc i32 %135 to i8
%137 = call i32 @sprintf(i8* %129, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i8 signext %136)
%138 = load i8*, i8** %9
%139 = getelementptr inbounds i8, i8* %138, i64 3
store i8* %139, i8** %9
br label %140
140: ; preds = %124
%141 = load i64, i64* %5
%142 = add i64 %141, 1
store i64 %142, i64* %5
br label %22
143: ; preds = %22
%144 = load i64, i64* %5
%145 = urem i64 %144, 16
%146 = icmp ne i64 %145, 0
br i1 %146, label %147, label %151
147: ; preds = %143
%148 = getelementptr inbounds [54 x i8], [54 x i8]* %7, i64 0, i64 0
%149 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%150 = call i32 (i32, i8*, ...) @server_log(i32 0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %148, i8* %149)
br label %151
151: ; preds = %147, %143
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"HEXDUMP size: %d\00"
@.str.1 = [6 x i8] c"%s\09%s\00"
@.str.11 = [6 x i8] c"%02x \00"
define void @hexdump(i8* nocapture %0, i64 %1) {
%3 = alloca [54 x i8]
%4 = alloca [17 x i8]
%5 = icmp eq i64 %1, 0
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%9 = tail call i32 (i32, i8*, ...) @server_log(i32 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %1)
br label %16
10: ; preds = %2
%11 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%12 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 0
%13 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%14 = tail call i32 (i32, i8*, ...) @server_log(i32 0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %11)
%15 = icmp eq i64 %11, 0
br i1 %15, label %55, label %16
16: ; preds = %6, %10
%17 = phi i64 [ %1, %6 ], [ %11, %10 ]
%18 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 0
%19 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
br label %20
20: ; preds = %16, %41
%21 = phi i8* [ %47, %41 ], [ %18, %16 ]
%22 = phi i64 [ %48, %41 ], [ 0, %16 ]
%23 = icmp ne i64 %22, 0
%24 = and i64 %22, 15
%25 = icmp eq i64 %24, 0
%26 = and i1 %23, %25
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = call i32 (i32, i8*, ...) @server_log(i32 0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %18, i8* %19)
store i8 0, i8* %18
br label %29
29: ; preds = %27, %20
%30 = phi i8* [ %18, %27 ], [ %21, %20 ]
%31 = getelementptr inbounds i8, i8* %0, i64 %22
%32 = load i8, i8* %31
%33 = and i8 %32, -33
%34 = add i8 %33, -65
%35 = icmp ult i8 %34, 26
br i1 %35, label %41, label %36
36: ; preds = %29
switch i8 %32, label %37 [
i8 91, label %41
i8 93, label %41
]
37: ; preds = %36
%38 = add i8 %32, -48
%39 = icmp ult i8 %38, 10
%40 = select i1 %39, i8 %32, i8 46
br label %41
41: ; preds = %37, %29, %36, %36
%42 = phi i8 [ %32, %36 ], [ %32, %36 ], [ %32, %29 ], [ %40, %37 ]
%43 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 %24
store i8 %42, i8* %43
%44 = add nuw nsw i64 %24, 1
%45 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 %44
store i8 0, i8* %45
%46 = call i32 @sprintf(i8* dereferenceable(1) %30, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i8 signext %32)
%47 = getelementptr inbounds i8, i8* %30, i64 3
%48 = add nuw i64 %22, 1
%49 = icmp eq i64 %48, %17
br i1 %49, label %50, label %20
50: ; preds = %41
%51 = and i64 %17, 15
%52 = icmp eq i64 %51, 0
br i1 %52, label %55, label %53
53: ; preds = %50
%54 = call i32 (i32, i8*, ...) @server_log(i32 0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %18, i8* %19)
br label %55
55: ; preds = %10, %53, %50
%56 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%57 = getelementptr inbounds [54 x i8], [54 x i8]* %3, i64 0, i64 0
ret void
}