#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*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int hex_dump(void *msg, int msg_len) {
  int i;
  char hexstr[49], ascstr[17], buf[3];
  unsigned char b, dumpstr = 0;
  char *pMsg = msg;
  memset(hexstr, ' ', 48);
  hexstr[48] = '\0';
  memset(ascstr, ' ', 16);
  ascstr[16] = '\0';
  printf("\n");
  printf("HEX                                              ASCII\n");
  for (i = 0; i < msg_len; i++) {
    b = pMsg[i];
    sprintf(buf, "%02x", b);
    hexstr[i % 16 * 3] = buf[0];
    hexstr[i % 16 * 3 + 1] = buf[1];
    hexstr[i % 16 * 3 + 2] = ' ';
    ascstr[i % 16] = (b > 31 && b < 128) ? b : '.';
    if ((dumpstr = ((i + 1) % 16 == 0)) != 0) {
      printf("%48s %16s\n", hexstr, ascstr);
      if (i < (msg_len - 1)) {
        memset(hexstr, ' ', 48);
        memset(ascstr, ' ', 16);
      }
    }
  }
  if (!dumpstr)
    printf("%48s %16s\n", hexstr, ascstr);
  return 0;
}


x86 assembly (clang, -O0):
<hex_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x0,-0x75(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x20,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
movb   $0x0,-0x20(%rbp)
lea    -0x70(%rbp),%rdi
mov    $0x20,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
movb   $0x0,-0x60(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12f8 <hex_dump+0x1c8>
mov    -0x80(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x74(%rbp)
lea    -0x73(%rbp),%rdi
lea    0xe74(%rip),%rsi
movzbl -0x74(%rbp),%edx
call   1050 <sprintf@plt>
mov    -0x73(%rbp),%cl
mov    -0x10(%rbp),%eax
mov    $0x10,%esi
cltd
idiv   %esi
imul   $0x3,%edx,%eax
cltq
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x72(%rbp),%cl
mov    -0x10(%rbp),%eax
mov    $0x10,%esi
cltd
idiv   %esi
imul   $0x3,%edx,%eax
add    $0x1,%eax
cltq
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
imul   $0x3,%edx,%eax
add    $0x2,%eax
cltq
movb   $0x20,-0x50(%rbp,%rax,1)
movzbl -0x74(%rbp),%eax
cmp    $0x1f,%eax
jle    1241 <hex_dump+0x111>
movzbl -0x74(%rbp),%eax
cmp    $0x80,%eax
jge    1241 <hex_dump+0x111>
movzbl -0x74(%rbp),%eax
mov    %eax,-0x84(%rbp)
jmp    1251 <hex_dump+0x121>
mov    $0x2e,%eax
mov    %eax,-0x84(%rbp)
jmp    1251 <hex_dump+0x121>
mov    -0x84(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%eax
mov    $0x10,%esi
cltd
idiv   %esi
movslq %edx,%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0x75(%rbp)
movzbl %al,%eax
cmp    $0x0,%eax
je     12e5 <hex_dump+0x1b5>
lea    -0x50(%rbp),%rsi
lea    -0x70(%rbp),%rdx
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12e0 <hex_dump+0x1b0>
lea    -0x50(%rbp),%rdi
mov    $0x20,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
lea    -0x70(%rbp),%rdi
mov    $0x20,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
jmp    12e5 <hex_dump+0x1b5>
jmp    12ea <hex_dump+0x1ba>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    119f <hex_dump+0x6f>
cmpb   $0x0,-0x75(%rbp)
jne    1318 <hex_dump+0x1e8>
lea    -0x50(%rbp),%rsi
lea    -0x70(%rbp),%rdx
lea    0xd2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %esi,%ebp
mov    %rdi,%r15
lea    0x30(%rsp),%rdi
mov    $0x20,%esi
mov    $0x30,%edx
call   1060 <memset@plt>
movb   $0x0,0x60(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x20,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
movb   $0x0,0x20(%rsp)
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe6a(%rip),%rdi
call   1040 <puts@plt>
test   %ebp,%ebp
jle    1275 <hex_dump+0x125>
lea    -0x1(%rbp),%eax
mov    %rax,0x28(%rsp)
mov    %ebp,%ebp
mov    $0x2e,%r13d
xor    %r14d,%r14d
jmp    11dc <hex_dump+0x8c>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%r14
cmp    %rbx,%rbp
je     1270 <hex_dump+0x120>
movzbl (%r15,%r14,1),%r12d
lea    0xd(%rsp),%rdi
lea    0xe13(%rip),%rsi
mov    %r12d,%edx
call   1070 <sprintf@plt>
movzwl 0xd(%rsp),%eax
mov    %r14d,%ecx
and    $0xf,%ecx
lea    (%rcx,%rcx,2),%rdx
mov    %ax,0x30(%rsp,%rdx,1)
cmp    $0x20,%r12b
cmovl  %r13d,%r12d
movb   $0x20,0x32(%rsp,%rdx,1)
mov    %r12b,0x10(%rsp,%rcx,1)
lea    0x1(%r14),%rbx
test   $0xf,%bl
jne    11d0 <hex_dump+0x80>
lea    0xdda(%rip),%rdi
lea    0x30(%rsp),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1050 <printf@plt>
cmp    0x28(%rsp),%r14
jae    11d0 <hex_dump+0x80>
lea    0x30(%rsp),%rdi
mov    $0x20,%esi
mov    $0x30,%edx
call   1060 <memset@plt>
lea    0x10(%rsp),%rdi
mov    $0x20,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
jmp    11d0 <hex_dump+0x80>
test   $0xf,%bl
je     128d <hex_dump+0x13d>
lea    0xd89(%rip),%rdi
lea    0x30(%rsp),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [56 x i8] c"HEX ASCII\0A\00"
@.str.2 = [5 x i8] c"%02x\00"
@.str.3 = [11 x i8] c"%48s %16s\0A\00"
define i32 @hex_dump(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [49 x i8]
%7 = alloca [17 x i8]
%8 = alloca [3 x i8]
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8 0, i8* %10
%12 = load i8*, i8** %3
store i8* %12, i8** %11
%13 = getelementptr inbounds [49 x i8], [49 x i8]* %6, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i8 signext 32, i32 48)
%15 = getelementptr inbounds [49 x i8], [49 x i8]* %6, i64 0, i64 48
store i8 0, i8* %15
%16 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%17 = call i32 @memset(i8* %16, i8 signext 32, i32 16)
%18 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 16
store i8 0, i8* %18
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
br label %21
21: ; preds = %96, %2
%22 = load i32, i32* %5
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %99
25: ; preds = %21
%26 = load i8*, i8** %11
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
store i8 %30, i8* %9
%31 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%32 = load i8, i8* %9
%33 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %32)
%34 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%35 = load i8, i8* %34
%36 = load i32, i32* %5
%37 = srem i32 %36, 16
%38 = mul nsw i32 %37, 3
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [49 x i8], [49 x i8]* %6, i64 0, i64 %39
store i8 %35, i8* %40
%41 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 1
%42 = load i8, i8* %41
%43 = load i32, i32* %5
%44 = srem i32 %43, 16
%45 = mul nsw i32 %44, 3
%46 = add nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [49 x i8], [49 x i8]* %6, i64 0, i64 %47
store i8 %42, i8* %48
%49 = load i32, i32* %5
%50 = srem i32 %49, 16
%51 = mul nsw i32 %50, 3
%52 = add nsw i32 %51, 2
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [49 x i8], [49 x i8]* %6, i64 0, i64 %53
store i8 32, i8* %54
%55 = load i8, i8* %9
%56 = zext i8 %55 to i32
%57 = icmp sgt i32 %56, 31
br i1 %57, label %58, label %65
58: ; preds = %25
%59 = load i8, i8* %9
%60 = zext i8 %59 to i32
%61 = icmp slt i32 %60, 128
br i1 %61, label %62, label %65
62: ; preds = %58
%63 = load i8, i8* %9
%64 = zext i8 %63 to i32
br label %66
65: ; preds = %58, %25
br label %66
66: ; preds = %65, %62
%67 = phi i32 [ %64, %62 ], [ 46, %65 ]
%68 = trunc i32 %67 to i8
%69 = load i32, i32* %5
%70 = srem i32 %69, 16
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 %71
store i8 %68, i8* %72
%73 = load i32, i32* %5
%74 = add nsw i32 %73, 1
%75 = srem i32 %74, 16
%76 = icmp eq i32 %75, 0
%77 = zext i1 %76 to i32
%78 = trunc i32 %77 to i8
store i8 %78, i8* %10
%79 = zext i8 %78 to i32
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %95
81: ; preds = %66
%82 = getelementptr inbounds [49 x i8], [49 x i8]* %6, i64 0, i64 0
%83 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %82, i8* %83)
%85 = load i32, i32* %5
%86 = load i32, i32* %4
%87 = sub nsw i32 %86, 1
%88 = icmp slt i32 %85, %87
br i1 %88, label %89, label %94
89: ; preds = %81
%90 = getelementptr inbounds [49 x i8], [49 x i8]* %6, i64 0, i64 0
%91 = call i32 @memset(i8* %90, i8 signext 32, i32 48)
%92 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%93 = call i32 @memset(i8* %92, i8 signext 32, i32 16)
br label %94
94: ; preds = %89, %81
br label %95
95: ; preds = %94, %66
br label %96
96: ; preds = %95
%97 = load i32, i32* %5
%98 = add nsw i32 %97, 1
store i32 %98, i32* %5
br label %21
99: ; preds = %21
%100 = load i8, i8* %10
%101 = icmp ne i8 %100, 0
br i1 %101, label %106, label %102
102: ; preds = %99
%103 = getelementptr inbounds [49 x i8], [49 x i8]* %6, i64 0, i64 0
%104 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %103, i8* %104)
br label %106
106: ; preds = %102, %99
ret i32 0
}

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