#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 uint8_t;
typedef int ssize_t;
typedef int /*<<< orphan*/ pb;

/* Variables and functions */
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
void hex(const void *pv, ssize_t cb, const char *pszWhat) {
  printf("%s: cb=%d\n", pszWhat, cb);
  unsigned char *pb = (unsigned char *)pv;
  int cch = 0;
  int off = 0;
  int cchPrecision = 16;
  while (off < cb) {
    int i;
    printf("%s%0*x %04x:", off ? "\n" : "", sizeof(pb) * 2, (uintptr_t)pb, off);
    for (i = 0; i < cchPrecision && off + i < cb; i++)
      printf(off + i < cb ? !(i & 7) && i ? "-%02x" : " %02x" : "   ", pb[i]);
    while (i++ < cchPrecision)
      printf("   ");
    printf(" ");
    for (i = 0; i < cchPrecision && off + i < cb; i++) {
      uint8_t u8 = pb[i];
      fputc(u8 < 127 && u8 >= 32 ? u8 : '.', stdout);
    }
    pb += cchPrecision;
    off += cchPrecision;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x10,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1348 <hex+0x228>
mov    -0x28(%rbp),%ecx
lea    0xe8f(%rip),%rsi
lea    0xe87(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8d
lea    0xe73(%rip),%rdi
mov    $0x10,%edx
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%ecx
xor    %eax,%eax
cmp    -0x2c(%rbp),%ecx
mov    %al,-0x35(%rbp)
jge    11cb <hex+0xab>
mov    -0x28(%rbp),%eax
add    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
setl   %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    11db <hex+0xbb>
jmp    125e <hex+0x13e>
mov    -0x28(%rbp),%eax
add    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1229 <hex+0x109>
mov    -0x30(%rbp),%ecx
and    $0x7,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x36(%rbp)
jne    1208 <hex+0xe8>
cmpl   $0x0,-0x30(%rbp)
setne  %al
mov    %al,-0x36(%rbp)
mov    -0x36(%rbp),%dl
lea    0xe0c(%rip),%rax
lea    0xdff(%rip),%rcx
test   $0x1,%dl
cmovne %rcx,%rax
mov    %rax,-0x40(%rbp)
jmp    1239 <hex+0x119>
lea    0xdf4(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    1239 <hex+0x119>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11ab <hex+0x8b>
jmp    1263 <hex+0x143>
mov    -0x30(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x30(%rbp)
cmp    -0x2c(%rbp),%eax
jge    128a <hex+0x16a>
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1263 <hex+0x143>
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%ecx
xor    %eax,%eax
cmp    -0x2c(%rbp),%ecx
mov    %al,-0x41(%rbp)
jge    12bf <hex+0x19f>
mov    -0x28(%rbp),%eax
add    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
setl   %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    12cf <hex+0x1af>
jmp    1329 <hex+0x209>
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x7f,-0x34(%rbp)
jge    12fd <hex+0x1dd>
cmpl   $0x20,-0x34(%rbp)
jl     12fd <hex+0x1dd>
mov    -0x34(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    130a <hex+0x1ea>
mov    $0x2e,%eax
mov    %eax,-0x48(%rbp)
jmp    130a <hex+0x1ea>
mov    -0x48(%rbp),%edi
mov    0x2ccc(%rip),%rax
mov    (%rax),%esi
call   1040 <fputc@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    129f <hex+0x17f>
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1165 <hex+0x45>
lea    0xcba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%r12
lea    0xeb6(%rip),%rdi
mov    %rdx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,0xc(%rsp)
test   %ebp,%ebp
jle    129c <hex+0x16c>
movslq 0xc(%rsp),%r15
mov    $0x1,%r14d
lea    0xea4(%rip),%rbp
lea    0xea3(%rip),%rbx
xor    %r8d,%r8d
jmp    11aa <hex+0x7a>
add    $0x10,%r12
mov    0x10(%rsp),%r8
add    $0x10,%r8
add    $0x10,%r14
cmp    0xc(%rsp),%r8d
lea    0xe7b(%rip),%rbp
lea    0xe7a(%rip),%rbx
jge    129c <hex+0x16c>
test   %r8,%r8
lea    0xe55(%rip),%rsi
lea    0xe4f(%rip),%rax
cmove  %rax,%rsi
mov    $0x10,%edx
lea    0xe40(%rip),%rdi
mov    %r12,%rcx
mov    %r8,0x10(%rsp)
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
nopl   0x0(%rax)
mov    %rax,%r13
test   $0x7,%r13b
mov    %rbx,%rdi
cmove  %rbp,%rdi
test   %rax,%rax
cmove  %rbx,%rdi
movzbl (%r12,%rax,1),%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1(%r13),%rax
cmp    $0xe,%r13
ja     1214 <hex+0xe4>
lea    (%r14,%r13,1),%rcx
cmp    %r15,%rcx
jl     11e0 <hex+0xb0>
cmp    $0xf,%eax
lea    0xe06(%rip),%rbx
ja     123f <hex+0x10f>
mov    $0xf,%ebp
sub    %r13d,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%ebp
jne    1230 <hex+0x100>
mov    $0x20,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
mov    $0x2e,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r12,%rbp,1),%eax
lea    -0x20(%rax),%ecx
cmp    $0x5f,%cl
cmovae %r13d,%eax
movzbl %al,%edi
mov    0x2d67(%rip),%rax
mov    (%rax),%esi
call   1050 <fputc@plt>
cmp    $0xe,%rbp
ja     1180 <hex+0x50>
lea    (%r14,%rbp,1),%rax
add    $0x1,%rbp
cmp    %r15,%rax
jl     1260 <hex+0x130>
jmp    1180 <hex+0x50>
mov    $0xa,%edi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [11 x i8] c"%s: cb=%d\0A\00"
@.str.1 = [13 x i8] c"%s%0*x %04x:\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [6 x i8] c"-%02x\00"
@.str.5 = [6 x i8] c" %02x\00"
@.str.6 = [4 x i8] c" \00"
@stdout = global i32 0
define void @hex(i8* %0, i32 %1, i8* %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %1)
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %63
6: ; preds = %3
%7 = sext i32 %1 to i64
%8 = sext i32 %1 to i64
br label %9
9: ; preds = %58, %6
%10 = phi i64 [ 0, %6 ], [ %60, %58 ]
%11 = phi i8* [ %0, %6 ], [ %59, %58 ]
%12 = icmp eq i64 %10, 0
%13 = select i1 %12, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%14 = ptrtoint i8* %11 to i64
%15 = trunc i64 %10 to i32
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %13, i64 16, i64 %14, i32 %15)
br label %20
17: ; preds = %20
%18 = trunc i64 %31 to i32
%19 = icmp ult i32 %18, 16
br i1 %19, label %36, label %41
20: ; preds = %9, %20
%21 = phi i64 [ 0, %9 ], [ %31, %20 ]
%22 = and i64 %21, 7
%23 = icmp eq i64 %22, 0
%24 = icmp ne i64 %21, 0
%25 = and i1 %24, %23
%26 = select i1 %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0)
%27 = getelementptr inbounds i8, i8* %11, i64 %21
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %26, i32 %29)
%31 = add nuw nsw i64 %21, 1
%32 = icmp ult i64 %21, 15
%33 = add nuw nsw i64 %31, %10
%34 = icmp slt i64 %33, %7
%35 = select i1 %32, i1 %34, i1 false
br i1 %35, label %20, label %17
36: ; preds = %17, %36
%37 = phi i32 [ %38, %36 ], [ %18, %17 ]
%38 = add nuw nsw i32 %37, 1
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%40 = icmp eq i32 %38, 16
br i1 %40, label %41, label %36
41: ; preds = %36, %17
%42 = tail call i32 @putchar(i32 32)
br label %43
43: ; preds = %41, %43
%44 = phi i64 [ 0, %41 ], [ %53, %43 ]
%45 = getelementptr inbounds i8, i8* %11, i64 %44
%46 = load i8, i8* %45
%47 = add i8 %46, -32
%48 = icmp ult i8 %47, 95
%49 = select i1 %48, i8 %46, i8 46
%50 = zext i8 %49 to i32
%51 = load i32, i32* @stdout
%52 = tail call i32 @fputc(i32 %50, i32 %51)
%53 = add nuw nsw i64 %44, 1
%54 = icmp ult i64 %44, 15
%55 = add nuw nsw i64 %53, %10
%56 = icmp slt i64 %55, %8
%57 = select i1 %54, i1 %56, i1 false
br i1 %57, label %43, label %58
58: ; preds = %43
%59 = getelementptr inbounds i8, i8* %11, i64 16
%60 = add nuw i64 %10, 16
%61 = trunc i64 %60 to i32
%62 = icmp slt i32 %61, %1
br i1 %62, label %9, label %63
63: ; preds = %58, %3
%64 = tail call i32 @putchar(i32 10)
ret void
}