#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 */
int /*<<< orphan*/ reverse_string(char *);
void hexadecimal(int number, char *buffer) {
  int counter;
  char HEXDIGITS[] = "0123456789ABCDEF";
  for (counter = 0; number > 0; number /= 16, counter++) {
    buffer[counter] = HEXDIGITS[number % 16];
  }
  buffer[counter] = '\0';
  reverse_string(buffer);
}


x86 assembly (clang, -O0):
<hexadecimal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeda(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xed7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xed5(%rip),%al
mov    %al,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1188 <hexadecimal+0x78>
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x30(%rbp,%rax,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1145 <hexadecimal+0x35>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <reverse_string@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexadecimal>:
xor    %eax,%eax
test   %edi,%edi
jle    113c <hexadecimal+0x2c>
lea    0xee3(%rip),%rcx
nopl   (%rax)
mov    %edi,%edx
and    $0xf,%edx
movzbl (%rdx,%rcx,1),%edx
mov    %dl,(%rsi,%rax,1)
mov    %edi,%edx
shr    $0x4,%edx
add    $0x1,%rax
cmp    $0xf,%edi
mov    %edx,%edi
ja     1120 <hexadecimal+0x10>
movb   $0x0,(%rsi,%rax,1)
mov    %rsi,%rdi
jmp    1030 <reverse_string@plt>

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

LLVM IR (-O2):
@__const.hexadecimal.HEXDIGITS = [17 x i8] c"0123456789ABCDEF\00"
define void @hexadecimal(i32 %0, i8* %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %17
4: ; preds = %2, %4
%5 = phi i64 [ %13, %4 ], [ 0, %2 ]
%6 = phi i32 [ %12, %4 ], [ %0, %2 ]
%7 = and i32 %6, 15
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.hexadecimal.HEXDIGITS, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %1, i64 %5
store i8 %10, i8* %11
%12 = lshr i32 %6, 4
%13 = add nuw nsw i64 %5, 1
%14 = icmp ult i32 %6, 16
br i1 %14, label %15, label %4
15: ; preds = %4
%16 = and i64 %13, 4294967295
br label %17
17: ; preds = %15, %2
%18 = phi i64 [ 0, %2 ], [ %16, %15 ]
%19 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 0, i8* %19
%20 = tail call i32 @reverse_string(i8* %1)
ret void
}