#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 hexvalue(int);
int strlen(char *);
void d_to_h(int dec[3], char hex[7]) {
  int countd, counth;
  hex[0] = '#';
  for (counth = 1, countd = 0; counth < strlen(hex); countd++, counth += 2) {
    hex[counth + 1] = hexvalue(dec[countd] % 16);
    dec[countd] /= 16;
    hex[counth] = hexvalue(dec[countd] % 16);
  }
}


x86 assembly (clang, -O0):
<d_to_h>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x23,(%rax)
movl   $0x1,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11eb <d_to_h+0xcb>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <hexvalue@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    $0x10,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x28(%rbp),%rax
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <hexvalue@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    1145 <d_to_h+0x25>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d_to_h>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
movb   $0x23,(%rsi)
mov    %rsi,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     1197 <d_to_h+0x77>
mov    $0x1,%ebx
mov    -0x2(%r14,%rbx,2),%edi
lea    0xf(%rdi),%eax
test   %edi,%edi
cmovns %edi,%eax
and    $0xfffffff0,%eax
sub    %eax,%edi
call   1030 <hexvalue@plt>
mov    %al,0x1(%r15,%rbx,1)
mov    -0x2(%r14,%rbx,2),%eax
lea    0xf(%rax),%edi
test   %eax,%eax
cmovns %eax,%edi
sar    $0x4,%edi
mov    %edi,-0x2(%r14,%rbx,2)
lea    0xf(%rdi),%eax
test   %edi,%edi
cmovns %edi,%eax
and    $0xfffffff0,%eax
sub    %eax,%edi
call   1030 <hexvalue@plt>
mov    %al,(%r15,%rbx,1)
add    $0x2,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    %ebx,%eax
jg     1140 <d_to_h+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @d_to_h(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
%7 = load i8*, i8** %4
%8 = getelementptr inbounds i8, i8* %7, i64 0
store i8 35, i8* %8
store i32 1, i32* %6
store i32 0, i32* %5
br label %9
9: ; preds = %44, %2
%10 = load i32, i32* %6
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %49
14: ; preds = %9
%15 = load i32*, i32** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = srem i32 %19, 16
%21 = call signext i8 @hexvalue(i32 %20)
%22 = load i8*, i8** %4
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8 %21, i8* %26
%27 = load i32*, i32** %3
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = sdiv i32 %31, 16
store i32 %32, i32* %30
%33 = load i32*, i32** %3
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = srem i32 %37, 16
%39 = call signext i8 @hexvalue(i32 %38)
%40 = load i8*, i8** %4
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 %39, i8* %43
br label %44
44: ; preds = %14
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %5
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 2
store i32 %48, i32* %6
br label %9
49: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @d_to_h(i32* nocapture %0, i8* %1) {
store i8 35, i8* %1
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp sgt i32 %3, 1
br i1 %4, label %5, label %24
5: ; preds = %2, %5
%6 = phi i64 [ %19, %5 ], [ 0, %2 ]
%7 = phi i64 [ %20, %5 ], [ 1, %2 ]
%8 = getelementptr inbounds i32, i32* %0, i64 %6
%9 = load i32, i32* %8
%10 = srem i32 %9, 16
%11 = tail call signext i8 @hexvalue(i32 %10)
%12 = add nuw nsw i64 %7, 1
%13 = getelementptr inbounds i8, i8* %1, i64 %12
store i8 %11, i8* %13
%14 = load i32, i32* %8
%15 = sdiv i32 %14, 16
store i32 %15, i32* %8
%16 = srem i32 %15, 16
%17 = tail call signext i8 @hexvalue(i32 %16)
%18 = getelementptr inbounds i8, i8* %1, i64 %7
store i8 %17, i8* %18
%19 = add nuw i64 %6, 1
%20 = add nuw i64 %7, 2
%21 = tail call i32 @strlen(i8* %1)
%22 = trunc i64 %20 to i32
%23 = icmp sgt i32 %21, %22
br i1 %23, label %5, label %24
24: ; preds = %5, %2
ret void
}