#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 nist_dump_hex(const void *data, int length) {
  int i;
  const unsigned char *p = (const unsigned char *)data;
  for (i = 0; i < length; ++i) {
    if (i && !(i & 3)) {
      printf((i & 31) ? "-" : "\n");
    }
    printf("%02x", *p++);
  }
}


x86 assembly (clang, -O0):
<nist_dump_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a3 <nist_dump_hex+0x93>
cmpl   $0x0,-0x10(%rbp)
je     1175 <nist_dump_hex+0x65>
mov    -0x10(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
jne    1175 <nist_dump_hex+0x65>
mov    -0x10(%rbp),%ecx
and    $0x1f,%ecx
lea    0xea2(%rip),%rdi
lea    0xe99(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movzbl (%rax),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112e <nist_dump_hex+0x1e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nist_dump_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1176 <nist_dump_hex+0x66>
mov    %rdi,%r15
mov    %esi,%ebx
lea    0xed7(%rip),%r12
lea    0xece(%rip),%r13
lea    0xecb(%rip),%r14
xor    %ebp,%ebp
jmp    1157 <nist_dump_hex+0x47>
nopl   (%rax)
movzbl (%r15,%rbp,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbp
cmp    %ebp,%ebx
je     1176 <nist_dump_hex+0x66>
test   %ebp,%ebp
je     1140 <nist_dump_hex+0x30>
mov    %ebp,%eax
and    $0x3,%eax
jne    1140 <nist_dump_hex+0x30>
test   $0x1f,%bpl
mov    %r13,%rdi
cmove  %r12,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1140 <nist_dump_hex+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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