#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*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ syslog(int, char *, char *);
void hexdump(int level, const void *mem, int length) {
  char line[80];
  char *src = (char *)mem;
  unsigned i, j;
  if (length <= 0)
    return;
  for (i = 0; i < length; i += 16, src += 16) {
    char *t = line;
    t += sprintf(t, "%04x:  ", i);
    for (j = 0; j < 16; j++) {
      if (i + j < length)
        t += sprintf(t, "%02X", src[j] & 0xff);
      else
        t += sprintf(t, "  ");
      t += sprintf(t, j % 2 ? " " : "-");
    }
    syslog(level, "%s", line);
  }
  return;
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x78(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     114c <hexdump+0x2c>
jmp    12a3 <hexdump+0x183>
movl   $0x0,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    129e <hexdump+0x17e>
lea    -0x70(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rdi
mov    -0x7c(%rbp),%edx
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x88(%rbp)
movl   $0x0,-0x80(%rbp)
cmpl   $0x10,-0x80(%rbp)
jae    1271 <hexdump+0x151>
mov    -0x7c(%rbp),%eax
add    -0x80(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11f9 <hexdump+0xd9>
mov    -0x88(%rbp),%rdi
mov    -0x78(%rbp),%rax
mov    -0x80(%rbp),%ecx
movsbl (%rax,%rcx,1),%edx
and    $0xff,%edx
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x88(%rbp)
jmp    1224 <hexdump+0x104>
mov    -0x88(%rbp),%rdi
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rdi
mov    -0x80(%rbp),%ecx
and    $0x1,%ecx
lea    0xdd5(%rip),%rsi
lea    0xdc7(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x88(%rbp)
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    119f <hexdump+0x7f>
mov    -0x4(%rbp),%edi
lea    -0x70(%rbp),%rdx
lea    0xd90(%rip),%rsi
call   1030 <syslog@plt>
mov    -0x7c(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x7c(%rbp)
mov    -0x78(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x78(%rbp)
jmp    1153 <hexdump+0x33>
jmp    12a3 <hexdump+0x183>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %edi,0xc(%rsp)
mov    %edx,0x8(%rsp)
test   %edx,%edx
jle    1215 <hexdump+0xf5>
mov    %rsi,%rbx
mov    0x8(%rsp),%r14d
lea    0x10(%rsp),%r15
lea    0xeb4(%rip),%r13
xor    %edx,%edx
jmp    118b <hexdump+0x6b>
cs nopw 0x0(%rax,%rax,1)
mov    0xc(%rsp),%edi
lea    0xea4(%rip),%rsi
lea    0x10(%rsp),%r15
mov    %r15,%rdx
call   1030 <syslog@plt>
add    $0x10,%ebp
add    $0x10,%rbx
mov    %ebp,%edx
cmp    0x8(%rsp),%ebp
jae    1215 <hexdump+0xf5>
mov    %edx,%ebp
mov    %r15,%rdi
lea    0xe69(%rip),%rsi
xor    %eax,%eax
call   1040 <sprintf@plt>
cltq
lea    (%rsp,%rax,1),%r15
add    $0x10,%r15
xor    %r12d,%r12d
jmp    11f2 <hexdump+0xd2>
nopl   (%rax)
movb   $0x0,0x2(%r15)
movw   $0x2020,(%r15)
mov    $0x2,%eax
add    %rax,%r15
test   $0x1,%r12b
mov    %r13,%rsi
lea    0xe3c(%rip),%rax
cmove  %rax,%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <sprintf@plt>
cltq
add    %rax,%r15
add    $0x1,%r12
cmp    $0x10,%r12
je     1160 <hexdump+0x40>
lea    (%r12,%rbp,1),%rax
cmp    %r14,%rax
jae    11b0 <hexdump+0x90>
movzbl (%rbx,%r12,1),%edx
mov    %r15,%rdi
lea    0xdfe(%rip),%rsi
xor    %eax,%eax
call   1040 <sprintf@plt>
cltq
jmp    11c0 <hexdump+0xa0>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%04x: \00"
@.str.1 = [5 x i8] c"%02X\00"
@.str.2 = [3 x i8] c" \00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [2 x i8] c"-\00"
@.str.5 = [3 x i8] c"%s\00"
define void @hexdump(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [80 x i8]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%12 = load i8*, i8** %5
store i8* %12, i8** %8
%13 = load i32, i32* %6
%14 = icmp sle i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
br label %81
16: ; preds = %3
store i32 0, i32* %9
br label %17
17: ; preds = %75, %16
%18 = load i32, i32* %9
%19 = load i32, i32* %6
%20 = icmp ult i32 %18, %19
br i1 %20, label %21, label %80
21: ; preds = %17
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
store i8* %22, i8** %11
%23 = load i8*, i8** %11
%24 = load i32, i32* %9
%25 = call i32 (i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i8*, i8** %11
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds i8, i8* %26, i64 %27
store i8* %28, i8** %11
store i32 0, i32* %10
br label %29
29: ; preds = %68, %21
%30 = load i32, i32* %10
%31 = icmp ult i32 %30, 16
br i1 %31, label %32, label %71
32: ; preds = %29
%33 = load i32, i32* %9
%34 = load i32, i32* %10
%35 = add i32 %33, %34
%36 = load i32, i32* %6
%37 = icmp ult i32 %35, %36
br i1 %37, label %38, label %51
38: ; preds = %32
%39 = load i8*, i8** %11
%40 = load i8*, i8** %8
%41 = load i32, i32* %10
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = and i32 %45, 255
%47 = call i32 (i8*, i8*, ...) @sprintf(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = load i8*, i8** %11
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds i8, i8* %48, i64 %49
store i8* %50, i8** %11
br label %57
51: ; preds = %32
%52 = load i8*, i8** %11
%53 = call i32 (i8*, i8*, ...) @sprintf(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%54 = load i8*, i8** %11
%55 = sext i32 %53 to i64
%56 = getelementptr inbounds i8, i8* %54, i64 %55
store i8* %56, i8** %11
br label %57
57: ; preds = %51, %38
%58 = load i8*, i8** %11
%59 = load i32, i32* %10
%60 = urem i32 %59, 2
%61 = icmp ne i32 %60, 0
%62 = zext i1 %61 to i64
%63 = select i1 %61, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0)
%64 = call i32 (i8*, i8*, ...) @sprintf(i8* %58, i8* %63)
%65 = load i8*, i8** %11
%66 = sext i32 %64 to i64
%67 = getelementptr inbounds i8, i8* %65, i64 %66
store i8* %67, i8** %11
br label %68
68: ; preds = %57
%69 = load i32, i32* %10
%70 = add i32 %69, 1
store i32 %70, i32* %10
br label %29
71: ; preds = %29
%72 = load i32, i32* %4
%73 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%74 = call i32 @syslog(i32 %72, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %73)
br label %75
75: ; preds = %71
%76 = load i32, i32* %9
%77 = add i32 %76, 16
store i32 %77, i32* %9
%78 = load i8*, i8** %8
%79 = getelementptr inbounds i8, i8* %78, i64 16
store i8* %79, i8** %8
br label %17
80: ; preds = %17
br label %81
81: ; preds = %80, %15
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%04x: \00"
@.str.1 = [5 x i8] c"%02X\00"
@.str.2 = [3 x i8] c" \00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [2 x i8] c"-\00"
@.str.5 = [3 x i8] c"%s\00"
define void @hexdump(i32 %0, i8* nocapture %1, i32 %2) {
%4 = alloca [80 x i8]
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %44
7: ; preds = %3
%8 = zext i32 %2 to i64
br label %9
9: ; preds = %7, %39
%10 = phi i32 [ %41, %39 ], [ 0, %7 ]
%11 = phi i8* [ %42, %39 ], [ %1, %7 ]
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %10)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %13
%15 = zext i32 %10 to i64
br label %16
16: ; preds = %9, %28
%17 = phi i64 [ 0, %9 ], [ %37, %28 ]
%18 = phi i8* [ %14, %9 ], [ %36, %28 ]
%19 = add nuw nsw i64 %17, %15
%20 = icmp ult i64 %19, %8
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = getelementptr inbounds i8, i8* %11, i64 %17
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %18, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = sext i32 %25 to i64
br label %28
27: ; preds = %16
br label %28
28: ; preds = %27, %21
%29 = phi i64 [ 2, %27 ], [ %26, %21 ]
%30 = getelementptr inbounds i8, i8* %18, i64 %29
%31 = and i64 %17, 1
%32 = icmp eq i64 %31, 0
%33 = select i1 %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
%34 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %30, i8* dereferenceable(1) %33)
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %30, i64 %35
%37 = add nuw nsw i64 %17, 1
%38 = icmp eq i64 %37, 16
br i1 %38, label %39, label %16
39: ; preds = %28
%40 = call i32 @syslog(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %5)
%41 = add i32 %10, 16
%42 = getelementptr inbounds i8, i8* %11, i64 16
%43 = icmp ult i32 %41, %2
br i1 %43, label %9, label %44
44: ; preds = %39, %3
ret void
}