#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 */
void printhex(unsigned n) {
  int i;
  for (i = 0; i < 8; i++)
    printchr("0123456789ABCDEF"[(n >> 28) & 15]), n <<= 4;
}


x86 assembly (clang, -O0):
<printhex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    1162 <printhex+0x52>
mov    -0x4(%rbp),%eax
shr    $0x1c,%eax
and    $0xf,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    0xec0(%rip),%rax
movsbl (%rax,%rcx,1),%edi
mov    $0x0,%al
call   1030 <printchr@plt>
mov    -0x4(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1122 <printhex+0x12>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printhex>:
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
xor    %eax,%eax
call   1030 <printchr@plt>
mov    %ebx,%eax
shr    $0x18,%eax
and    $0xf,%eax
movsbl (%rax,%r15,1),%edi
xor    %eax,%eax
call   1030 <printchr@plt>
mov    %ebx,%eax
shr    $0x14,%eax
and    $0xf,%eax
movsbl (%rax,%r15,1),%edi
xor    %eax,%eax
call   1030 <printchr@plt>
mov    %ebx,%eax
shr    $0x10,%eax
and    $0xf,%eax
movsbl (%rax,%r15,1),%edi
xor    %eax,%eax
call   1030 <printchr@plt>
mov    %ebx,%eax
shr    $0xc,%eax
and    $0xf,%eax
movsbl (%rax,%r15,1),%edi
xor    %eax,%eax
call   1030 <printchr@plt>
mov    %ebx,%eax
shr    $0x8,%eax
and    $0xf,%eax
movsbl (%rax,%r15,1),%edi
xor    %eax,%eax
call   1030 <printchr@plt>
shr    $0x4,%ebx
and    $0xf,%ebx
movsbl (%rbx,%r15,1),%edi
xor    %eax,%eax
call   1030 <printchr@plt>
and    $0xf,%r14d
movsbl (%r14,%r15,1),%edi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <printchr@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"0123456789ABCDEF\00"
define void @printhex(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
br label %4
4: ; preds = %18, %1
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 8
br i1 %6, label %7, label %21
7: ; preds = %4
%8 = load i32, i32* %2
%9 = lshr i32 %8, 28
%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 = sext i8 %13 to i32
%15 = call i32 (i32, ...) bitcast (i32 (...)* @printchr to i32 (i32, ...)*)(i32 %14)
%16 = load i32, i32* %2
%17 = shl i32 %16, 4
store i32 %17, i32* %2
br label %18
18: ; preds = %7
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %4
21: ; preds = %4
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789ABCDEF\00"
define void @printhex(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 = sext i8 %5 to i32
%7 = tail call i32 (i32, ...) bitcast (i32 (...)* @printchr to i32 (i32, ...)*)(i32 %6)
%8 = lshr i32 %0, 24
%9 = and i32 %8, 15
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = tail call i32 (i32, ...) bitcast (i32 (...)* @printchr to i32 (i32, ...)*)(i32 %13)
%15 = lshr i32 %0, 20
%16 = and i32 %15, 15
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = tail call i32 (i32, ...) bitcast (i32 (...)* @printchr to i32 (i32, ...)*)(i32 %20)
%22 = lshr i32 %0, 16
%23 = and i32 %22, 15
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = tail call i32 (i32, ...) bitcast (i32 (...)* @printchr to i32 (i32, ...)*)(i32 %27)
%29 = lshr i32 %0, 12
%30 = and i32 %29, 15
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = tail call i32 (i32, ...) bitcast (i32 (...)* @printchr to i32 (i32, ...)*)(i32 %34)
%36 = lshr i32 %0, 8
%37 = and i32 %36, 15
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = tail call i32 (i32, ...) bitcast (i32 (...)* @printchr to i32 (i32, ...)*)(i32 %41)
%43 = lshr i32 %0, 4
%44 = and i32 %43, 15
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = tail call i32 (i32, ...) bitcast (i32 (...)* @printchr to i32 (i32, ...)*)(i32 %48)
%50 = and i32 %0, 15
%51 = zext i32 %50 to i64
%52 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = tail call i32 (i32, ...) bitcast (i32 (...)* @printchr to i32 (i32, ...)*)(i32 %54)
ret void
}