#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 */
typedef int uint8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int const);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
void printhex(FILE *fp, const uint8_t *vec, size_t n) {
  int i;
  if (n > 0) {
    for (i = 0; i < n; i++)
      fprintf(fp, "%02x", vec[i]);
  } else
    fputc('-', fp);
  fputc('\n', fp);
}


x86 assembly (clang, -O0):
<printhex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    1182 <printhex+0x62>
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    117d <printhex+0x5d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe96(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1146 <printhex+0x26>
jmp    1190 <printhex+0x70>
mov    -0x8(%rbp),%rsi
mov    $0x2d,%edi
call   1030 <fputc@plt>
mov    -0x8(%rbp),%rsi
mov    $0xa,%edi
call   1030 <fputc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printhex>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
test   %rdx,%rdx
je     115a <printhex+0x3a>
mov    %rdx,%r13
mov    %rsi,%r15
xor    %ebx,%ebx
lea    0xec0(%rip),%r12
mov    (%r15,%rbx,4),%edx
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1140 <printhex+0x20>
jmp    1167 <printhex+0x47>
mov    $0x2d,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
mov    $0xa,%edi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <fputc@plt>

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

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
define void @printhex(i32* nocapture %0, i32* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %12, label %5
5: ; preds = %3, %5
%6 = phi i64 [ %10, %5 ], [ 0, %3 ]
%7 = getelementptr inbounds i32, i32* %1, i64 %6
%8 = load i32, i32* %7
%9 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = add nuw i64 %6, 1
%11 = icmp eq i64 %10, %2
br i1 %11, label %14, label %5
12: ; preds = %3
%13 = tail call i32 @fputc(i8 signext 45, i32* %0)
br label %14
14: ; preds = %5, %12
%15 = tail call i32 @fputc(i8 signext 10, i32* %0)
ret void
}