#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*/ rever(char *);
char tohex(int);
void dec2hex(int n, char s[]) {
  int i = 0;
  int mod;
  if (n <= 0) {
    s[0] = '\0';
    return;
  }
  while (n) {
    mod = n % 16;
    s[i++] = tohex(mod);
    n = n / 16;
  }
  s[i] = '\0';
  rever(s);
}


x86 assembly (clang, -O0):
<dec2hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     114c <dec2hex+0x2c>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    11b0 <dec2hex+0x90>
jmp    1151 <dec2hex+0x31>
cmpl   $0x0,-0x4(%rbp)
je     119b <dec2hex+0x7b>
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <tohex@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1151 <dec2hex+0x31>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <rever@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dec2hex>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
test   %edi,%edi
jle    1174 <dec2hex+0x54>
xor    %ebx,%ebx
lea    0xf(%rdi),%r15d
test   %edi,%edi
mov    %edi,%ebp
cmovs  %r15d,%ebp
mov    %ebp,%eax
and    $0xfffffff0,%eax
sub    %eax,%edi
call   1040 <tohex@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
sar    $0x4,%ebp
mov    %ebp,%edi
cmp    $0x1e,%r15d
ja     1130 <dec2hex+0x10>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <rever@plt>
movb   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @dec2hex(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %5
%7 = load i32, i32* %3
%8 = icmp sle i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i64 0
store i8 0, i8* %11
br label %35
12: ; preds = %2
br label %13
13: ; preds = %16, %12
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %13
%17 = load i32, i32* %3
%18 = srem i32 %17, 16
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = call signext i8 @tohex(i32 %19)
%21 = load i8*, i8** %4
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
store i8 %20, i8* %25
%26 = load i32, i32* %3
%27 = sdiv i32 %26, 16
store i32 %27, i32* %3
br label %13
28: ; preds = %13
%29 = load i8*, i8** %4
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 0, i8* %32
%33 = load i8*, i8** %4
%34 = call i32 @rever(i8* %33)
br label %35
35: ; preds = %28, %9
ret void
}

LLVM IR (-O2):
define void @dec2hex(i32 %0, i8* %1) {
%3 = icmp slt i32 %0, 1
br i1 %3, label %4, label %5
4: ; preds = %2
store i8 0, i8* %1
br label %19
5: ; preds = %2, %5
%6 = phi i64 [ %10, %5 ], [ 0, %2 ]
%7 = phi i32 [ %12, %5 ], [ %0, %2 ]
%8 = srem i32 %7, 16
%9 = tail call signext i8 @tohex(i32 %8)
%10 = add nuw i64 %6, 1
%11 = getelementptr inbounds i8, i8* %1, i64 %6
store i8 %9, i8* %11
%12 = sdiv i32 %7, 16
%13 = add i32 %7, 15
%14 = icmp ult i32 %13, 31
br i1 %14, label %15, label %5
15: ; preds = %5
%16 = and i64 %10, 4294967295
%17 = getelementptr inbounds i8, i8* %1, i64 %16
store i8 0, i8* %17
%18 = tail call i32 @rever(i8* %1)
br label %19
19: ; preds = %15, %4
ret void
}