#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 */
typedef int uintmax_t;
typedef int /*<<< orphan*/ n;

/* Variables and functions */
char hexDigit(int);
int /*<<< orphan*/ reverseCharBuffer(char *const, int);
char *uintmaxToHexString(uintmax_t n) {
  static char string[3 + sizeof(n) * 2] = "0x";
  static char *const digits = string + 2;
  int i;
  for (i = 0; n; i++) {
    digits[i] = hexDigit(n % 16);
    n /= 16;
  }
  reverseCharBuffer(digits, i);
  digits[i + 1] = '\0';
  return string;
}


x86 assembly (clang, -O0):
<uintmaxToHexString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     117b <uintmaxToHexString+0x5b>
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <hexDigit@plt>
mov    %al,%dl
movslq -0x8(%rbp),%rcx
lea    0x2ed5(%rip),%rax
mov    %dl,0x2(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1132 <uintmaxToHexString+0x12>
mov    -0x8(%rbp),%esi
lea    0x2eab(%rip),%rdi
add    $0x2,%rdi
call   1040 <reverseCharBuffer@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rcx
lea    0x2e92(%rip),%rax
movb   $0x0,0x2(%rax,%rcx,1)
lea    0x2e86(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uintmaxToHexString>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
test   %edi,%edi
je     116c <uintmaxToHexString+0x4c>
lea    0x2efc(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xf(%rdi),%r15d
test   %edi,%edi
mov    %edi,%ebp
cmovs  %r15d,%ebp
mov    %ebp,%eax
and    $0xfffffff0,%eax
sub    %eax,%edi
call   1030 <hexDigit@plt>
mov    %al,0x2(%rbx,%r14,1)
sar    $0x4,%ebp
add    $0x1,%rbx
mov    %ebp,%edi
cmp    $0x1e,%r15d
ja     1140 <uintmaxToHexString+0x20>
lea    0x2ebf(%rip),%rdi
mov    %ebx,%esi
call   1040 <reverseCharBuffer@plt>
lea    0x2eaf(%rip),%rax
mov    %ebx,%ecx
movb   $0x0,0x3(%rcx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@uintmaxToHexString.string = internal global [11 x i8] c"0x\00\00\00\00\00\00\00\00\00"
@uintmaxToHexString.digits = internal constant i8* getelementptr inbounds ([11 x i8], [11 x i8]* @uintmaxToHexString.string, i32 0, i64 2)
define i8* @uintmaxToHexString(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
br label %4
4: ; preds = %16, %1
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %4
%8 = load i32, i32* %2
%9 = srem i32 %8, 16
%10 = call signext i8 @hexDigit(i32 %9)
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @uintmaxToHexString.string, i32 0, i64 2), i64 %12
store i8 %10, i8* %13
%14 = load i32, i32* %2
%15 = sdiv i32 %14, 16
store i32 %15, i32* %2
br label %16
16: ; preds = %7
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %4
19: ; preds = %4
%20 = load i32, i32* %3
%21 = call i32 @reverseCharBuffer(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @uintmaxToHexString.string, i32 0, i64 2), i32 %20)
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @uintmaxToHexString.string, i32 0, i64 2), i64 %24
store i8 0, i8* %25
ret i8* getelementptr inbounds ([11 x i8], [11 x i8]* @uintmaxToHexString.string, i64 0, i64 0)
}

LLVM IR (-O2):
@uintmaxToHexString.string = internal global [11 x i8] c"0x\00\00\00\00\00\00\00\00\00"
define i8* @uintmaxToHexString(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %15, label %3
3: ; preds = %1, %3
%4 = phi i64 [ %10, %3 ], [ 0, %1 ]
%5 = phi i32 [ %9, %3 ], [ %0, %1 ]
%6 = srem i32 %5, 16
%7 = tail call signext i8 @hexDigit(i32 %6)
%8 = getelementptr inbounds i8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @uintmaxToHexString.string, i64 0, i64 2), i64 %4
store i8 %7, i8* %8
%9 = sdiv i32 %5, 16
%10 = add nuw i64 %4, 1
%11 = add i32 %5, 15
%12 = icmp ult i32 %11, 31
br i1 %12, label %13, label %3
13: ; preds = %3
%14 = trunc i64 %10 to i32
br label %15
15: ; preds = %13, %1
%16 = phi i32 [ 0, %1 ], [ %14, %13 ]
%17 = tail call i32 @reverseCharBuffer(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @uintmaxToHexString.string, i64 0, i64 2), i32 %16)
%18 = add nuw nsw i32 %16, 1
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @uintmaxToHexString.string, i64 0, i64 2), i64 %19
store i8 0, i8* %20
ret i8* getelementptr inbounds ([11 x i8], [11 x i8]* @uintmaxToHexString.string, i64 0, i64 0)
}