#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*/ sprintf(char *, char *, unsigned int);
void stringify(char *src, char *dst, int count) {
  char buffer[4];
  int i;
  for (i = 0; i < count; ++i) {
    unsigned value = (unsigned char)src[i];
    sprintf(buffer, "%X", value);
    if (value >= 0x10) {
      *(dst++) = buffer[0];
      *(dst++) = buffer[1];
    } else {
      *(dst++) = '0';
      *(dst++) = buffer[0];
    }
  }
}


x86 assembly (clang, -O0):
<stringify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c8 <stringify+0xb8>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xead(%rip),%rsi
call   1030 <sprintf@plt>
cmpl   $0x10,-0x20(%rbp)
jb     118f <stringify+0x7f>
mov    -0x18(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x17(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    11b5 <stringify+0xa5>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x30,(%rax)
mov    -0x18(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    11ba <stringify+0xaa>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <stringify+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringify>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1183 <stringify+0x73>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %edx,%r13d
xor    %r15d,%r15d
lea    0x4(%rsp),%r12
jmp    1158 <stringify+0x48>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x30,(%rbx,%r15,2)
movzbl 0x4(%rsp),%eax
mov    %al,0x1(%rbx,%r15,2)
add    $0x1,%r15
cmp    %r15,%r13
je     1183 <stringify+0x73>
movzbl (%r14,%r15,1),%ebp
mov    %r12,%rdi
lea    0xe99(%rip),%rsi
mov    %ebp,%edx
call   1030 <sprintf@plt>
cmp    $0x10,%ebp
jb     1140 <stringify+0x30>
movzbl 0x4(%rsp),%eax
mov    %al,(%rbx,%r15,2)
movzbl 0x5(%rsp),%eax
jmp    114a <stringify+0x3a>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%X\00"
define void @stringify(i8* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = alloca [4 x i8]
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %29
7: ; preds = %3
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %7, %23
%11 = phi i64 [ 0, %7 ], [ %27, %23 ]
%12 = phi i8* [ %1, %7 ], [ %26, %23 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %11
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = icmp ugt i8 %14, 15
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = load i8, i8* %5
store i8 %19, i8* %12
%20 = load i8, i8* %8
br label %23
21: ; preds = %10
store i8 48, i8* %12
%22 = load i8, i8* %5
br label %23
23: ; preds = %21, %18
%24 = phi i8 [ %20, %18 ], [ %22, %21 ]
%25 = getelementptr inbounds i8, i8* %12, i64 1
store i8 %24, i8* %25
%26 = getelementptr inbounds i8, i8* %12, i64 2
%27 = add nuw nsw i64 %11, 1
%28 = icmp eq i64 %27, %9
br i1 %28, label %29, label %10
29: ; preds = %23, %3
ret void
}