#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 id_to_hex(char *str, uint32_t id) {
  int i;
  static char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
                         '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
  str[0] = ':';
  for (i = 0; i < 8; i++) {
    str[i + 1] = hex[(id >> ((7 - i) * 4)) & 0xf];
  }
  str[9] = '\0';
}


x86 assembly (clang, -O0):
<id_to_hex>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x3a,(%rax)
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    1161 <id_to_hex+0x61>
mov    -0xc(%rbp),%eax
mov    $0x7,%ecx
sub    -0x10(%rbp),%ecx
shl    $0x2,%ecx
sar    %cl,%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0x2ef0(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1119 <id_to_hex+0x19>
mov    -0x8(%rbp),%rax
movb   $0x0,0x9(%rax)
pop    %rbp
ret

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

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

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