#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*/ print_char(char);
void print_hex(unsigned int hex) {
  char chars[] = {'0', '1', '2', '3', '4', '5', '6', '7',
                  '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
  print_char('0');
  print_char('x');
  for (int i = 28; i >= 0; i = i - 4)
    print_char(chars[(hex >> i) & 0xF]);
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    0xede(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xedb(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    $0x30,%edi
call   1030 <print_char@plt>
mov    $0x78,%edi
call   1030 <print_char@plt>
movl   $0x1c,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     117b <print_hex+0x6b>
mov    -0x4(%rbp),%eax
mov    -0x24(%rbp),%ecx
shr    %cl,%eax
and    $0xf,%eax
mov    %eax,%eax
movsbl -0x20(%rbp,%rax,1),%edi
call   1030 <print_char@plt>
mov    -0x24(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x24(%rbp)
jmp    114c <print_hex+0x3c>
add    $0x30,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
@__const.print_hex.chars = [16 x i8] c"0123456789ABCDEF"
define void @print_hex(i32 %0) {
%2 = alloca i32
%3 = alloca [16 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = bitcast [16 x i8]* %3 to i8*
%6 = call i32 @print_char(i8 signext 48)
%7 = call i32 @print_char(i8 signext 120)
store i32 28, i32* %4
br label %8
8: ; preds = %20, %1
%9 = load i32, i32* %4
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %8
%12 = load i32, i32* %2
%13 = load i32, i32* %4
%14 = lshr i32 %12, %13
%15 = and i32 %14, 15
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = call i32 @print_char(i8 signext %18)
br label %20
20: ; preds = %11
%21 = load i32, i32* %4
%22 = sub nsw i32 %21, 4
store i32 %22, i32* %4
br label %8
23: ; preds = %8
ret void
}

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