#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);
void printx(unsigned int x) {
  char digit[16] = "0123456789ABCDEF";
  if (x == 0) {
    printc('0');
    return;
  }
  int i = 7;
  while (((x >> (4 * i)) & 0xF) == 0)
    i--;
  for (; i >= 0; i--) {
    printc(digit[(x >> (4 * i)) & 0xF]);
  }
}


x86 assembly (clang, -O0):
<printx>:
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)
cmpl   $0x0,-0x4(%rbp)
jne    114a <printx+0x3a>
mov    $0x30,%edi
call   1030 <printc@plt>
jmp    11ad <printx+0x9d>
movl   $0x7,-0x24(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x24(%rbp),%ecx
shl    $0x2,%ecx
shr    %cl,%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    1176 <printx+0x66>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1151 <printx+0x41>
jmp    117b <printx+0x6b>
cmpl   $0x0,-0x24(%rbp)
jl     11ad <printx+0x9d>
mov    -0x4(%rbp),%eax
mov    -0x24(%rbp),%ecx
shl    $0x2,%ecx
shr    %cl,%eax
and    $0xf,%eax
mov    %eax,%eax
movsbl -0x20(%rbp,%rax,1),%edi
call   1030 <printc@plt>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    117b <printx+0x6b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printx>:
test   %edi,%edi
je     1186 <printx+0x76>
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    $0x20,%ebp
mov    $0x9,%ebx
nopl   0x0(%rax,%rax,1)
add    $0xfffffffc,%ebp
mov    %r14d,%eax
mov    %ebp,%ecx
shr    %cl,%eax
add    $0xffffffff,%ebx
test   $0xf,%al
je     1130 <printx+0x20>
mov    %ebx,%eax
add    $0xffffffff,%eax
js     117b <printx+0x6b>
neg    %ebx
lea    0xeaf(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14d,%eax
mov    %ebp,%ecx
shr    %cl,%eax
and    $0xf,%eax
movsbl (%rax,%r15,1),%edi
call   1030 <printc@plt>
add    $0xfffffffc,%ebp
inc    %ebx
jne    1160 <printx+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x30,%edi
jmp    1030 <printc@plt>

LLVM IR (-O0):
@__const.printx.digit = [16 x i8] c"0123456789ABCDEF"
define void @printx(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 = load i32, i32* %2
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @printc(i8 signext 48)
br label %38
10: ; preds = %1
store i32 7, i32* %4
br label %11
11: ; preds = %18, %10
%12 = load i32, i32* %2
%13 = load i32, i32* %4
%14 = mul nsw i32 4, %13
%15 = lshr i32 %12, %14
%16 = and i32 %15, 15
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i32, i32* %4
%20 = add nsw i32 %19, -1
store i32 %20, i32* %4
br label %11
21: ; preds = %11
br label %22
22: ; preds = %35, %21
%23 = load i32, i32* %4
%24 = icmp sge i32 %23, 0
br i1 %24, label %25, label %38
25: ; preds = %22
%26 = load i32, i32* %2
%27 = load i32, i32* %4
%28 = mul nsw i32 4, %27
%29 = lshr i32 %26, %28
%30 = and i32 %29, 15
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = call i32 @printc(i8 signext %33)
br label %35
35: ; preds = %25
%36 = load i32, i32* %4
%37 = add nsw i32 %36, -1
store i32 %37, i32* %4
br label %22
38: ; preds = %8, %22
ret void
}

LLVM IR (-O2):
@__const.printx.digit = [16 x i8] c"0123456789ABCDEF"
define void @printx(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @printc(i8 signext 48)
br label %25
5: ; preds = %1, %5
%6 = phi i32 [ %11, %5 ], [ 7, %1 ]
%7 = shl nsw i32 %6, 2
%8 = shl i32 15, %7
%9 = and i32 %8, %0
%10 = icmp eq i32 %9, 0
%11 = add nsw i32 %6, -1
br i1 %10, label %5, label %12
12: ; preds = %5
%13 = icmp sgt i32 %6, -1
br i1 %13, label %14, label %25
14: ; preds = %12, %14
%15 = phi i32 [ %23, %14 ], [ %6, %12 ]
%16 = shl nsw i32 %15, 2
%17 = lshr i32 %0, %16
%18 = and i32 %17, 15
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds [16 x i8], [16 x i8]* @__const.printx.digit, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = tail call i32 @printc(i8 signext %21)
%23 = add nsw i32 %15, -1
%24 = icmp eq i32 %15, 0
br i1 %24, label %25, label %14
25: ; preds = %14, %12, %3
ret void
}