#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 *, ...);
void print_hex_buff(unsigned char *start, unsigned char *end, int hex_output) {
  unsigned char *src = start;
  if (!hex_output) {
    return;
  }
  printf("[clam hex:\n");
  while (start < end) {
    printf("%.2x ", *start);
    if (!((start - src + 1) % 16))
      printf("\n");
    start++;
  }
  printf("]\n");
}


x86 assembly (clang, -O0):
<print_hex_buff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    113a <print_hex_buff+0x2a>
jmp    11bb <print_hex_buff+0xab>
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11ad <print_hex_buff+0x9d>
mov    -0x8(%rbp),%rax
movzbl (%rax),%esi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    $0x10,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    119c <print_hex_buff+0x8c>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1148 <print_hex_buff+0x38>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex_buff>:
test   %edx,%edx
je     11ba <print_hex_buff+0x8a>
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xeb9(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%r12
sub    %r14,%r12
jae    11a3 <print_hex_buff+0x73>
mov    $0x1,%ebx
lea    0xe9a(%rip),%r14
jmp    1182 <print_hex_buff+0x52>
nopl   0x0(%rax,%rax,1)
lea    (%r12,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
je     11a3 <print_hex_buff+0x73>
movzbl -0x1(%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   $0xf,%bl
jne    1170 <print_hex_buff+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1170 <print_hex_buff+0x40>
lea    0xe67(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <puts@plt>
ret

LLVM IR (-O0):
@.str = [12 x i8] c"[clam hex:\0A\00"
@.str.1 = [6 x i8] c"%.2x \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [3 x i8] c"]\0A\00"
define void @print_hex_buff(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
store i8* %8, i8** %7
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %3
br label %38
12: ; preds = %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %33, %12
%15 = load i8*, i8** %4
%16 = load i8*, i8** %5
%17 = icmp ult i8* %15, %16
br i1 %17, label %18, label %36
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i8*, i8** %4
%24 = load i8*, i8** %7
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = add nsw i64 %27, 1
%29 = srem i64 %28, 16
%30 = icmp ne i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %18
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %18
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %4
br label %14
36: ; preds = %14
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36, %11
ret void
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"%.2x \00"
@str = [11 x i8] c"[clam hex:\00"
@str.4 = [2 x i8] c"]\00"
define void @print_hex_buff(i8* %0, i8* readnone %1, i32 %2) {
%4 = ptrtoint i8* %0 to i64
%5 = ptrtoint i8* %1 to i64
%6 = icmp eq i32 %2, 0
br i1 %6, label %30, label %7
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%9 = icmp ult i8* %0, %1
br i1 %9, label %10, label %28
10: ; preds = %7
%11 = sub i64 1, %4
%12 = sub i64 %5, %4
%13 = getelementptr i8, i8* %0, i64 %12
br label %14
14: ; preds = %10, %25
%15 = phi i8* [ %0, %10 ], [ %26, %25 ]
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = ptrtoint i8* %15 to i64
%20 = add i64 %11, %19
%21 = and i64 %20, 15
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = tail call i32 @putchar(i32 10)
br label %25
25: ; preds = %23, %14
%26 = getelementptr inbounds i8, i8* %15, i64 1
%27 = icmp eq i8* %26, %13
br i1 %27, label %28, label %14
28: ; preds = %25, %7
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.4, i64 0, i64 0))
br label %30
30: ; preds = %3, %28
ret void
}