void print_int_hex(value) int value;
{
  const char *alphabet = "0123456789ABCDEF";
  int mask;
  int nibble_index = 32 - 4;
  int nibble;
  print_string("0x");
  for (mask = 0xF0000000; mask != 0; mask >>= 4) {
    nibble = (value & mask) >> nibble_index;
    print_char(alphabet[nibble]);
    nibble_index -= 4;
  }
  print_done();
}


x86 assembly (clang, -O0):
<print_int_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    0xebe(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x1c,-0x18(%rbp)
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <print_string@plt>
movl   $0xf0000000,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11a4 <print_int_hex+0x74>
mov    -0x4(%rbp),%eax
and    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
sar    %cl,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
mov    $0x0,%al
call   1050 <print_char@plt>
mov    -0x18(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x14(%rbp)
jmp    1162 <print_int_hex+0x32>
mov    $0x0,%al
call   1040 <print_done@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_int_hex>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
lea    0xee0(%rip),%rdi
xor    %eax,%eax
call   1030 <print_string@plt>
mov    $0xf0000000,%ebx
mov    $0x1c,%ebp
lea    0xeb7(%rip),%r15
nopl   0x0(%rax)
mov    %ebx,%eax
and    %r14d,%eax
mov    %ebp,%ecx
sar    %cl,%eax
cltq
movsbl (%rax,%r15,1),%edi
xor    %eax,%eax
call   1040 <print_char@plt>
add    $0xfffffffc,%ebp
sar    $0x4,%ebx
jmp    1150 <print_int_hex+0x30>

LLVM IR (-O0):
@.str = [17 x i8] c"0123456789ABCDEF\00"
@.str.1 = [3 x i8] c"0x\00"
define void @print_int_hex(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %3
store i32 28, i32* %5
%7 = call i32 (i8*, ...) bitcast (i32 (...)* @print_string to i32 (i8*, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 -268435456, i32* %4
br label %8
8: ; preds = %26, %1
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %29
11: ; preds = %8
%12 = load i32, i32* %2
%13 = load i32, i32* %4
%14 = and i32 %12, %13
%15 = load i32, i32* %5
%16 = ashr i32 %14, %15
store i32 %16, i32* %6
%17 = load i8*, i8** %3
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = call i32 (i32, ...) bitcast (i32 (...)* @print_char to i32 (i32, ...)*)(i32 %22)
%24 = load i32, i32* %5
%25 = sub nsw i32 %24, 4
store i32 %25, i32* %5
br label %26
26: ; preds = %11
%27 = load i32, i32* %4
%28 = ashr i32 %27, 4
store i32 %28, i32* %4
br label %8
29: ; preds = %8
%30 = call i32 (...) @print_done()
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789ABCDEF\00"
@.str.1 = [3 x i8] c"0x\00"
define void @print_int_hex(i32 %0) {
%2 = tail call i32 (i8*, ...) bitcast (i32 (...)* @print_string to i32 (i8*, ...)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %3
3: ; preds = %3, %1
%4 = phi i32 [ 28, %1 ], [ %13, %3 ]
%5 = phi i32 [ -268435456, %1 ], [ %14, %3 ]
%6 = and i32 %5, %0
%7 = ashr i32 %6, %4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = tail call i32 (i32, ...) bitcast (i32 (...)* @print_char to i32 (i32, ...)*)(i32 %11)
%13 = add nsw i32 %4, -4
%14 = ashr i32 %5, 4
br label %3
}