#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 flags;

/* Variables and functions */
int /*<<< orphan*/ die(char *, size_t);
int /*<<< orphan*/ hexdump_16bit(void const *, int, size_t);
int /*<<< orphan*/ hexdump_32bit(void const *, int, size_t);
int /*<<< orphan*/ hexdump_8bit(void const *, int, size_t);
int /*<<< orphan*/ hexdump_addr(unsigned long);
int /*<<< orphan*/ hexdump_ascii(void const *, int, size_t);
int /*<<< orphan*/ hexdump_bin(void const *, int, size_t);
int /*<<< orphan*/ hexdump_eol();
void __hexdump(unsigned long base, const void *data, size_t length,
               size_t flags) {
  size_t count;
  int nleft;
  count = ((flags)&0xFF);
  if (count == 0)
    count = 16;
  if (count > 32)
    count = 32;
  if ((flags & (0x8000 | 0x4000 | 0x2000 | 0x10000)) == 0)
    flags |= 0x2000;
  if ((((flags) & (0x8000 | 0x4000 | 0x2000 | 0x10000)) == (0x10000)))
    count = 4;
  while (length > 0) {
    nleft = length > count ? count : length;
    hexdump_addr(base);
    if ((((flags) & (0x8000 | 0x4000 | 0x2000 | 0x10000)) == (0x10000))) {
      hexdump_bin(data, nleft, count);
    } else if ((((flags) & (0x8000 | 0x4000 | 0x2000 | 0x10000)) == (0x2000))) {
      hexdump_8bit(data, nleft, count);
    } else if ((((flags) & (0x8000 | 0x4000 | 0x2000 | 0x10000)) == (0x4000))) {
      hexdump_16bit(data, nleft, count);
    } else if ((((flags) & (0x8000 | 0x4000 | 0x2000 | 0x10000)) == (0x8000))) {
      hexdump_32bit(data, nleft, count);
    } else {
      die("__hexdump(): invalid %0zX flags given", flags);
    }
    if (flags & 0x1000) {
      hexdump_ascii(data, nleft, count);
    }
    hexdump_eol();
    length -= nleft;
    data += count;
    base += count;
  }
}


x86 assembly (clang, -O0):
<__hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
and    $0xff,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b9 <__hexdump+0x39>
movq   $0x10,-0x28(%rbp)
cmpq   $0x20,-0x28(%rbp)
jbe    11cc <__hexdump+0x4c>
movq   $0x20,-0x28(%rbp)
mov    -0x20(%rbp),%rax
and    $0x1e000,%rax
cmp    $0x0,%rax
jne    11ee <__hexdump+0x6e>
mov    -0x20(%rbp),%rax
or     $0x2000,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
and    $0x1e000,%rax
cmp    $0x10000,%rax
jne    120c <__hexdump+0x8c>
movq   $0x4,-0x28(%rbp)
jmp    1211 <__hexdump+0x91>
cmpq   $0x0,-0x18(%rbp)
jbe    1371 <__hexdump+0x1f1>
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    1237 <__hexdump+0xb7>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    123f <__hexdump+0xbf>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <hexdump_addr@plt>
mov    -0x20(%rbp),%rax
and    $0x1e000,%rax
cmp    $0x10000,%rax
jne    127a <__hexdump+0xfa>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1030 <hexdump_bin@plt>
jmp    131a <__hexdump+0x19a>
mov    -0x20(%rbp),%rax
and    $0x1e000,%rax
cmp    $0x2000,%rax
jne    12a5 <__hexdump+0x125>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1040 <hexdump_8bit@plt>
jmp    1315 <__hexdump+0x195>
mov    -0x20(%rbp),%rax
and    $0x1e000,%rax
cmp    $0x4000,%rax
jne    12d0 <__hexdump+0x150>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1050 <hexdump_16bit@plt>
jmp    1310 <__hexdump+0x190>
mov    -0x20(%rbp),%rax
and    $0x1e000,%rax
cmp    $0x8000,%rax
jne    12fb <__hexdump+0x17b>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   10a0 <hexdump_32bit@plt>
jmp    130b <__hexdump+0x18b>
mov    -0x20(%rbp),%rsi
lea    0xcfa(%rip),%rdi
call   1080 <die@plt>
jmp    1310 <__hexdump+0x190>
jmp    1315 <__hexdump+0x195>
jmp    131a <__hexdump+0x19a>
mov    -0x20(%rbp),%rax
and    $0x1000,%rax
cmp    $0x0,%rax
je     133e <__hexdump+0x1be>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1090 <hexdump_ascii@plt>
mov    $0x0,%al
call   1060 <hexdump_eol@plt>
movslq -0x2c(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1211 <__hexdump+0x91>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
movzbl %cl,%eax
test   %rax,%rax
mov    $0x10,%edx
cmovne %rax,%rdx
cmp    $0x20,%rdx
mov    $0x20,%eax
cmovb  %rdx,%rax
mov    %rcx,%r12
or     $0x2000,%r12
test   $0x1e000,%ecx
cmovne %rcx,%r12
mov    %r12,%rcx
mov    %r12,(%rsp)
and    $0x1e000,%r12d
cmp    $0x10000,%r12
mov    $0x4,%r13d
cmovne %rax,%r13
test   %rbx,%rbx
je     12e2 <__hexdump+0x162>
mov    %rsi,%r14
mov    %rdi,%r15
jmp    1206 <__hexdump+0x86>
xchg   %ax,%ax
xor    %eax,%eax
call   1060 <hexdump_eol@plt>
add    %r13,%r14
add    %r13,%r15
sub    %rbp,%rbx
je     12e2 <__hexdump+0x162>
cmp    %r13,%rbx
mov    %rbx,%rbp
cmova  %r13,%rbp
mov    %r15,%rdi
call   1070 <hexdump_addr@plt>
cmp    $0x10000,%r12d
jne    1240 <__hexdump+0xc0>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r13,%rdx
call   1030 <hexdump_bin@plt>
testl  $0x1000,(%rsp)
je     11f0 <__hexdump+0x70>
jmp    12d0 <__hexdump+0x150>
nopl   0x0(%rax)
cmp    $0x8000,%r12d
je     1293 <__hexdump+0x113>
cmp    $0x4000,%r12d
je     1277 <__hexdump+0xf7>
cmp    $0x2000,%r12d
jne    12af <__hexdump+0x12f>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r13,%rdx
call   1040 <hexdump_8bit@plt>
testl  $0x1000,(%rsp)
je     11f0 <__hexdump+0x70>
jmp    12d0 <__hexdump+0x150>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r13,%rdx
call   1050 <hexdump_16bit@plt>
testl  $0x1000,(%rsp)
je     11f0 <__hexdump+0x70>
jmp    12d0 <__hexdump+0x150>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r13,%rdx
call   10a0 <hexdump_32bit@plt>
testl  $0x1000,(%rsp)
je     11f0 <__hexdump+0x70>
jmp    12d0 <__hexdump+0x150>
lea    0xd4a(%rip),%rdi
mov    (%rsp),%rsi
call   1080 <die@plt>
testl  $0x1000,(%rsp)
je     11f0 <__hexdump+0x70>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r13,%rdx
call   1090 <hexdump_ascii@plt>
jmp    11f0 <__hexdump+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"__hexdump(): invalid %0zX flags given\00"
define void @__hexdump(i64 %0, i8* %1, i64 %2, i64 %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
store i64 %0, i64* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%11 = load i64, i64* %8
%12 = and i64 %11, 255
store i64 %12, i64* %9
%13 = load i64, i64* %9
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %4
store i64 16, i64* %9
br label %16
16: ; preds = %15, %4
%17 = load i64, i64* %9
%18 = icmp ugt i64 %17, 32
br i1 %18, label %19, label %20
19: ; preds = %16
store i64 32, i64* %9
br label %20
20: ; preds = %19, %16
%21 = load i64, i64* %8
%22 = and i64 %21, 122880
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i64, i64* %8
%26 = or i64 %25, 8192
store i64 %26, i64* %8
br label %27
27: ; preds = %24, %20
%28 = load i64, i64* %8
%29 = and i64 %28, 122880
%30 = icmp eq i64 %29, 65536
br i1 %30, label %31, label %32
31: ; preds = %27
store i64 4, i64* %9
br label %32
32: ; preds = %31, %27
br label %33
33: ; preds = %99, %32
%34 = load i64, i64* %7
%35 = icmp ugt i64 %34, 0
br i1 %35, label %36, label %111
36: ; preds = %33
%37 = load i64, i64* %7
%38 = load i64, i64* %9
%39 = icmp ugt i64 %37, %38
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = load i64, i64* %9
br label %44
42: ; preds = %36
%43 = load i64, i64* %7
br label %44
44: ; preds = %42, %40
%45 = phi i64 [ %41, %40 ], [ %43, %42 ]
%46 = trunc i64 %45 to i32
store i32 %46, i32* %10
%47 = load i64, i64* %5
%48 = call i32 @hexdump_addr(i64 %47)
%49 = load i64, i64* %8
%50 = and i64 %49, 122880
%51 = icmp eq i64 %50, 65536
br i1 %51, label %52, label %57
52: ; preds = %44
%53 = load i8*, i8** %6
%54 = load i32, i32* %10
%55 = load i64, i64* %9
%56 = call i32 @hexdump_bin(i8* %53, i32 %54, i64 %55)
br label %90
57: ; preds = %44
%58 = load i64, i64* %8
%59 = and i64 %58, 122880
%60 = icmp eq i64 %59, 8192
br i1 %60, label %61, label %66
61: ; preds = %57
%62 = load i8*, i8** %6
%63 = load i32, i32* %10
%64 = load i64, i64* %9
%65 = call i32 @hexdump_8bit(i8* %62, i32 %63, i64 %64)
br label %89
66: ; preds = %57
%67 = load i64, i64* %8
%68 = and i64 %67, 122880
%69 = icmp eq i64 %68, 16384
br i1 %69, label %70, label %75
70: ; preds = %66
%71 = load i8*, i8** %6
%72 = load i32, i32* %10
%73 = load i64, i64* %9
%74 = call i32 @hexdump_16bit(i8* %71, i32 %72, i64 %73)
br label %88
75: ; preds = %66
%76 = load i64, i64* %8
%77 = and i64 %76, 122880
%78 = icmp eq i64 %77, 32768
br i1 %78, label %79, label %84
79: ; preds = %75
%80 = load i8*, i8** %6
%81 = load i32, i32* %10
%82 = load i64, i64* %9
%83 = call i32 @hexdump_32bit(i8* %80, i32 %81, i64 %82)
br label %87
84: ; preds = %75
%85 = load i64, i64* %8
%86 = call i32 @die(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i64 %85)
br label %87
87: ; preds = %84, %79
br label %88
88: ; preds = %87, %70
br label %89
89: ; preds = %88, %61
br label %90
90: ; preds = %89, %52
%91 = load i64, i64* %8
%92 = and i64 %91, 4096
%93 = icmp ne i64 %92, 0
br i1 %93, label %94, label %99
94: ; preds = %90
%95 = load i8*, i8** %6
%96 = load i32, i32* %10
%97 = load i64, i64* %9
%98 = call i32 @hexdump_ascii(i8* %95, i32 %96, i64 %97)
br label %99
99: ; preds = %94, %90
%100 = call i32 (...) @hexdump_eol()
%101 = load i32, i32* %10
%102 = sext i32 %101 to i64
%103 = load i64, i64* %7
%104 = sub i64 %103, %102
store i64 %104, i64* %7
%105 = load i64, i64* %9
%106 = load i8*, i8** %6
%107 = getelementptr i8, i8* %106, i64 %105
store i8* %107, i8** %6
%108 = load i64, i64* %9
%109 = load i64, i64* %5
%110 = add i64 %109, %108
store i64 %110, i64* %5
br label %33
111: ; preds = %33
ret void
}

LLVM IR (-O2):
@.str = [38 x i8] c"__hexdump(): invalid %0zX flags given\00"
define void @__hexdump(i64 %0, i8* %1, i64 %2, i64 %3) {
%5 = and i64 %3, 255
%6 = icmp eq i64 %5, 0
%7 = select i1 %6, i64 16, i64 %5
%8 = icmp ult i64 %7, 32
%9 = select i1 %8, i64 %7, i64 32
%10 = and i64 %3, 122880
%11 = icmp eq i64 %10, 0
%12 = or i64 %3, 8192
%13 = select i1 %11, i64 %12, i64 %3
%14 = and i64 %13, 122880
%15 = icmp eq i64 %14, 65536
%16 = select i1 %15, i64 4, i64 %9
%17 = icmp eq i64 %2, 0
br i1 %17, label %49, label %18
18: ; preds = %4
%19 = and i64 %13, 4096
%20 = icmp eq i64 %19, 0
br label %21
21: ; preds = %18, %43
%22 = phi i64 [ %0, %18 ], [ %47, %43 ]
%23 = phi i64 [ %2, %18 ], [ %45, %43 ]
%24 = phi i8* [ %1, %18 ], [ %46, %43 ]
%25 = icmp ugt i64 %23, %16
%26 = select i1 %25, i64 %16, i64 %23
%27 = trunc i64 %26 to i32
%28 = tail call i32 @hexdump_addr(i64 %22)
br i1 %15, label %29, label %31
29: ; preds = %21
%30 = tail call i32 @hexdump_bin(i8* %24, i32 %27, i64 %16)
br label %40
31: ; preds = %21
switch i64 %14, label %38 [
i64 8192, label %32
i64 16384, label %34
i64 32768, label %36
]
32: ; preds = %31
%33 = tail call i32 @hexdump_8bit(i8* %24, i32 %27, i64 %16)
br label %40
34: ; preds = %31
%35 = tail call i32 @hexdump_16bit(i8* %24, i32 %27, i64 %16)
br label %40
36: ; preds = %31
%37 = tail call i32 @hexdump_32bit(i8* %24, i32 %27, i64 %16)
br label %40
38: ; preds = %31
%39 = tail call i32 @die(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i64 %13)
br label %40
40: ; preds = %32, %36, %38, %34, %29
br i1 %20, label %43, label %41
41: ; preds = %40
%42 = tail call i32 @hexdump_ascii(i8* %24, i32 %27, i64 %16)
br label %43
43: ; preds = %41, %40
%44 = tail call i32 (...) @hexdump_eol()
%45 = sub i64 %23, %26
%46 = getelementptr i8, i8* %24, i64 %16
%47 = add i64 %22, %16
%48 = icmp eq i64 %45, 0
br i1 %48, label %49, label %21
49: ; preds = %43, %4
ret void
}