#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 */
char num2char_hex(int);
int num2str_hex(uint32_t v, char *buf) {
  *(buf + 7) = num2char_hex(v & 0x0f);
  *(buf + 6) = num2char_hex((v >>= 4) & 0x0f);
  *(buf + 5) = num2char_hex((v >>= 4) & 0x0f);
  *(buf + 4) = num2char_hex((v >>= 4) & 0x0f);
  *(buf + 3) = num2char_hex((v >>= 4) & 0x0f);
  *(buf + 2) = num2char_hex((v >>= 4) & 0x0f);
  *(buf + 1) = num2char_hex((v >>= 4) & 0x0f);
  *(buf) = num2char_hex((v >>= 4) & 0x0f);
  return 8;
}


x86 assembly (clang, -O0):
<num2str_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
and    $0xf,%edi
call   1030 <num2char_hex@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x7(%rax)
mov    -0x4(%rbp),%edi
sar    $0x4,%edi
mov    %edi,-0x4(%rbp)
and    $0xf,%edi
call   1030 <num2char_hex@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x4(%rbp),%edi
sar    $0x4,%edi
mov    %edi,-0x4(%rbp)
and    $0xf,%edi
call   1030 <num2char_hex@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x4(%rbp),%edi
sar    $0x4,%edi
mov    %edi,-0x4(%rbp)
and    $0xf,%edi
call   1030 <num2char_hex@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x4(%rbp),%edi
sar    $0x4,%edi
mov    %edi,-0x4(%rbp)
and    $0xf,%edi
call   1030 <num2char_hex@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x4(%rbp),%edi
sar    $0x4,%edi
mov    %edi,-0x4(%rbp)
and    $0xf,%edi
call   1030 <num2char_hex@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x4(%rbp),%edi
sar    $0x4,%edi
mov    %edi,-0x4(%rbp)
and    $0xf,%edi
call   1030 <num2char_hex@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x4(%rbp),%edi
sar    $0x4,%edi
mov    %edi,-0x4(%rbp)
and    $0xf,%edi
call   1030 <num2char_hex@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    $0x8,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num2str_hex>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
and    $0xf,%edi
call   1030 <num2char_hex@plt>
mov    %al,0x7(%rbx)
mov    %ebp,%edi
shr    $0x4,%edi
and    $0xf,%edi
call   1030 <num2char_hex@plt>
mov    %al,0x6(%rbx)
mov    %ebp,%edi
shr    $0x8,%edi
and    $0xf,%edi
call   1030 <num2char_hex@plt>
mov    %al,0x5(%rbx)
mov    %ebp,%edi
shr    $0xc,%edi
and    $0xf,%edi
call   1030 <num2char_hex@plt>
mov    %al,0x4(%rbx)
mov    %ebp,%edi
shr    $0x10,%edi
and    $0xf,%edi
call   1030 <num2char_hex@plt>
mov    %al,0x3(%rbx)
mov    %ebp,%edi
shr    $0x14,%edi
and    $0xf,%edi
call   1030 <num2char_hex@plt>
mov    %al,0x2(%rbx)
mov    %ebp,%edi
shr    $0x18,%edi
and    $0xf,%edi
call   1030 <num2char_hex@plt>
mov    %al,0x1(%rbx)
shr    $0x1c,%ebp
mov    %ebp,%edi
call   1030 <num2char_hex@plt>
mov    %al,(%rbx)
mov    $0x8,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @num2str_hex(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i32, i32* %3
%6 = and i32 %5, 15
%7 = call signext i8 @num2char_hex(i32 %6)
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 7
store i8 %7, i8* %9
%10 = load i32, i32* %3
%11 = ashr i32 %10, 4
store i32 %11, i32* %3
%12 = and i32 %11, 15
%13 = call signext i8 @num2char_hex(i32 %12)
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 6
store i8 %13, i8* %15
%16 = load i32, i32* %3
%17 = ashr i32 %16, 4
store i32 %17, i32* %3
%18 = and i32 %17, 15
%19 = call signext i8 @num2char_hex(i32 %18)
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 5
store i8 %19, i8* %21
%22 = load i32, i32* %3
%23 = ashr i32 %22, 4
store i32 %23, i32* %3
%24 = and i32 %23, 15
%25 = call signext i8 @num2char_hex(i32 %24)
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 4
store i8 %25, i8* %27
%28 = load i32, i32* %3
%29 = ashr i32 %28, 4
store i32 %29, i32* %3
%30 = and i32 %29, 15
%31 = call signext i8 @num2char_hex(i32 %30)
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 3
store i8 %31, i8* %33
%34 = load i32, i32* %3
%35 = ashr i32 %34, 4
store i32 %35, i32* %3
%36 = and i32 %35, 15
%37 = call signext i8 @num2char_hex(i32 %36)
%38 = load i8*, i8** %4
%39 = getelementptr inbounds i8, i8* %38, i64 2
store i8 %37, i8* %39
%40 = load i32, i32* %3
%41 = ashr i32 %40, 4
store i32 %41, i32* %3
%42 = and i32 %41, 15
%43 = call signext i8 @num2char_hex(i32 %42)
%44 = load i8*, i8** %4
%45 = getelementptr inbounds i8, i8* %44, i64 1
store i8 %43, i8* %45
%46 = load i32, i32* %3
%47 = ashr i32 %46, 4
store i32 %47, i32* %3
%48 = and i32 %47, 15
%49 = call signext i8 @num2char_hex(i32 %48)
%50 = load i8*, i8** %4
store i8 %49, i8* %50
ret i32 8
}

LLVM IR (-O2):
define i32 @num2str_hex(i32 %0, i8* nocapture writeonly %1) {
%3 = and i32 %0, 15
%4 = tail call signext i8 @num2char_hex(i32 %3)
%5 = getelementptr inbounds i8, i8* %1, i64 7
store i8 %4, i8* %5
%6 = lshr i32 %0, 4
%7 = and i32 %6, 15
%8 = tail call signext i8 @num2char_hex(i32 %7)
%9 = getelementptr inbounds i8, i8* %1, i64 6
store i8 %8, i8* %9
%10 = lshr i32 %0, 8
%11 = and i32 %10, 15
%12 = tail call signext i8 @num2char_hex(i32 %11)
%13 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %12, i8* %13
%14 = lshr i32 %0, 12
%15 = and i32 %14, 15
%16 = tail call signext i8 @num2char_hex(i32 %15)
%17 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %16, i8* %17
%18 = lshr i32 %0, 16
%19 = and i32 %18, 15
%20 = tail call signext i8 @num2char_hex(i32 %19)
%21 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %20, i8* %21
%22 = lshr i32 %0, 20
%23 = and i32 %22, 15
%24 = tail call signext i8 @num2char_hex(i32 %23)
%25 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %24, i8* %25
%26 = lshr i32 %0, 24
%27 = and i32 %26, 15
%28 = tail call signext i8 @num2char_hex(i32 %27)
%29 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %28, i8* %29
%30 = lshr i32 %0, 28
%31 = tail call signext i8 @num2char_hex(i32 %30)
store i8 %31, i8* %1
ret i32 8
}