#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 dumpraw(const char *str, unsigned char *buffer, size_t length) {
  size_t x;
  printf("[");
  for (x = 0; x < length; x++) {
    if (x != (length - 1)) {
      printf("%02x ", buffer[x]);
    } else {
      printf("%02x", buffer[x]);
    }
  }
  printf("]");
}


x86 assembly (clang, -O0):
<dumpraw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11ac <dumpraw+0x9c>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
je     117c <dumpraw+0x6c>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1196 <dumpraw+0x86>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119b <dumpraw+0x8b>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    113a <dumpraw+0x2a>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dumpraw>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    $0x5b,%edi
call   1030 <putchar@plt>
test   %r15,%r15
je     117f <dumpraw+0x5f>
lea    -0x1(%r15),%rbx
lea    0xebb(%rip),%r12
lea    0xeae(%rip),%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    %rbp,%rbx
mov    %r13,%rdi
cmove  %r12,%rdi
movzbl (%r14,%rbp,1),%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1160 <dumpraw+0x40>
mov    $0x5d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str.1 = [6 x i8] c"%02x \00"
@.str.2 = [5 x i8] c"%02x\00"
define void @dumpraw(i8* nocapture readnone %0, i8* nocapture %1, i64 %2) {
%4 = tail call i32 @putchar(i32 91)
%5 = icmp eq i64 %2, 0
br i1 %5, label %18, label %6
6: ; preds = %3
%7 = add i64 %2, -1
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %16, %8 ]
%10 = icmp eq i64 %9, %7
%11 = getelementptr inbounds i8, i8* %1, i64 %9
%12 = select i1 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
%13 = load i8, i8* %11
%14 = zext i8 %13 to i32
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %12, i32 %14)
%16 = add nuw i64 %9, 1
%17 = icmp eq i64 %16, %2
br i1 %17, label %18, label %8
18: ; preds = %8, %3
%19 = tail call i32 @putchar(i32 93)
ret void
}