#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*/ DecToHex(int);
int HexToDec(char *, char);
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int red, green, blue;
  char type, hex[10], i = 1;
  type = getchar();
  if (type == 'd') {
    scanf("%d,%d,%d", &red, &green, &blue);
    printf("#");
    DecToHex(red);
    DecToHex(green);
    DecToHex(blue);
  }
  if (type == 'h') {
    scanf("%s", hex);
    if (hex[0] != '#')
      return 0;
    red = HexToDec(hex, i);
    i += 2;
    green = HexToDec(hex, i);
    i += 2;
    blue = HexToDec(hex, i);
    printf("rgb(%d, %d, %d)", red, green, blue);
  } else
    return 0;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x1,-0x1c(%rbp)
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x64,%eax
jne    11ba <main+0x6a>
lea    0xe7f(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
mov    $0x0,%al
call   1070 <scanf@plt>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
call   1030 <DecToHex@plt>
mov    -0xc(%rbp),%edi
call   1030 <DecToHex@plt>
mov    -0x10(%rbp),%edi
call   1030 <DecToHex@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x68,%eax
jne    1252 <main+0x102>
lea    -0x1b(%rbp),%rsi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
movsbl -0x1b(%rbp),%eax
cmp    $0x23,%eax
je     11f2 <main+0xa2>
movl   $0x0,-0x4(%rbp)
jmp    1265 <main+0x115>
lea    -0x1b(%rbp),%rdi
movsbl -0x1c(%rbp),%esi
call   1040 <HexToDec@plt>
mov    %eax,-0x8(%rbp)
movsbl -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %al,-0x1c(%rbp)
lea    -0x1b(%rbp),%rdi
movsbl -0x1c(%rbp),%esi
call   1040 <HexToDec@plt>
mov    %eax,-0xc(%rbp)
movsbl -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %al,-0x1c(%rbp)
lea    -0x1b(%rbp),%rdi
movsbl -0x1c(%rbp),%esi
call   1040 <HexToDec@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    125e <main+0x10e>
movl   $0x0,-0x4(%rbp)
jmp    1265 <main+0x115>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0x68,%al
je     11bf <main+0x5f>
cmp    $0x64,%al
jne    121f <main+0xbf>
lea    0xe7e(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
xor    %eax,%eax
call   1080 <scanf@plt>
mov    $0x23,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%edi
call   1040 <DecToHex@plt>
mov    0x1c(%rsp),%edi
call   1040 <DecToHex@plt>
mov    0x18(%rsp),%edi
call   1040 <DecToHex@plt>
jmp    121f <main+0xbf>
lea    0xe43(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
cmpb   $0x23,0xc(%rsp)
jne    121f <main+0xbf>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1050 <HexToDec@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    $0x3,%esi
call   1050 <HexToDec@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x5,%esi
call   1050 <HexToDec@plt>
lea    0xdfb(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c"%d,%d,%d\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [16 x i8] c"rgb(%d, %d, %d)\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i8]
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%9 = tail call signext i8 (...) @getchar()
switch i8 %9, label %28 [
i8 100, label %10
i8 104, label %19
]
10: ; preds = %0
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%12 = call i32 @putchar(i32 35)
%13 = load i32, i32* %1
%14 = call i32 @DecToHex(i32 %13)
%15 = load i32, i32* %2
%16 = call i32 @DecToHex(i32 %15)
%17 = load i32, i32* %3
%18 = call i32 @DecToHex(i32 %17)
br label %28
19: ; preds = %0
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%21 = load i8, i8* %8
%22 = icmp eq i8 %21, 35
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = call i32 @HexToDec(i8* %8, i8 signext 1)
%25 = call i32 @HexToDec(i8* %8, i8 signext 3)
%26 = call i32 @HexToDec(i8* %8, i8 signext 5)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %24, i32 %25, i32 %26)
br label %28
28: ; preds = %10, %0, %19, %23
ret i32 0
}