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

/* Variables and functions */
int /*<<< orphan*/ dm_LogPrintf(int, char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, char);
void dm_LogHandle(char *hdl, int len) {
  int i;
  char outbuf[256], *pch;
  memset(outbuf, 0, sizeof(outbuf));
  for (i = 0, pch = outbuf; i < len; i++, pch += 3)
    sprintf(pch, " %02X", hdl[i]);
  dm_LogPrintf(3, "Handle: %s\n", outbuf);
}


x86 assembly (clang, -O0):
<dm_LogHandle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1030 <memset@plt>
movl   $0x0,-0x10(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x118(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b5 <dm_LogHandle+0x85>
mov    -0x118(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xe74(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x118(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x118(%rbp)
jmp    116a <dm_LogHandle+0x3a>
lea    -0x110(%rbp),%rdx
mov    $0x3,%edi
lea    0xe3e(%rip),%rsi
call   1040 <dm_LogPrintf@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dm_LogHandle>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1030 <memset@plt>
test   %ebp,%ebp
jle    118d <dm_LogHandle+0x5d>
mov    %ebp,%r12d
xor    %ebp,%ebp
lea    0xe9a(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
movsbl (%r14,%rbp,1),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <sprintf@plt>
add    $0x1,%rbp
add    $0x3,%rbx
cmp    %rbp,%r12
jne    1170 <dm_LogHandle+0x40>
lea    0xe72(%rip),%rsi
mov    %rsp,%rdx
mov    $0x3,%edi
call   1040 <dm_LogPrintf@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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