#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 */
unsigned int pow(int, unsigned int const);
int /*<<< orphan*/ putchar(char);
unsigned int ulen(unsigned int const, int);
int print_uhex(const unsigned int number) {
  unsigned int i, digit;
  const unsigned int ln = ulen(number, 16);
  unsigned int mult = pow(16, ln - 1);
  putchar('0');
  putchar('x');
  for (i = 0; i < ln; ++i) {
    digit = (number / mult) % 16;
    if (digit < 10) {
      putchar((char)digit + 0x30);
    } else if (digit < 16) {
      putchar((char)(digit - 10) + 0x61);
    } else {
      putchar('?');
    }
    mult /= 16;
  }
  return ln + 2;
}


x86 assembly (clang, -O0):
<print_uhex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x10,%esi
call   1040 <ulen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
sub    $0x1,%esi
mov    $0x10,%edi
call   1050 <pow@plt>
mov    %eax,-0x14(%rbp)
mov    $0x30,%edi
call   1030 <putchar@plt>
mov    $0x78,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    11fc <print_uhex+0xcc>
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x14(%rbp)
and    $0xf,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jae    11b3 <print_uhex+0x83>
mov    -0xc(%rbp),%eax
movsbl %al,%eax
add    $0x30,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    11e5 <print_uhex+0xb5>
cmpl   $0x10,-0xc(%rbp)
jae    11d6 <print_uhex+0xa6>
mov    -0xc(%rbp),%eax
sub    $0xa,%eax
movsbl %al,%eax
add    $0x61,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    11e0 <print_uhex+0xb0>
mov    $0x3f,%edi
call   1030 <putchar@plt>
jmp    11e5 <print_uhex+0xb5>
mov    -0x14(%rbp),%eax
shr    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1179 <print_uhex+0x49>
mov    -0x10(%rbp),%eax
add    $0x2,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_uhex>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
mov    $0x10,%esi
call   1040 <ulen@plt>
mov    %eax,%r14d
lea    -0x1(%r14),%esi
mov    $0x10,%edi
call   1050 <pow@plt>
mov    %eax,%ebp
mov    $0x30,%edi
call   1030 <putchar@plt>
mov    $0x78,%edi
call   1030 <putchar@plt>
cmp    $0x1,%r14d
jb     11ac <print_uhex+0x7c>
mov    %r14d,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15d,%eax
xor    %edx,%edx
div    %ebp
and    $0xf,%eax
lea    0x57(%rax),%ecx
lea    0x30(%rax),%edx
cmp    $0xa,%eax
movzbl %dl,%eax
movzbl %cl,%ecx
cmovb  %eax,%ecx
movzbl %cl,%edi
call   1030 <putchar@plt>
shr    $0x4,%ebp
add    $0xffffffff,%ebx
jne    1180 <print_uhex+0x50>
add    $0x2,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @print_uhex(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = call i32 @ulen(i32 %7, i32 16)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = sub i32 %9, 1
%11 = call i32 @pow(i32 16, i32 %10)
store i32 %11, i32* %6
%12 = call i32 @putchar(i8 signext 48)
%13 = call i32 @putchar(i8 signext 120)
store i32 0, i32* %3
br label %14
14: ; preds = %49, %1
%15 = load i32, i32* %3
%16 = load i32, i32* %5
%17 = icmp ult i32 %15, %16
br i1 %17, label %18, label %52
18: ; preds = %14
%19 = load i32, i32* %2
%20 = load i32, i32* %6
%21 = udiv i32 %19, %20
%22 = urem i32 %21, 16
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp ult i32 %23, 10
br i1 %24, label %25, label %32
25: ; preds = %18
%26 = load i32, i32* %4
%27 = trunc i32 %26 to i8
%28 = sext i8 %27 to i32
%29 = add nsw i32 %28, 48
%30 = trunc i32 %29 to i8
%31 = call i32 @putchar(i8 signext %30)
br label %46
32: ; preds = %18
%33 = load i32, i32* %4
%34 = icmp ult i32 %33, 16
br i1 %34, label %35, label %43
35: ; preds = %32
%36 = load i32, i32* %4
%37 = sub i32 %36, 10
%38 = trunc i32 %37 to i8
%39 = sext i8 %38 to i32
%40 = add nsw i32 %39, 97
%41 = trunc i32 %40 to i8
%42 = call i32 @putchar(i8 signext %41)
br label %45
43: ; preds = %32
%44 = call i32 @putchar(i8 signext 63)
br label %45
45: ; preds = %43, %35
br label %46
46: ; preds = %45, %25
%47 = load i32, i32* %6
%48 = udiv i32 %47, 16
store i32 %48, i32* %6
br label %49
49: ; preds = %46
%50 = load i32, i32* %3
%51 = add i32 %50, 1
store i32 %51, i32* %3
br label %14
52: ; preds = %14
%53 = load i32, i32* %5
%54 = add i32 %53, 2
ret i32 %54
}

LLVM IR (-O2):
define i32 @print_uhex(i32 %0) {
%2 = tail call i32 @ulen(i32 %0, i32 16)
%3 = add i32 %2, -1
%4 = tail call i32 @pow(i32 16, i32 %3)
%5 = tail call i32 @putchar(i8 signext 48)
%6 = tail call i32 @putchar(i8 signext 120)
%7 = icmp eq i32 %2, 0
br i1 %7, label %22, label %8
8: ; preds = %1, %8
%9 = phi i32 [ %19, %8 ], [ %4, %1 ]
%10 = phi i32 [ %20, %8 ], [ 0, %1 ]
%11 = udiv i32 %0, %9
%12 = and i32 %11, 15
%13 = icmp ult i32 %12, 10
%14 = trunc i32 %12 to i8
%15 = add nuw nsw i8 %14, 87
%16 = or i8 %14, 48
%17 = select i1 %13, i8 %16, i8 %15
%18 = tail call i32 @putchar(i8 signext %17)
%19 = lshr i32 %9, 4
%20 = add nuw i32 %10, 1
%21 = icmp eq i32 %20, %2
br i1 %21, label %22, label %8
22: ; preds = %8, %1
%23 = add i32 %2, 2
ret i32 %23
}