#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;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int const, char *);
int strlen(char *);
void hex_colon_bytes(char *s, const void *data, int d_sz) {
  int i;
  const uint8_t *d = data;
  char *p;
  for (i = 0, p = s + strlen(s); i < d_sz; i++)
    sprintf(p + i * 3, "%02x%s", d[i], (i < d_sz - 1) ? ":" : "");
}


x86 assembly (clang, -O0):
<hex_colon_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c1 <hex_colon_bytes+0xa1>
mov    -0x28(%rbp),%rdi
imul   $0x3,-0x18(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%r8d
sub    $0x1,%r8d
lea    0xe6f(%rip),%rcx
lea    0xe67(%rip),%rax
cmp    %r8d,%esi
cmovl  %rax,%rcx
lea    0xe52(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1163 <hex_colon_bytes+0x43>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_colon_bytes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %r15d,%r15d
jle    1191 <hex_colon_bytes+0x71>
cltq
add    %rax,%rbx
lea    -0x1(%r15),%r12d
mov    %r15d,%r13d
xor    %ebp,%ebp
lea    0xead(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14,%rbp,4),%edx
cmp    %r12,%rbp
lea    0xe9a(%rip),%rcx
lea    0xe92(%rip),%rax
cmovb  %rax,%rcx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <sprintf@plt>
add    $0x1,%rbp
add    $0x3,%rbx
cmp    %rbp,%r13
jne    1160 <hex_colon_bytes+0x40>
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%s\00"
@.str.1 = [2 x i8] c":\00"
@.str.2 = [1 x i8] zeroinitializer
define void @hex_colon_bytes(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %5
%11 = bitcast i8* %10 to i32*
store i32* %11, i32** %8
store i32 0, i32* %7
%12 = load i8*, i8** %4
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
store i8* %16, i8** %9
br label %17
17: ; preds = %39, %3
%18 = load i32, i32* %7
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %42
21: ; preds = %17
%22 = load i8*, i8** %9
%23 = load i32, i32* %7
%24 = mul nsw i32 %23, 3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = load i32*, i32** %8
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = load i32, i32* %7
%33 = load i32, i32* %6
%34 = sub nsw i32 %33, 1
%35 = icmp slt i32 %32, %34
%36 = zext i1 %35 to i64
%37 = select i1 %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%38 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %31, i8* %37)
br label %39
39: ; preds = %21
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %17
42: ; preds = %17
ret void
}

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