#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*/ printf(char *, int, int, int);
int /*<<< orphan*/ scanf(char *, ...);
int tohex(char);
int main() {
  char c;
  scanf("%c%*c", &c);
  switch (c) {
  case 'd': {
    int r, g, b;
    scanf("%d, %d, %d", &r, &g, &b);
    printf("#%x%x%x", r, g, b);
    break;
  }
  case 'h': {
    char num[6];
    scanf("%*c%s", num);
    printf("rgb(%d, %d, %d)\n", tohex(num[0]) * 16 + tohex(num[1]),
           tohex(num[2]) * 16 + tohex(num[3]),
           tohex(num[4]) * 16 + tohex(num[5]));
    break;
  }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
xor    %eax,%eax
lea    -0x5(%rbp),%rsi
call   1040 <scanf@plt>
movsbl -0x5(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x64,%eax
je     1177 <main+0x47>
jmp    1166 <main+0x36>
mov    -0x20(%rbp),%eax
sub    $0x68,%eax
je     11ab <main+0x7b>
jmp    1230 <main+0x100>
lea    0xe88(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
jmp    1230 <main+0x100>
lea    -0x1a(%rbp),%rsi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0x1a(%rbp),%edi
call   1050 <tohex@plt>
shl    $0x4,%eax
mov    %eax,-0x34(%rbp)
movsbl -0x19(%rbp),%edi
call   1050 <tohex@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
movsbl -0x18(%rbp),%edi
call   1050 <tohex@plt>
shl    $0x4,%eax
mov    %eax,-0x30(%rbp)
movsbl -0x17(%rbp),%edi
call   1050 <tohex@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
movsbl -0x16(%rbp),%edi
call   1050 <tohex@plt>
shl    $0x4,%eax
mov    %eax,-0x2c(%rbp)
movsbl -0x15(%rbp),%edi
call   1050 <tohex@plt>
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
add    %eax,%ecx
lea    0xdf4(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
lea    0xf(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
movsbl 0xf(%rsp),%eax
cmp    $0x68,%eax
je     1190 <main+0x60>
cmp    $0x64,%eax
jne    120a <main+0xda>
lea    0xea1(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x10(%rsp),%esi
mov    0x1c(%rsp),%edx
mov    0x18(%rsp),%ecx
lea    0xe83(%rip),%rdi
jmp    1205 <main+0xd5>
lea    0xe82(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
movsbl 0x10(%rsp),%edi
call   1050 <tohex@plt>
mov    %eax,%r14d
shl    $0x4,%r14d
movsbl 0x11(%rsp),%edi
call   1050 <tohex@plt>
add    %eax,%r14d
movsbl 0x12(%rsp),%edi
call   1050 <tohex@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x13(%rsp),%edi
call   1050 <tohex@plt>
add    %eax,%ebp
movsbl 0x14(%rsp),%edi
call   1050 <tohex@plt>
mov    %eax,%ebx
shl    $0x4,%ebx
movsbl 0x15(%rsp),%edi
call   1050 <tohex@plt>
add    %eax,%ebx
lea    0xe21(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%c%*c\00"
@.str.1 = [11 x i8] c"%d, %d, %d\00"
@.str.2 = [8 x i8] c"#%x%x%x\00"
@.str.3 = [6 x i8] c"%*c%s\00"
@.str.4 = [17 x i8] c"rgb(%d, %d, %d)\0A\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [6 x i8]
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %1)
%7 = load i8, i8* %1
%8 = sext i8 %7 to i32
switch i32 %8, label %45 [
i32 100, label %9
i32 104, label %18
]
9: ; preds = %0
%10 = bitcast i32* %2 to i8*
%11 = bitcast i32* %3 to i8*
%12 = bitcast i32* %4 to i8*
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %15, i32 %16)
br label %45
18: ; preds = %0
%19 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%21 = load i8, i8* %19
%22 = call i32 @tohex(i8 signext %21)
%23 = shl nsw i32 %22, 4
%24 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 1
%25 = load i8, i8* %24
%26 = call i32 @tohex(i8 signext %25)
%27 = add nsw i32 %26, %23
%28 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 2
%29 = load i8, i8* %28
%30 = call i32 @tohex(i8 signext %29)
%31 = shl nsw i32 %30, 4
%32 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 3
%33 = load i8, i8* %32
%34 = call i32 @tohex(i8 signext %33)
%35 = add nsw i32 %34, %31
%36 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 4
%37 = load i8, i8* %36
%38 = call i32 @tohex(i8 signext %37)
%39 = shl nsw i32 %38, 4
%40 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 5
%41 = load i8, i8* %40
%42 = call i32 @tohex(i8 signext %41)
%43 = add nsw i32 %42, %39
%44 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %27, i32 %35, i32 %43)
br label %45
45: ; preds = %0, %18, %9
ret i32 0
}