#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 */
char tohex(unsigned int);
void itox(unsigned int val, char *buffer) {
  int i = 8;
  while (i > 0) {
    i--;
    buffer[i] = tohex(val & 0x0f);
    val >>= 4;
  }
}


x86 assembly (clang, -O0):
<itox>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x8,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    115f <itox+0x4f>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
and    $0xf,%edi
call   1030 <tohex@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
shr    $0x4,%eax
mov    %eax,-0x4(%rbp)
jmp    1126 <itox+0x16>
add    $0x20,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define void @itox(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 8, i32* %5
br label %6
6: ; preds = %9, %2
%7 = load i32, i32* %5
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %6
%10 = load i32, i32* %5
%11 = add nsw i32 %10, -1
store i32 %11, i32* %5
%12 = load i32, i32* %3
%13 = and i32 %12, 15
%14 = call signext i8 @tohex(i32 %13)
%15 = load i8*, i8** %4
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8 %14, i8* %18
%19 = load i32, i32* %3
%20 = lshr i32 %19, 4
store i32 %20, i32* %3
br label %6
21: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @itox(i32 %0, i8* nocapture writeonly %1) {
%3 = and i32 %0, 15
%4 = tail call signext i8 @tohex(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 @tohex(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 @tohex(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 @tohex(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 @tohex(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 @tohex(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 @tohex(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 @tohex(i32 %30)
store i8 %31, i8* %1
ret void
}