#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*/ printc(char);
int /*<<< orphan*/ prints(char *);
void printh(unsigned n) {
  int i;
  prints("0x");
  for (i = 0; i < 8; i++) {
    int d = n >> 28;
    n <<= 4;
    printc("0123456789abcdef"[d]);
  }
}


x86 assembly (clang, -O0):
<printh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xece(%rip),%rdi
call   1030 <prints@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    117c <printh+0x5c>
mov    -0x4(%rbp),%eax
shr    $0x1c,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x4(%rbp)
movslq -0xc(%rbp),%rcx
lea    0xe9e(%rip),%rax
movsbl (%rax,%rcx,1),%edi
call   1040 <printc@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    113e <printh+0x1e>
add    $0x10,%rsp
pop    %rbp
ret

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

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

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