#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 uint32_t;

/* Variables and functions */
void number2hex(char *s, uint32_t id) {
  char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
                  '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
  uint32_t i;
  for (i = 0; i < 8; i++) {
    s[i] = hex[(id >> (28 - 4 * i)) & 0xf];
  }
  s[8] = '\0';
}


x86 assembly (clang, -O0):
<number2hex>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0xeee(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeeb(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x8,-0x24(%rbp)
jge    1166 <number2hex+0x66>
mov    -0xc(%rbp),%eax
mov    -0x24(%rbp),%edx
shl    $0x2,%edx
mov    $0x1c,%ecx
sub    %edx,%ecx
sar    %cl,%eax
and    $0xf,%eax
cltq
mov    -0x20(%rbp,%rax,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1128 <number2hex+0x28>
mov    -0x8(%rbp),%rax
movb   $0x0,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<number2hex>:
mov    %esi,%eax
mov    %rax,%rdx
shr    $0x1c,%rdx
lea    0xef0(%rip),%rcx
mov    (%rdx,%rcx,1),%dl
mov    %dl,(%rdi)
mov    %esi,%edx
shr    $0x18,%edx
and    $0xf,%edx
mov    (%rdx,%rcx,1),%dl
mov    %dl,0x1(%rdi)
mov    %esi,%edx
shr    $0x14,%edx
and    $0xf,%edx
mov    (%rdx,%rcx,1),%dl
mov    %dl,0x2(%rdi)
mov    %esi,%edx
shr    $0x10,%edx
and    $0xf,%edx
mov    (%rdx,%rcx,1),%dl
mov    %dl,0x3(%rdi)
mov    %esi,%edx
shr    $0xc,%edx
and    $0xf,%edx
mov    (%rdx,%rcx,1),%dl
mov    %dl,0x4(%rdi)
mov    %esi,%edx
shr    $0x8,%edx
and    $0xf,%edx
mov    (%rdx,%rcx,1),%dl
mov    %dl,0x5(%rdi)
shr    $0x4,%esi
and    $0xf,%esi
mov    (%rsi,%rcx,1),%dl
mov    %dl,0x6(%rdi)
and    $0xf,%eax
mov    (%rax,%rcx,1),%al
mov    %al,0x7(%rdi)
movb   $0x0,0x8(%rdi)
ret

LLVM IR (-O0):
@__const.number2hex.hex = [16 x i8] c"0123456789ABCDEF"
define void @number2hex(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [16 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = bitcast [16 x i8]* %5 to i8*
store i32 0, i32* %6
br label %8
8: ; preds = %25, %2
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 8
br i1 %10, label %11, label %28
11: ; preds = %8
%12 = load i32, i32* %4
%13 = load i32, i32* %6
%14 = mul nsw i32 4, %13
%15 = sub nsw i32 28, %14
%16 = ashr i32 %12, %15
%17 = and i32 %16, 15
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = load i8*, i8** %3
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 %20, i8* %24
br label %25
25: ; preds = %11
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %8
28: ; preds = %8
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i64 8
store i8 0, i8* %30
ret void
}

LLVM IR (-O2):
@__const.number2hex.hex = [16 x i8] c"0123456789ABCDEF"
define void @number2hex(i8* nocapture writeonly %0, i32 %1) {
%3 = lshr i32 %1, 28
%4 = zext i32 %3 to i64
%5 = getelementptr inbounds [16 x i8], [16 x i8]* @__const.number2hex.hex, i64 0, i64 %4
%6 = load i8, i8* %5
store i8 %6, i8* %0
%7 = lshr i32 %1, 24
%8 = and i32 %7, 15
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds [16 x i8], [16 x i8]* @__const.number2hex.hex, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %11, i8* %12
%13 = lshr i32 %1, 20
%14 = and i32 %13, 15
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [16 x i8], [16 x i8]* @__const.number2hex.hex, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %17, i8* %18
%19 = lshr i32 %1, 16
%20 = and i32 %19, 15
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [16 x i8], [16 x i8]* @__const.number2hex.hex, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %23, i8* %24
%25 = lshr i32 %1, 12
%26 = and i32 %25, 15
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds [16 x i8], [16 x i8]* @__const.number2hex.hex, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %29, i8* %30
%31 = lshr i32 %1, 8
%32 = and i32 %31, 15
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds [16 x i8], [16 x i8]* @__const.number2hex.hex, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = getelementptr inbounds i8, i8* %0, i64 5
store i8 %35, i8* %36
%37 = lshr i32 %1, 4
%38 = and i32 %37, 15
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds [16 x i8], [16 x i8]* @__const.number2hex.hex, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = getelementptr inbounds i8, i8* %0, i64 6
store i8 %41, i8* %42
%43 = and i32 %1, 15
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds [16 x i8], [16 x i8]* @__const.number2hex.hex, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = getelementptr inbounds i8, i8* %0, i64 7
store i8 %46, i8* %47
%48 = getelementptr inbounds i8, i8* %0, i64 8
store i8 0, i8* %48
ret void
}