#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*/ HEXTODEC(char *);
int /*<<< orphan*/ printf(char *, int, int, int);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int RGB1, RGB2, RGB3;
  char t, str[6];
  do {
    scanf("%s", &t);
  } while (t != 'h' && t != 'd');
  if (t == 'd') {
    scanf("%d, %d, %d", &RGB1, &RGB2, &RGB3);
    printf("#%x%x%x", RGB1, RGB2, RGB3);
  } else {
    scanf("%*c#%s", str);
    HEXTODEC(str);
    RGB1 = (str[0] * 16) + str[1];
    RGB2 = (str[2] * 16) + str[3];
    RGB3 = (str[4] * 16) + str[5];
    printf("rgb(%d, %d, %d)", RGB1, RGB2, RGB3);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xed1(%rip),%rdi
lea    -0x11(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0x68,%ecx
mov    %al,-0x18(%rbp)
je     1170 <main+0x40>
movsbl -0x11(%rbp),%eax
cmp    $0x64,%eax
setne  %al
mov    %al,-0x18(%rbp)
mov    -0x18(%rbp),%al
test   $0x1,%al
jne    113f <main+0xf>
movsbl -0x11(%rbp),%eax
cmp    $0x64,%eax
jne    11bc <main+0x8c>
lea    0xe71(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
jmp    121c <main+0xec>
lea    -0x17(%rbp),%rsi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    -0x17(%rbp),%rdi
call   1030 <HEXTODEC@plt>
movsbl -0x17(%rbp),%eax
shl    $0x4,%eax
movsbl -0x16(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
movsbl -0x15(%rbp),%eax
shl    $0x4,%eax
movsbl -0x14(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
movsbl -0x13(%rbp),%eax
shl    $0x4,%eax
movsbl -0x12(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe03(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xed9(%rip),%r14
lea    0x7(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movzbl 0x7(%rsp),%eax
cmp    $0x68,%al
je     119c <main+0x6c>
cmp    $0x64,%al
jne    1150 <main+0x20>
lea    0xe8f(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x8(%rsp),%esi
mov    0x14(%rsp),%edx
mov    0x10(%rsp),%ecx
lea    0xe71(%rip),%rdi
jmp    11ee <main+0xbe>
lea    0xe70(%rip),%rdi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %rbx,%rdi
call   1030 <HEXTODEC@plt>
movsbl 0x8(%rsp),%eax
shl    $0x4,%eax
movsbl 0x9(%rsp),%esi
add    %eax,%esi
movsbl 0xa(%rsp),%eax
shl    $0x4,%eax
movsbl 0xb(%rsp),%edx
add    %eax,%edx
movsbl 0xc(%rsp),%eax
shl    $0x4,%eax
movsbl 0xd(%rsp),%ecx
add    %eax,%ecx
lea    0xe2c(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [11 x i8] c"%d, %d, %d\00"
@.str.2 = [8 x i8] c"#%x%x%x\00"
@.str.3 = [7 x i8] c"%*c#%s\00"
@.str.4 = [16 x i8] c"rgb(%d, %d, %d)\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca [6 x i8]
store i32 0, i32* %1
br label %7
7: ; preds = %17, %0
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %9
9: ; preds = %7
%10 = load i8, i8* %5
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 104
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i8, i8* %5
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 100
br label %17
17: ; preds = %13, %9
%18 = phi i1 [ false, %9 ], [ %16, %13 ]
br i1 %18, label %7, label %19
19: ; preds = %17
%20 = load i8, i8* %5
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 100
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = 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)
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = load i32, i32* %4
%28 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %25, i32 %26, i32 %27)
br label %62
29: ; preds = %19
%30 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%31 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%33 = call i32 @HEXTODEC(i8* %32)
%34 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = mul nsw i32 %36, 16
%38 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 1
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = add nsw i32 %37, %40
store i32 %41, i32* %2
%42 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 2
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = mul nsw i32 %44, 16
%46 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 3
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = add nsw i32 %45, %48
store i32 %49, i32* %3
%50 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 4
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = mul nsw i32 %52, 16
%54 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 5
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = add nsw i32 %53, %56
store i32 %57, i32* %4
%58 = load i32, i32* %2
%59 = load i32, i32* %3
%60 = load i32, i32* %4
%61 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %58, i32 %59, i32 %60)
br label %62
62: ; preds = %29, %23
ret i32 0
}

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