#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*/ monitor_put(char);
void monitor_write_hex(unsigned int d) {
  int i, shiftd;
  char *digits = "0123456789ABCDEF";
  for (i = 0; i < 8; i++) {
    shiftd = d >> (32 - 4 - 4 * i) & 0x0F;
    monitor_put(digits[shiftd]);
  }
}


x86 assembly (clang, -O0):
<monitor_write_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    0xede(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    116e <monitor_write_hex+0x5e>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%edx
shl    $0x2,%edx
mov    $0x1c,%ecx
sub    %edx,%ecx
shr    %cl,%eax
and    $0xf,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <monitor_put@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    112d <monitor_write_hex+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<monitor_write_hex>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%ebx
mov    %edi,%r14d
mov    %r14,%rax
shr    $0x1c,%rax
lea    0xed8(%rip),%r15
movsbl (%rax,%r15,1),%edi
call   1030 <monitor_put@plt>
mov    %ebx,%eax
shr    $0x18,%eax
and    $0xf,%eax
movsbl (%rax,%r15,1),%edi
call   1030 <monitor_put@plt>
mov    %ebx,%eax
shr    $0x14,%eax
and    $0xf,%eax
movsbl (%rax,%r15,1),%edi
call   1030 <monitor_put@plt>
mov    %ebx,%eax
shr    $0x10,%eax
and    $0xf,%eax
movsbl (%rax,%r15,1),%edi
call   1030 <monitor_put@plt>
mov    %ebx,%eax
shr    $0xc,%eax
and    $0xf,%eax
movsbl (%rax,%r15,1),%edi
call   1030 <monitor_put@plt>
mov    %ebx,%eax
shr    $0x8,%eax
and    $0xf,%eax
movsbl (%rax,%r15,1),%edi
call   1030 <monitor_put@plt>
shr    $0x4,%ebx
and    $0xf,%ebx
movsbl (%rbx,%r15,1),%edi
call   1030 <monitor_put@plt>
and    $0xf,%r14d
movsbl (%r14,%r15,1),%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <monitor_put@plt>

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

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789ABCDEF\00"
define void @monitor_write_hex(i32 %0) {
%2 = lshr i32 %0, 28
%3 = zext i32 %2 to i64
%4 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %3
%5 = load i8, i8* %4
%6 = tail call i32 @monitor_put(i8 signext %5)
%7 = lshr i32 %0, 24
%8 = and i32 %7, 15
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i32 @monitor_put(i8 signext %11)
%13 = lshr i32 %0, 20
%14 = and i32 %13, 15
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = tail call i32 @monitor_put(i8 signext %17)
%19 = lshr i32 %0, 16
%20 = and i32 %19, 15
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = tail call i32 @monitor_put(i8 signext %23)
%25 = lshr i32 %0, 12
%26 = and i32 %25, 15
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = tail call i32 @monitor_put(i8 signext %29)
%31 = lshr i32 %0, 8
%32 = and i32 %31, 15
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = tail call i32 @monitor_put(i8 signext %35)
%37 = lshr i32 %0, 4
%38 = and i32 %37, 15
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = tail call i32 @monitor_put(i8 signext %41)
%43 = and i32 %0, 15
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = tail call i32 @monitor_put(i8 signext %46)
ret void
}