#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*/ snprintf(char *, int, char *, unsigned char const);
void hexencode(const unsigned char *digest, int len, char *buf, int buflen) {
  int i;
  for (i = 0; i < len; i++) {
    snprintf(buf + 3 * i, buflen - 3 * i, "%%%02x", digest[i]);
  }
}


x86 assembly (clang, -O0):
<hexencode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1175 <hexencode+0x65>
mov    -0x18(%rbp),%rdi
imul   $0x3,-0x20(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x1c(%rbp),%esi
imul   $0x3,-0x20(%rbp),%eax
sub    %eax,%esi
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
lea    0xea2(%rip),%rdx
movzbl (%rax,%rcx,1),%ecx
call   1030 <snprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112d <hexencode+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexencode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1164 <hexencode+0x54>
mov    %ecx,%r13d
mov    %rdx,%rbx
mov    %rdi,%r14
mov    %esi,%r12d
xor    %ebp,%ebp
lea    0xecc(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%r14,%rbp,1),%ecx
mov    %rbx,%rdi
mov    %r13d,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
add    $0x1,%rbp
add    $0x3,%rbx
add    $0xfffffffd,%r13d
cmp    %rbp,%r12
jne    1140 <hexencode+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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