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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
void pdkim_hexprint(FILE *stream, char *data, int len, int lf) {
  int i;
  unsigned char *p = (unsigned char *)data;
  for (i = 0; i < len; i++) {
    int c = p[i];
    fprintf(stream, "%02x", c);
  }
  if (lf)
    fputc('\n', stream);
}


x86 assembly (clang, -O0):
<pdkim_hexprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1181 <pdkim_hexprint+0x61>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xe92(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1145 <pdkim_hexprint+0x25>
cmpl   $0x0,-0x18(%rbp)
je     1199 <pdkim_hexprint+0x79>
mov    -0x8(%rbp),%rsi
mov    $0xa,%edi
call   1030 <fputc@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pdkim_hexprint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdi,%r12
test   %edx,%edx
jle    116a <pdkim_hexprint+0x4a>
mov    %rsi,%r13
mov    %edx,%ebx
xor    %ebp,%ebp
lea    0xebd(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x0(%r13,%rbp,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1150 <pdkim_hexprint+0x30>
test   %r14d,%r14d
je     118a <pdkim_hexprint+0x6a>
mov    $0xa,%edi
mov    %r12,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fputc@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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