#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, char);
void print_hex_size(unsigned int num, char attr, int hexdigits) {
  int i;
  for (i = (hexdigits - 1) * 4; i >= 0; i -= 4)
    print_char("0123456789ABCDEF"[(num >> i) & 0xF], attr);
}


x86 assembly (clang, -O0):
<print_hex_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
shl    $0x2,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     116d <print_hex_size+0x5d>
mov    -0x4(%rbp),%eax
mov    -0x10(%rbp),%ecx
shr    %cl,%eax
and    $0xf,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    0xeb0(%rip),%rax
mov    (%rax,%rcx,1),%al
movsbl %al,%edi
movsbl -0x5(%rbp),%esi
call   1030 <print_char@plt>
mov    -0x10(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x10(%rbp)
jmp    1130 <print_hex_size+0x20>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex_size>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
shl    $0x2,%ebx
mov    %ebx,%eax
add    $0xfffffffc,%eax
js     115e <print_hex_size+0x4e>
mov    %edi,%r14d
lea    0xed3(%rip),%r15
movsbl %sil,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xfffffffc,%ebx
mov    %r14d,%eax
mov    %ebx,%ecx
shr    %cl,%eax
and    $0xf,%eax
movsbl (%rax,%r15,1),%edi
mov    %ebp,%esi
call   1030 <print_char@plt>
cmp    $0x3,%ebx
jg     1140 <print_hex_size+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789ABCDEF\00"
define void @print_hex_size(i32 %0, i8 signext %1, i32 %2) {
%4 = shl i32 %2, 2
%5 = add i32 %4, -4
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %17
7: ; preds = %3, %7
%8 = phi i32 [ %15, %7 ], [ %5, %3 ]
%9 = lshr i32 %0, %8
%10 = and i32 %9, 15
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = tail call i32 @print_char(i8 signext %13, i8 signext %1)
%15 = add nsw i32 %8, -4
%16 = icmp sgt i32 %8, 3
br i1 %16, label %7, label %17
17: ; preds = %7, %3
ret void
}