#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*/ convert_to_dec(char **);
int convert_to_hex(int, int, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *, int *);
int main() {
  char input = '\0';
  scanf("%c", &input);
  if (input == 'h') {
    char hex_input[100];
    scanf("%s", hex_input);
    convert_to_dec(&hex_input);
  } else if (input == 'd') {
    scanf("%c", &input);
    char input[100];
    int a = 0;
    int b = 0;
    int c = 0;
    scanf("%[^\n]s", input);
    sscanf(input, "%d, %d, %d", &a, &b, &c);
    printf("#%x\n", convert_to_hex(a, b, c));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
lea    0xe93(%rip),%rdi
lea    -0x5(%rbp),%rsi
call   1070 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x68,%eax
jne    11a1 <main+0x51>
lea    -0x70(%rbp),%rsi
lea    0xe75(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x70(%rbp),%rdi
call   1040 <convert_to_dec@plt>
jmp    1241 <main+0xf1>
movsbl -0x5(%rbp),%eax
cmp    $0x64,%eax
jne    123c <main+0xec>
lea    0xe4b(%rip),%rdi
lea    -0x5(%rbp),%rsi
call   1070 <scanf@plt>
movl   $0x0,-0xe4(%rbp)
movl   $0x0,-0xe8(%rbp)
movl   $0x0,-0xec(%rbp)
lea    -0xe0(%rbp),%rsi
lea    0xe1c(%rip),%rdi
call   1070 <scanf@plt>
lea    -0xe0(%rbp),%rdi
lea    0xe10(%rip),%rsi
lea    -0xe4(%rbp),%rdx
lea    -0xe8(%rbp),%rcx
lea    -0xec(%rbp),%r8
call   1060 <sscanf@plt>
mov    -0xe4(%rbp),%edi
mov    -0xe8(%rbp),%esi
mov    -0xec(%rbp),%edx
call   1030 <convert_to_hex@plt>
mov    %eax,%esi
lea    0xde1(%rip),%rdi
call   1050 <printf@plt>
jmp    1241 <main+0xf1>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
movb   $0x0,0x3(%rsp)
lea    0xe9c(%rip),%rdi
lea    0x3(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x3(%rsp),%al
cmp    $0x64,%al
je     119c <main+0x4c>
cmp    $0x68,%al
jne    1216 <main+0xc6>
lea    0xe7e(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    %rbx,%rdi
call   1040 <convert_to_dec@plt>
jmp    1216 <main+0xc6>
lea    0xe5d(%rip),%rdi
lea    0x3(%rsp),%rsi
call   1070 <scanf@plt>
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
lea    0xe3a(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0xe2d(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %rbx,%rdi
call   1060 <sscanf@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
call   1030 <convert_to_hex@plt>
lea    0xe09(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [7 x i8] c"%[^\0A]s\00"
@.str.3 = [11 x i8] c"%d, %d, %d\00"
@.str.4 = [5 x i8] c"#%x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i8 0, i8* %2
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 104
br i1 %11, label %12, label %17
12: ; preds = %0
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = bitcast [100 x i8]* %3 to i8**
%16 = call i32 @convert_to_dec(i8** %15)
br label %33
17: ; preds = %0
%18 = load i8, i8* %2
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 100
br i1 %20, label %21, label %32
21: ; preds = %17
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%24 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%26 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32* %5, i32* %6, i32* %7)
%27 = load i32, i32* %5
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = call i32 @convert_to_hex(i32 %27, i32 %28, i32 %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %21, %17
br label %33
33: ; preds = %32, %12
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [7 x i8] c"%[^\0A]s\00"
@.str.3 = [11 x i8] c"%d, %d, %d\00"
@.str.4 = [5 x i8] c"#%x\0A\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8 0, i8* %1
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%8 = load i8, i8* %1
switch i8 %8, label %27 [
i8 104, label %9
i8 100, label %14
]
9: ; preds = %0
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = bitcast [100 x i8]* %2 to i8**
%13 = call i32 @convert_to_dec(i8** %12)
br label %27
14: ; preds = %0
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%17 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%18 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%19 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%20 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%21 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32* %4, i32* %5, i32* %6)
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = call i32 @convert_to_hex(i32 %22, i32 %23, i32 %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %0, %14, %9
ret i32 0
}