#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*/ d2_putc(int, char);
void d2_putx(int fd, int x) {
  char chars[] = "0123456789ABCDEF";
  if (x / 16) {
    d2_putx(fd, x / 16);
    d2_putc(fd, chars[x % 16]);
  } else
    d2_putc(fd, chars[x]);
}


x86 assembly (clang, -O0):
<d2_putx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0xecb(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec8(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xec6(%rip),%al
mov    %al,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%eax
je     1196 <d2_putx+0x76>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
call   1030 <d2_putx@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movsbl -0x20(%rbp,%rax,1),%esi
call   1040 <d2_putc@plt>
jmp    11a7 <d2_putx+0x87>
mov    -0x4(%rbp),%edi
movslq -0x8(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%esi
call   1040 <d2_putc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d2_putx>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%r14d
lea    0xf(%rbx),%ebp
cmp    $0x1e,%ebp
jbe    1148 <d2_putx+0x28>
test   %ebx,%ebx
cmovns %ebx,%ebp
mov    %ebp,%esi
sar    $0x4,%esi
mov    %r14d,%edi
call   1030 <d2_putx@plt>
and    $0xfffffff0,%ebp
sub    %ebp,%ebx
movslq %ebx,%rax
lea    0xeae(%rip),%rcx
movsbl (%rax,%rcx,1),%esi
mov    %r14d,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <d2_putc@plt>

LLVM IR (-O0):
@__const.d2_putx.chars = [17 x i8] c"0123456789ABCDEF\00"
define void @d2_putx(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [17 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = bitcast [17 x i8]* %5 to i8*
%7 = load i32, i32* %4
%8 = sdiv i32 %7, 16
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %2
%11 = load i32, i32* %3
%12 = load i32, i32* %4
%13 = sdiv i32 %12, 16
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = srem i32 %15, 16
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @d2_putc(i32 %14, i8 signext %19)
br label %28
21: ; preds = %2
%22 = load i32, i32* %3
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @d2_putc(i32 %22, i8 signext %26)
br label %28
28: ; preds = %21, %10
ret void
}

LLVM IR (-O2):
@__const.d2_putx.chars = [17 x i8] c"0123456789ABCDEF\00"
define void @d2_putx(i32 %0, i32 %1) {
%3 = add i32 %1, 15
%4 = icmp ult i32 %3, 31
br i1 %4, label %5, label %11
5: ; preds = %2, %11
%6 = phi i32 [ %13, %11 ], [ %1, %2 ]
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.d2_putx.chars, i64 0, i64 %7
%9 = load i8, i8* %8
%10 = tail call i32 @d2_putc(i32 %0, i8 signext %9)
ret void
11: ; preds = %2
%12 = sdiv i32 %1, 16
tail call void @d2_putx(i32 %0, i32 %12)
%13 = srem i32 %1, 16
br label %5
}