#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 *, ...);
int /*<<< orphan*/ isascii(char);
int /*<<< orphan*/ isprint(char);
void dumphex(FILE *f, char *buf, int len) {
  int i, j;
  char c;
  for (i = 0; i < len; i++) {
    fprintf(f, "%02x", buf[i] & 0xff);
    if (i % 2 == 1)
      fprintf(f, " ");
    if (i % 16 == 15) {
      fprintf(f, " ");
      for (j = 15; j >= 0; j--) {
        c = buf[i - j];
        fprintf(f, "%c", (!isascii(c) || !isprint(c) ? '.' : c));
      }
      fprintf(f, "\n");
    }
  }
  for (j = i % 16; j < 16; j++) {
    fprintf(f, "  ");
    if (j % 2 == 1)
      fprintf(f, " ");
  }
  fprintf(f, " ");
  for (j = len - (i % 16); j < len; j++) {
    c = buf[j];
    fprintf(f, "%c", (!isascii(c) || !isprint(c) ? '.' : c));
  }
  fprintf(f, "\n");
}


x86 assembly (clang, -O0):
<dumphex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1272 <dumphex+0x142>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
and    $0xff,%edx
lea    0xe8d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    11a0 <dumphex+0x70>
mov    -0x8(%rbp),%rdi
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
jne    125f <dumphex+0x12f>
mov    -0x8(%rbp),%rdi
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xf,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     124d <dumphex+0x11d>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movsbl -0x1d(%rbp),%edi
call   1050 <isascii@plt>
cmp    $0x0,%eax
je     1216 <dumphex+0xe6>
movsbl -0x1d(%rbp),%edi
call   1040 <isprint@plt>
cmp    $0x0,%eax
jne    1223 <dumphex+0xf3>
mov    $0x2e,%eax
mov    %eax,-0x2c(%rbp)
jmp    122a <dumphex+0xfa>
movsbl -0x1d(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xdcd(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11cd <dumphex+0x9d>
mov    -0x8(%rbp),%rdi
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1264 <dumphex+0x134>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114a <dumphex+0x1a>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jge    12d5 <dumphex+0x1a5>
mov    -0x8(%rbp),%rdi
lea    0xd75(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    12c2 <dumphex+0x192>
mov    -0x8(%rbp),%rdi
lea    0xd50(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12c7 <dumphex+0x197>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1280 <dumphex+0x150>
mov    -0x8(%rbp),%rdi
lea    0xd2b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    -0x30(%rbp),%eax
sub    %edx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    137d <dumphex+0x24d>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
movsbl -0x1d(%rbp),%edi
call   1050 <isascii@plt>
cmp    $0x0,%eax
je     1346 <dumphex+0x216>
movsbl -0x1d(%rbp),%edi
call   1040 <isprint@plt>
cmp    $0x0,%eax
jne    1353 <dumphex+0x223>
mov    $0x2e,%eax
mov    %eax,-0x3c(%rbp)
jmp    135a <dumphex+0x22a>
movsbl -0x1d(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%edx
lea    0xc9d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1300 <dumphex+0x1d0>
mov    -0x8(%rbp),%rdi
lea    0xc80(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dumphex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r13
mov    %rdi,%rbx
test   %edx,%edx
mov    %edx,0xc(%rsp)
jle    1236 <dumphex+0xe6>
mov    %edx,%r15d
mov    %r13,%r14
xor    %r12d,%r12d
mov    %r13,0x10(%rsp)
jmp    11a3 <dumphex+0x53>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
mov    0x10(%rsp),%r13
add    $0x1,%r12
add    $0x1,%r14
cmp    %r15,%r12
je     122b <dumphex+0xdb>
movzbl 0x0(%r13,%r12,1),%edx
mov    %rbx,%rdi
lea    0xe4d(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
test   $0x1,%r12b
je     11cd <dumphex+0x7d>
mov    $0x20,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
mov    %r12d,%eax
not    %eax
test   $0xf,%al
jne    1192 <dumphex+0x42>
mov    $0x20,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
mov    $0xfffffffffffffff0,%r13
jmp    1206 <dumphex+0xb6>
nopl   0x0(%rax)
mov    $0x2e,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
inc    %r13
je     1180 <dumphex+0x30>
movsbl 0x1(%r14,%r13,1),%ebp
mov    %ebp,%edi
call   1060 <isascii@plt>
test   %eax,%eax
je     11f0 <dumphex+0xa0>
mov    %ebp,%edi
call   1050 <isprint@plt>
mov    $0x2e,%edi
test   %eax,%eax
je     11f5 <dumphex+0xa5>
mov    %ebp,%edi
jmp    11f5 <dumphex+0xa5>
mov    0xc(%rsp),%r14d
and    $0xf,%r14d
jmp    1239 <dumphex+0xe9>
xor    %r14d,%r14d
lea    0xdc5(%rip),%r12
mov    %r14d,%ebp
jmp    1258 <dumphex+0x108>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
cmp    $0x10,%ebp
je     1282 <dumphex+0x132>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r12,%rdi
mov    %rbx,%rcx
call   1070 <fwrite@plt>
test   $0x1,%bpl
je     1250 <dumphex+0x100>
mov    $0x20,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
jmp    1250 <dumphex+0x100>
mov    $0x20,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
test   %r14d,%r14d
je     12ee <dumphex+0x19e>
mov    0xc(%rsp),%eax
movslq %eax,%r12
sub    %r14d,%eax
movslq %eax,%rbp
jmp    12c6 <dumphex+0x176>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x2e,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
add    $0x1,%rbp
cmp    %r12,%rbp
jge    12ee <dumphex+0x19e>
movsbl 0x0(%r13,%rbp,1),%r14d
mov    %r14d,%edi
call   1060 <isascii@plt>
test   %eax,%eax
je     12b0 <dumphex+0x160>
mov    %r14d,%edi
call   1050 <isprint@plt>
mov    $0x2e,%edi
test   %eax,%eax
je     12b5 <dumphex+0x165>
mov    %r14d,%edi
jmp    12b5 <dumphex+0x165>
mov    $0xa,%edi
mov    %rbx,%rsi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fputc@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%02x\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [3 x i8] c" \00"
define void @dumphex(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %10
10: ; preds = %70, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %73
14: ; preds = %10
%15 = load i32*, i32** %4
%16 = load i8*, i8** %5
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = and i32 %21, 255
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %7
%25 = srem i32 %24, 2
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %30
27: ; preds = %14
%28 = load i32*, i32** %4
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %27, %14
%31 = load i32, i32* %7
%32 = srem i32 %31, 16
%33 = icmp eq i32 %32, 15
br i1 %33, label %34, label %69
34: ; preds = %30
%35 = load i32*, i32** %4
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 15, i32* %8
br label %37
37: ; preds = %63, %34
%38 = load i32, i32* %8
%39 = icmp sge i32 %38, 0
br i1 %39, label %40, label %66
40: ; preds = %37
%41 = load i8*, i8** %5
%42 = load i32, i32* %7
%43 = load i32, i32* %8
%44 = sub nsw i32 %42, %43
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %41, i64 %45
%47 = load i8, i8* %46
store i8 %47, i8* %9
%48 = load i32*, i32** %4
%49 = load i8, i8* %9
%50 = call i32 @isascii(i8 signext %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %40
%53 = load i8, i8* %9
%54 = call i32 @isprint(i8 signext %53)
%55 = icmp ne i32 %54, 0
br i1 %55, label %57, label %56
56: ; preds = %52, %40
br label %60
57: ; preds = %52
%58 = load i8, i8* %9
%59 = sext i8 %58 to i32
br label %60
60: ; preds = %57, %56
%61 = phi i32 [ 46, %56 ], [ %59, %57 ]
%62 = call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %60
%64 = load i32, i32* %8
%65 = add nsw i32 %64, -1
store i32 %65, i32* %8
br label %37
66: ; preds = %37
%67 = load i32*, i32** %4
%68 = call i32 (i32*, i8*, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %69
69: ; preds = %66, %30
br label %70
70: ; preds = %69
%71 = load i32, i32* %7
%72 = add nsw i32 %71, 1
store i32 %72, i32* %7
br label %10
73: ; preds = %10
%74 = load i32, i32* %7
%75 = srem i32 %74, 16
store i32 %75, i32* %8
br label %76
76: ; preds = %89, %73
%77 = load i32, i32* %8
%78 = icmp slt i32 %77, 16
br i1 %78, label %79, label %92
79: ; preds = %76
%80 = load i32*, i32** %4
%81 = call i32 (i32*, i8*, ...) @fprintf(i32* %80, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%82 = load i32, i32* %8
%83 = srem i32 %82, 2
%84 = icmp eq i32 %83, 1
br i1 %84, label %85, label %88
85: ; preds = %79
%86 = load i32*, i32** %4
%87 = call i32 (i32*, i8*, ...) @fprintf(i32* %86, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %88
88: ; preds = %85, %79
br label %89
89: ; preds = %88
%90 = load i32, i32* %8
%91 = add nsw i32 %90, 1
store i32 %91, i32* %8
br label %76
92: ; preds = %76
%93 = load i32*, i32** %4
%94 = call i32 (i32*, i8*, ...) @fprintf(i32* %93, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%95 = load i32, i32* %6
%96 = load i32, i32* %7
%97 = srem i32 %96, 16
%98 = sub nsw i32 %95, %97
store i32 %98, i32* %8
br label %99
99: ; preds = %124, %92
%100 = load i32, i32* %8
%101 = load i32, i32* %6
%102 = icmp slt i32 %100, %101
br i1 %102, label %103, label %127
103: ; preds = %99
%104 = load i8*, i8** %5
%105 = load i32, i32* %8
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i8, i8* %104, i64 %106
%108 = load i8, i8* %107
store i8 %108, i8* %9
%109 = load i32*, i32** %4
%110 = load i8, i8* %9
%111 = call i32 @isascii(i8 signext %110)
%112 = icmp ne i32 %111, 0
br i1 %112, label %113, label %117
113: ; preds = %103
%114 = load i8, i8* %9
%115 = call i32 @isprint(i8 signext %114)
%116 = icmp ne i32 %115, 0
br i1 %116, label %118, label %117
117: ; preds = %113, %103
br label %121
118: ; preds = %113
%119 = load i8, i8* %9
%120 = sext i8 %119 to i32
br label %121
121: ; preds = %118, %117
%122 = phi i32 [ 46, %117 ], [ %120, %118 ]
%123 = call i32 (i32*, i8*, ...) @fprintf(i32* %109, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %122)
br label %124
124: ; preds = %121
%125 = load i32, i32* %8
%126 = add nsw i32 %125, 1
store i32 %126, i32* %8
br label %99
127: ; preds = %99
%128 = load i32*, i32** %4
%129 = call i32 (i32*, i8*, ...) @fprintf(i32* %128, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
@.str.4 = [3 x i8] c" \00"
define void @dumphex(i32* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %47
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %42
%8 = phi i64 [ 0, %5 ], [ %43, %42 ]
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = trunc i64 %8 to i32
%14 = and i32 %13, 1
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %7
%17 = tail call i32 @fputc(i32 32, i32* %0)
br label %18
18: ; preds = %16, %7
%19 = and i32 %13, 15
%20 = icmp eq i32 %19, 15
br i1 %20, label %21, label %42
21: ; preds = %18
%22 = tail call i32 @fputc(i32 32, i32* %0)
br label %23
23: ; preds = %21, %35
%24 = phi i64 [ 15, %21 ], [ %38, %35 ]
%25 = sub nsw i64 %8, %24
%26 = getelementptr inbounds i8, i8* %1, i64 %25
%27 = load i8, i8* %26
%28 = tail call i32 @isascii(i8 signext %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %23
%31 = tail call i32 @isprint(i8 signext %27)
%32 = icmp eq i32 %31, 0
%33 = sext i8 %27 to i32
%34 = select i1 %32, i32 46, i32 %33
br label %35
35: ; preds = %30, %23
%36 = phi i32 [ 46, %23 ], [ %34, %30 ]
%37 = tail call i32 @fputc(i32 %36, i32* %0)
%38 = add nsw i64 %24, -1
%39 = icmp eq i64 %24, 0
br i1 %39, label %40, label %23
40: ; preds = %35
%41 = tail call i32 @fputc(i32 10, i32* %0)
br label %42
42: ; preds = %18, %40
%43 = add nuw nsw i64 %8, 1
%44 = icmp eq i64 %43, %6
br i1 %44, label %45, label %7
45: ; preds = %42
%46 = and i32 %2, 15
br label %47
47: ; preds = %45, %3
%48 = phi i32 [ 0, %3 ], [ %46, %45 ]
br label %49
49: ; preds = %47, %56
%50 = phi i32 [ %48, %47 ], [ %57, %56 ]
%51 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 2, i64 1, i32* %0)
%52 = and i32 %50, 1
%53 = icmp eq i32 %52, 0
br i1 %53, label %56, label %54
54: ; preds = %49
%55 = tail call i32 @fputc(i32 32, i32* %0)
br label %56
56: ; preds = %49, %54
%57 = add nuw nsw i32 %50, 1
%58 = icmp eq i32 %57, 16
br i1 %58, label %59, label %49
59: ; preds = %56
%60 = tail call i32 @fputc(i32 32, i32* %0)
%61 = icmp eq i32 %48, 0
br i1 %61, label %82, label %62
62: ; preds = %59
%63 = sub i32 %2, %48
%64 = sext i32 %63 to i64
%65 = sext i32 %2 to i64
br label %66
66: ; preds = %62, %77
%67 = phi i64 [ %64, %62 ], [ %80, %77 ]
%68 = getelementptr inbounds i8, i8* %1, i64 %67
%69 = load i8, i8* %68
%70 = tail call i32 @isascii(i8 signext %69)
%71 = icmp eq i32 %70, 0
br i1 %71, label %77, label %72
72: ; preds = %66
%73 = tail call i32 @isprint(i8 signext %69)
%74 = icmp eq i32 %73, 0
%75 = sext i8 %69 to i32
%76 = select i1 %74, i32 46, i32 %75
br label %77
77: ; preds = %72, %66
%78 = phi i32 [ 46, %66 ], [ %76, %72 ]
%79 = tail call i32 @fputc(i32 %78, i32* %0)
%80 = add nsw i64 %67, 1
%81 = icmp slt i64 %80, %65
br i1 %81, label %66, label %82
82: ; preds = %77, %59
%83 = tail call i32 @fputc(i32 10, i32* %0)
ret void
}