#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*/ Dprintf(int, char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
void dump_hex(void *b, int l) {
  unsigned char *buf = b;
  char logbuf[80];
  int i, j;
  for (i = 0; i < l; i += 16) {
    for (j = 0; j < 16 && i + j < l; ++j)
      sprintf(logbuf + j * 3, " %02x", buf[i + j]);
    Dprintf(2, "%s", logbuf);
  }
  Dprintf(2, "\n");
}


x86 assembly (clang, -O0):
<dump_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11df <dump_hex+0xbf>
movl   $0x0,-0x78(%rbp)
xor    %eax,%eax
cmpl   $0x10,-0x78(%rbp)
mov    %al,-0x79(%rbp)
jge    1172 <dump_hex+0x52>
mov    -0x74(%rbp),%eax
add    -0x78(%rbp),%eax
cmp    -0xc(%rbp),%eax
setl   %al
mov    %al,-0x79(%rbp)
mov    -0x79(%rbp),%al
test   $0x1,%al
jne    1182 <dump_hex+0x62>
jmp    11ba <dump_hex+0x9a>
lea    -0x70(%rbp),%rdi
imul   $0x3,-0x78(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x18(%rbp),%rax
mov    -0x74(%rbp),%ecx
add    -0x78(%rbp),%ecx
movslq %ecx,%rcx
lea    0xe5d(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1030 <sprintf@plt>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    1154 <dump_hex+0x34>
lea    -0x70(%rbp),%rdx
mov    $0x2,%edi
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1040 <Dprintf@plt>
mov    -0x74(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x74(%rbp)
jmp    1141 <dump_hex+0x21>
mov    $0x2,%edi
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1040 <Dprintf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %esi,0xc(%rsp)
test   %esi,%esi
jle    11a9 <dump_hex+0x89>
mov    %rdi,%rbx
mov    0xc(%rsp),%r12d
lea    0x10(%rsp),%rbp
lea    0xeb6(%rip),%r13
xor    %r14d,%r14d
jmp    117a <dump_hex+0x5a>
nop
mov    $0x2,%edi
lea    0xeaa(%rip),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <Dprintf@plt>
add    $0x10,%r14
add    $0x10,%rbx
cmp    0xc(%rsp),%r14d
jge    11a9 <dump_hex+0x89>
xor    %r15d,%r15d
nopl   (%rax)
lea    (%r14,%r15,1),%rax
cmp    %r12,%rax
jge    1150 <dump_hex+0x30>
movzbl (%rbx,%r15,1),%edx
mov    %rbp,%rdi
mov    %r13,%rsi
call   1030 <sprintf@plt>
add    $0x1,%r15
add    $0x3,%rbp
cmp    $0x10,%r15
jne    1180 <dump_hex+0x60>
jmp    1150 <dump_hex+0x30>
lea    0xe59(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   1040 <Dprintf@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c" %02x\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @dump_hex(i8* nocapture %0, i32 %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %27
6: ; preds = %2
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %22
%9 = phi i64 [ 0, %6 ], [ %24, %22 ]
br label %10
10: ; preds = %8, %14
%11 = phi i64 [ 0, %8 ], [ %20, %14 ]
%12 = add nuw nsw i64 %11, %9
%13 = icmp slt i64 %12, %7
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = mul nuw nsw i64 %11, 3
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %15
%17 = getelementptr inbounds i8, i8* %0, i64 %12
%18 = load i8, i8* %17
%19 = call i32 @sprintf(i8* %16, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %18)
%20 = add nuw nsw i64 %11, 1
%21 = icmp eq i64 %20, 16
br i1 %21, label %22, label %10
22: ; preds = %14, %10
%23 = call i32 (i32, i8*, ...) @Dprintf(i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%24 = add nuw i64 %9, 16
%25 = trunc i64 %24 to i32
%26 = icmp slt i32 %25, %1
br i1 %26, label %8, label %27
27: ; preds = %22, %2
%28 = call i32 (i32, i8*, ...) @Dprintf(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}