#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*/ print_tabs(unsigned short);
int /*<<< orphan*/ printf(char *, ...);
void print_hex_blob(void *_buffer, unsigned offset, unsigned size,
                    unsigned short tabs, unsigned short spacing, int json) {
  unsigned i = 0;
  unsigned char *buffer = _buffer;
  const int line_break = 16;
  if (size == 0)
    return;
  printf("%02x", (unsigned int)(buffer[offset]));
  for (i = offset + 1; i < offset + size; i++) {
    if (spacing && (i - offset) % line_break == 0) {
      printf("\n");
      print_tabs(tabs);
    }
    if (!json)
      printf(":");
    printf("%02x", (unsigned int)(buffer[i]));
  }
  if (spacing)
    printf("\n");
}


x86 assembly (clang, -O0):
<print_hex_blob>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r8w,%ax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %cx,-0x12(%rbp)
mov    %ax,-0x14(%rbp)
mov    %r9d,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x10,-0x2c(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1167 <print_hex_blob+0x47>
jmp    1228 <print_hex_blob+0x108>
mov    -0x28(%rbp),%rax
mov    -0xc(%rbp),%ecx
movzbl (%rax,%rcx,1),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    -0x10(%rbp),%ecx
cmp    %ecx,%eax
jae    120f <print_hex_blob+0xef>
movzwl -0x14(%rbp),%eax
cmp    $0x0,%eax
je     11d0 <print_hex_blob+0xb0>
mov    -0x1c(%rbp),%eax
sub    -0xc(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    11d0 <print_hex_blob+0xb0>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzwl -0x12(%rbp),%edi
call   1040 <print_tabs@plt>
cmpl   $0x0,-0x18(%rbp)
jne    11e8 <print_hex_blob+0xc8>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movzbl (%rax,%rcx,1),%esi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1189 <print_hex_blob+0x69>
cmpw   $0x0,-0x14(%rbp)
je     1228 <print_hex_blob+0x108>
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex_blob>:
test   %edx,%edx
je     120b <print_hex_blob+0xdb>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r14d
mov    %r8d,%r15d
mov    %ecx,%r13d
mov    %edx,%ebp
mov    %esi,%r12d
mov    %rdi,%rbx
mov    %esi,%eax
movzbl (%rdi,%rax,1),%esi
lea    0xe9f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    %r12d,%ebp
add    $0x1,%r12d
cmp    %ebp,%r12d
jae    11ec <print_hex_blob+0xbc>
mov    %r13d,%eax
mov    %r12d,%r13d
mov    $0x1,%r12d
movzwl %ax,%eax
mov    %eax,0x4(%rsp)
jmp    11b5 <print_hex_blob+0x85>
nopl   0x0(%rax)
test   %r14d,%r14d
je     11e0 <print_hex_blob+0xb0>
movzbl (%rbx,%r13,1),%esi
lea    0xe5f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r13
add    $0x1,%r12d
cmp    %r13d,%ebp
jbe    11ec <print_hex_blob+0xbc>
test   %r15w,%r15w
je     1190 <print_hex_blob+0x60>
test   $0xf,%r12b
jne    1190 <print_hex_blob+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%edi
call   1050 <print_tabs@plt>
jmp    1190 <print_hex_blob+0x60>
cs nopw 0x0(%rax,%rax,1)
mov    $0x3a,%edi
call   1030 <putchar@plt>
jmp    1195 <print_hex_blob+0x65>
test   %r15w,%r15w
lea    0x8(%rsp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
je     120b <print_hex_blob+0xdb>
mov    $0xa,%edi
jmp    1030 <putchar@plt>
ret

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

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