#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 get_char(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ scanf(char *, int *, int *, int *);
void dec_to_hex() {
  int dec[3], counter_h, counter_d;
  char hex[7];
  scanf("%d,%d,%d", &dec[0], &dec[1], &dec[2]);
  hex[0] = '#';
  for (counter_h = 1, counter_d = 0; counter_h < 7;
       counter_h += 2, counter_d++) {
    hex[counter_h + 1] = get_char(dec[counter_d] % 16);
    hex[counter_h] = get_char((dec[counter_d] / 16) % 16);
  }
  printf("%s\n", hex);
}


x86 assembly (clang, -O0):
<dec_to_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0xc(%rbp),%rsi
lea    -0xc(%rbp),%rdx
add    $0x4,%rdx
lea    -0xc(%rbp),%rcx
add    $0x8,%rcx
lea    0xead(%rip),%rdi
call   1040 <scanf@plt>
movb   $0x23,-0x1b(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x7,-0x10(%rbp)
jge    11d9 <dec_to_hex+0xa9>
movslq -0x14(%rbp),%rax
mov    -0xc(%rbp,%rax,4),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1050 <get_char@plt>
mov    %al,%cl
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cltq
mov    %cl,-0x1b(%rbp,%rax,1)
movslq -0x14(%rbp),%rax
mov    -0xc(%rbp,%rax,4),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1050 <get_char@plt>
mov    %al,%cl
movslq -0x10(%rbp),%rax
mov    %cl,-0x1b(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116a <dec_to_hex+0x3a>
lea    -0x1b(%rbp),%rsi
lea    0xe25(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dec_to_hex>:
sub    $0x18,%rsp
lea    0x10(%rsp),%rdx
lea    0x14(%rsp),%rcx
lea    0xebb(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
movb   $0x23,0x5(%rsp)
mov    0xc(%rsp),%edi
lea    0xf(%rdi),%eax
test   %edi,%edi
cmovns %edi,%eax
and    $0xfffffff0,%eax
sub    %eax,%edi
call   1050 <get_char@plt>
mov    0xc(%rsp),%ecx
lea    0xf(%rcx),%edi
test   %ecx,%ecx
cmovns %ecx,%edi
mov    %al,0x7(%rsp)
sar    $0x4,%edi
lea    0xf(%rdi),%eax
test   %edi,%edi
cmovns %edi,%eax
and    $0xfffffff0,%eax
sub    %eax,%edi
call   1050 <get_char@plt>
mov    %al,0x6(%rsp)
mov    0x10(%rsp),%edi
lea    0xf(%rdi),%eax
test   %edi,%edi
cmovns %edi,%eax
and    $0xfffffff0,%eax
sub    %eax,%edi
call   1050 <get_char@plt>
mov    0x10(%rsp),%ecx
lea    0xf(%rcx),%edi
test   %ecx,%ecx
cmovns %ecx,%edi
mov    %al,0x9(%rsp)
sar    $0x4,%edi
lea    0xf(%rdi),%eax
test   %edi,%edi
cmovns %edi,%eax
and    $0xfffffff0,%eax
sub    %eax,%edi
call   1050 <get_char@plt>
mov    %al,0x8(%rsp)
mov    0x14(%rsp),%edi
lea    0xf(%rdi),%eax
test   %edi,%edi
cmovns %edi,%eax
and    $0xfffffff0,%eax
sub    %eax,%edi
call   1050 <get_char@plt>
mov    0x14(%rsp),%ecx
lea    0xf(%rcx),%edi
test   %ecx,%ecx
cmovns %ecx,%edi
mov    %al,0xb(%rsp)
sar    $0x4,%edi
lea    0xf(%rdi),%eax
test   %edi,%edi
cmovns %edi,%eax
and    $0xfffffff0,%eax
sub    %eax,%edi
call   1050 <get_char@plt>
mov    %al,0xa(%rsp)
lea    0xdf1(%rip),%rdi
lea    0x5(%rsp),%rsi
call   1030 <printf@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%d,%d,%d\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @dec_to_hex() {
%1 = alloca [3 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = alloca [7 x i8]
%5 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%6 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
%8 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %6, i32* %7)
%9 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
store i8 35, i8* %9
store i32 1, i32* %2
store i32 0, i32* %3
br label %10
10: ; preds = %34, %0
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 7
br i1 %12, label %13, label %39
13: ; preds = %10
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = srem i32 %17, 16
%19 = call signext i8 @get_char(i32 %18)
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 %22
store i8 %19, i8* %23
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = sdiv i32 %27, 16
%29 = srem i32 %28, 16
%30 = call signext i8 @get_char(i32 %29)
%31 = load i32, i32* %2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 %32
store i8 %30, i8* %33
br label %34
34: ; preds = %13
%35 = load i32, i32* %2
%36 = add nsw i32 %35, 2
store i32 %36, i32* %2
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
br label %10
39: ; preds = %10
%40 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %40)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%d,%d,%d\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @dec_to_hex() {
%1 = alloca [3 x i32]
%2 = alloca [7 x i8]
%3 = bitcast [3 x i32]* %1 to i8*
%4 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%6 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
%8 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %6, i32* %7)
store i8 35, i8* %4
%9 = load i32, i32* %5
%10 = srem i32 %9, 16
%11 = call signext i8 @get_char(i32 %10)
%12 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 2
store i8 %11, i8* %12
%13 = load i32, i32* %5
%14 = sdiv i32 %13, 16
%15 = srem i32 %14, 16
%16 = call signext i8 @get_char(i32 %15)
%17 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 1
store i8 %16, i8* %17
%18 = load i32, i32* %6
%19 = srem i32 %18, 16
%20 = call signext i8 @get_char(i32 %19)
%21 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 4
store i8 %20, i8* %21
%22 = load i32, i32* %6
%23 = sdiv i32 %22, 16
%24 = srem i32 %23, 16
%25 = call signext i8 @get_char(i32 %24)
%26 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 3
store i8 %25, i8* %26
%27 = load i32, i32* %7
%28 = srem i32 %27, 16
%29 = call signext i8 @get_char(i32 %28)
%30 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 6
store i8 %29, i8* %30
%31 = load i32, i32* %7
%32 = sdiv i32 %31, 16
%33 = srem i32 %32, 16
%34 = call signext i8 @get_char(i32 %33)
%35 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 5
store i8 %34, i8* %35
%36 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4)
ret void
}