#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 print_hexdump(char *tab, unsigned char *buff, int size) {
  int i;
  char str[17] = {'\0'};
  for (i = 0; i < size; i++) {
    if (((i % 16) == 0)) {
      if (str[0] != '\0')
        printf(" %s", str);
      memset(str, '\0', 17);
      printf("\n%s%4.4x ", tab, i);
    }
    if ((buff[i] >= 0x20) && (buff[i] <= 0x7e))
      str[i % 16] = buff[i];
    else
      str[i % 16] = '.';
    printf("%2.2x ", buff[i]);
  }
  printf(" %s", str);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<print_hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1040 <memset@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1235 <print_hexdump+0x115>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ae <print_hexdump+0x8e>
movsbl -0x30(%rbp),%eax
cmp    $0x0,%eax
je     1189 <print_hexdump+0x69>
lea    -0x30(%rbp),%rsi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     11fa <print_hexdump+0xda>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jg     11fa <print_hexdump+0xda>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x18(%rbp),%eax
mov    $0x10,%esi
cltd
idiv   %esi
movslq %edx,%rax
mov    %cl,-0x30(%rbp,%rax,1)
jmp    120d <print_hexdump+0xed>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movb   $0x2e,-0x30(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114a <print_hexdump+0x2a>
lea    -0x30(%rbp),%rsi
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,0x20(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
test   %edx,%edx
jle    11e3 <print_hexdump+0xb3>
mov    %rsi,%rbx
mov    %edx,%r12d
mov    %rsp,%r14
lea    0xea7(%rip),%rbp
xor    %r13d,%r13d
jmp    11bb <print_hexdump+0x8b>
nopl   0x0(%rax)
xor    %esi,%esi
mov    $0x11,%edx
call   1050 <memset@plt>
lea    0xe81(%rip),%rdi
mov    0x20(%rsp),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%rbx,%r13,1),%esi
lea    -0x20(%rsi),%eax
cmp    $0x5f,%al
mov    $0x2e,%eax
cmovb  %esi,%eax
mov    %al,(%rsp,%r15,1)
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r13
cmp    %r13,%r12
je     11e3 <print_hexdump+0xb3>
mov    %r13,%r15
and    $0xf,%r15
jne    1192 <print_hexdump+0x62>
cmpb   $0x0,(%rsp)
mov    %r14,%rdi
je     1170 <print_hexdump+0x40>
lea    0xe2c(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
jmp    1170 <print_hexdump+0x40>
lea    0xe16(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c" %s\00"
@.str.1 = [10 x i8] c"\0A%s%4.4x \00"
@.str.2 = [7 x i8] c"%2.2x \00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @print_hexdump(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [17 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = bitcast [17 x i8]* %8 to i8*
store i32 0, i32* %7
br label %10
10: ; preds = %71, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %74
14: ; preds = %10
%15 = load i32, i32* %7
%16 = srem i32 %15, 16
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %32
18: ; preds = %14
%19 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %23, %18
%27 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%28 = call i32 @memset(i8* %27, i8 signext 0, i32 17)
%29 = load i8*, i8** %4
%30 = load i32, i32* %7
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %29, i32 %30)
br label %32
32: ; preds = %26, %14
%33 = load i8*, i8** %5
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = icmp sge i32 %38, 32
br i1 %39, label %40, label %58
40: ; preds = %32
%41 = load i8*, i8** %5
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = icmp sle i32 %46, 126
br i1 %47, label %48, label %58
48: ; preds = %40
%49 = load i8*, i8** %5
%50 = load i32, i32* %7
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = load i32, i32* %7
%55 = srem i32 %54, 16
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %56
store i8 %53, i8* %57
br label %63
58: ; preds = %40, %32
%59 = load i32, i32* %7
%60 = srem i32 %59, 16
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 %61
store i8 46, i8* %62
br label %63
63: ; preds = %58, %48
%64 = load i8*, i8** %5
%65 = load i32, i32* %7
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = load i8, i8* %67
%69 = zext i8 %68 to i32
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %69)
br label %71
71: ; preds = %63
%72 = load i32, i32* %7
%73 = add nsw i32 %72, 1
store i32 %73, i32* %7
br label %10
74: ; preds = %10
%75 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %75)
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c" %s\00"
@.str.1 = [10 x i8] c"\0A%s%4.4x \00"
@.str.2 = [7 x i8] c"%2.2x \00"
define i32 @print_hexdump(i8* %0, i8* nocapture %1, i32 %2) {
%4 = alloca [17 x i8]
%5 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %34
7: ; preds = %3
%8 = zext i32 %2 to i64
br label %9
9: ; preds = %7, %22
%10 = phi i64 [ 0, %7 ], [ %32, %22 ]
%11 = trunc i64 %10 to i32
%12 = and i32 %11, 15
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %9
%15 = load i8, i8* %5
%16 = icmp eq i8 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %19
19: ; preds = %17, %14
%20 = call i32 @memset(i8* %5, i8 signext 0, i32 17)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %11)
br label %22
22: ; preds = %19, %9
%23 = getelementptr inbounds i8, i8* %1, i64 %10
%24 = load i8, i8* %23
%25 = add i8 %24, -32
%26 = icmp ult i8 %25, 95
%27 = zext i32 %12 to i64
%28 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 %27
%29 = select i1 %26, i8 %24, i8 46
store i8 %29, i8* %28
%30 = zext i8 %24 to i32
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = add nuw nsw i64 %10, 1
%33 = icmp eq i64 %32, %8
br i1 %33, label %34, label %9
34: ; preds = %22, %3
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
%36 = call i32 @putchar(i32 10)
ret i32 0
}