#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 uint8_t;
typedef int int32_t;

/* Variables and functions */
void intToHex(int32_t value, char *buffer) {
  uint8_t i;
  for (i = 0; i < 4; i++) {
    buffer[i] = "0123456789ABCDEF"[value & 0xF];
    value >>= 4;
  }
  buffer[4] = 0;
}


x86 assembly (clang, -O0):
<intToHex>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    1151 <intToHex+0x51>
mov    -0x4(%rbp),%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xed4(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1112 <intToHex+0x12>
mov    -0x10(%rbp),%rax
movb   $0x0,0x4(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<intToHex>:
mov    %edi,%eax
and    $0xf,%eax
lea    0xef4(%rip),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,(%rsi)
mov    %edi,%eax
shr    $0x4,%eax
and    $0xf,%eax
mov    (%rax,%rcx,1),%al
mov    %al,0x1(%rsi)
mov    %edi,%eax
shr    $0x8,%eax
and    $0xf,%eax
mov    (%rax,%rcx,1),%al
mov    %al,0x2(%rsi)
shr    $0xc,%edi
and    $0xf,%edi
mov    (%rdi,%rcx,1),%al
mov    %al,0x3(%rsi)
movb   $0x0,0x4(%rsi)
ret

LLVM IR (-O0):
@.str = [17 x i8] c"0123456789ABCDEF\00"
define void @intToHex(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 0, i32* %5
br label %6
6: ; preds = %21, %2
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 4
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = load i32, i32* %3
%11 = and i32 %10, 15
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %12
%14 = load i8, i8* %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 = ashr i32 %19, 4
store i32 %20, i32* %3
br label %21
21: ; preds = %9
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %6
24: ; preds = %6
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 4
store i8 0, i8* %26
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789ABCDEF\00"
define void @intToHex(i32 %0, i8* nocapture writeonly %1) {
%3 = and i32 %0, 15
%4 = zext i32 %3 to i64
%5 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %4
%6 = load i8, i8* %5
store i8 %6, i8* %1
%7 = lshr i32 %0, 4
%8 = and i32 %7, 15
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %11, i8* %12
%13 = lshr i32 %0, 8
%14 = and i32 %13, 15
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %17, i8* %18
%19 = lshr i32 %0, 12
%20 = and i32 %19, 15
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %23, i8* %24
%25 = getelementptr inbounds i8, i8* %1, i64 4
store i8 0, i8* %25
ret void
}