#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*/ printf(char *, ...);
int /*<<< orphan*/ show_char(void *, int);
void show_hex(void *buff, int len) {
  int i = 15, tmp;
  while (len--) {
    printf("%02x ", *(unsigned char *)(buff++));
    if (i-- == 0) {
      printf("\t");
      show_char(buff - 16, 16);
      printf("\n");
      i = 15;
    }
  }
  if (i != 0) {
    tmp = i + 1;
    while (tmp--)
      printf(" %c ", '.');
    printf("\t");
    show_char(buff - 15 + i, 16 - i);
    printf("\n");
  }
  printf("\n\n");
}


x86 assembly (clang, -O0):
<show_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0xf,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     11b8 <show_hex+0x98>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movzbl (%rax),%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
cmp    $0x0,%eax
jne    11b3 <show_hex+0x93>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
add    $0xfffffffffffffff0,%rdi
mov    $0x10,%esi
call   1040 <show_char@plt>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xf,-0x10(%rbp)
jmp    1136 <show_hex+0x16>
cmpl   $0x0,-0x10(%rbp)
je     122f <show_hex+0x10f>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     11f7 <show_hex+0xd7>
lea    0xe22(%rip),%rdi
mov    $0x2e,%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11cb <show_hex+0xab>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
add    $0xfffffffffffffff1,%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
mov    $0x10,%esi
sub    -0x10(%rbp),%esi
call   1040 <show_char@plt>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_hex>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
test   %esi,%esi
je     11af <show_hex+0x6f>
mov    %esi,%ebp
mov    $0xf,%r15d
lea    0xea3(%rip),%r14
jmp    1168 <show_hex+0x28>
nop
add    $0x1,%rbx
test   %ebp,%ebp
je     11a8 <show_hex+0x68>
add    $0xffffffff,%ebp
movzbl (%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
sub    $0x1,%r15d
jae    1160 <show_hex+0x20>
mov    $0x9,%edi
call   1030 <putchar@plt>
lea    -0xf(%rbx),%rdi
mov    $0x10,%esi
call   1060 <show_char@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xf,%r15d
jmp    1160 <show_hex+0x20>
test   %r15d,%r15d
jne    11b5 <show_hex+0x75>
jmp    1200 <show_hex+0xc0>
mov    $0xf,%r15d
lea    0x1(%r15),%ebp
lea    0xe46(%rip),%r14
mov    %r14,%rdi
mov    $0x2e,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xffffffff,%ebp
jne    11c0 <show_hex+0x80>
mov    $0x9,%edi
call   1030 <putchar@plt>
movslq %r15d,%rax
lea    (%rbx,%rax,1),%rdi
add    $0xfffffffffffffff1,%rdi
mov    $0x10,%esi
sub    %r15d,%esi
call   1060 <show_char@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe04(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%02x \00"
@.str.1 = [2 x i8] c"\09\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [5 x i8] c" %c \00"
@.str.4 = [3 x i8] c"\0A\0A\00"
define void @show_hex(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 15, i32* %5
br label %7
7: ; preds = %26, %2
%8 = load i32, i32* %4
%9 = add nsw i32 %8, -1
store i32 %9, i32* %4
%10 = icmp ne i32 %8, 0
br i1 %10, label %11, label %27
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %3
%14 = load i8, i8* %12
%15 = zext i8 %14 to i32
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %5
%18 = add nsw i32 %17, -1
store i32 %18, i32* %5
%19 = icmp eq i32 %17, 0
br i1 %19, label %20, label %26
20: ; preds = %11
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = load i8*, i8** %3
%23 = getelementptr i8, i8* %22, i64 -16
%24 = call i32 @show_char(i8* %23, i32 16)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 15, i32* %5
br label %26
26: ; preds = %20, %11
br label %7
27: ; preds = %7
%28 = load i32, i32* %5
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %50
30: ; preds = %27
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %33
33: ; preds = %37, %30
%34 = load i32, i32* %6
%35 = add nsw i32 %34, -1
store i32 %35, i32* %6
%36 = icmp ne i32 %34, 0
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 46)
br label %33
39: ; preds = %33
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%41 = load i8*, i8** %3
%42 = getelementptr i8, i8* %41, i64 -15
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr i8, i8* %42, i64 %44
%46 = load i32, i32* %5
%47 = sub nsw i32 16, %46
%48 = call i32 @show_char(i8* %45, i32 %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %39, %27
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
ret void
}

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