#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*/ exit(int);
int /*<<< orphan*/ getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int);
int /*<<< orphan*/ stdin;
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
int main() {
  char mode;
  scanf("%c ", &mode);
  switch (mode) {
  case 'd': {
    int red, green, blue;
    scanf("%d, %d, %d", &red, &green, &blue);
    if (red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 ||
        blue > 255) {
      exit(1);
    }
    char hex_number[7];
    sprintf(hex_number, "%x%.2x%.2x", red, green, blue);
    printf("#%s\n", hex_number);
  } break;
  case 'h': {
    char *line;
    size_t n;
    getline(&line, &n, stdin);
    if (line[0] != '#') {
      exit(1);
    }
    char hex_number[3];
    hex_number[2] = '\0';
    int red, green, blue;
    hex_number[0] = line[1];
    hex_number[1] = line[2];
    red = (int)strtol(hex_number, NULL, 16);
    hex_number[0] = line[3];
    hex_number[1] = line[4];
    green = (int)strtol(hex_number, NULL, 16);
    hex_number[0] = line[5];
    hex_number[1] = line[6];
    blue = (int)strtol(hex_number, NULL, 16);
    printf("rgb(%d, %d, %d)\n", red, green, blue);
  } break;
  default:
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
xor    %eax,%eax
lea    -0x5(%rbp),%rsi
call   1050 <scanf@plt>
movsbl -0x5(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x64,%eax
je     11a7 <main+0x47>
jmp    1196 <main+0x36>
mov    -0x44(%rbp),%eax
sub    $0x68,%eax
je     1241 <main+0xe1>
jmp    130c <main+0x1ac>
lea    0xe56(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1050 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
jl     1206 <main+0xa6>
cmpl   $0xff,-0xc(%rbp)
jg     1206 <main+0xa6>
cmpl   $0x0,-0x10(%rbp)
jl     1206 <main+0xa6>
cmpl   $0xff,-0x10(%rbp)
jg     1206 <main+0xa6>
cmpl   $0x0,-0x14(%rbp)
jl     1206 <main+0xa6>
cmpl   $0xff,-0x14(%rbp)
jle    1210 <main+0xb0>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x1b(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xdea(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x1b(%rbp),%rsi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1316 <main+0x1b6>
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <getline@plt>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     1271 <main+0x111>
mov    $0x1,%edi
call   1080 <exit@plt>
movb   $0x0,-0x31(%rbp)
mov    -0x28(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x33(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0x32(%rbp)
lea    -0x33(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    0x3(%rax),%al
mov    %al,-0x33(%rbp)
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%al
mov    %al,-0x32(%rbp)
lea    -0x33(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    0x5(%rax),%al
mov    %al,-0x33(%rbp)
mov    -0x28(%rbp),%rax
mov    0x6(%rax),%al
mov    %al,-0x32(%rbp)
lea    -0x33(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%esi
mov    -0x3c(%rbp),%edx
mov    -0x40(%rbp),%ecx
lea    0xd1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1316 <main+0x1b6>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xe90(%rip),%rdi
lea    0x7(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movsbl 0x7(%rsp),%eax
cmp    $0x68,%eax
je     121a <main+0xba>
cmp    $0x64,%eax
jne    12cd <main+0x16d>
lea    0xe6a(%rip),%rdi
lea    0x18(%rsp),%rsi
mov    %rsp,%rdx
lea    0x14(%rsp),%rcx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x18(%rsp),%edx
cmp    $0xff,%edx
ja     12cd <main+0x16d>
mov    (%rsp),%ecx
test   %ecx,%ecx
js     12cd <main+0x16d>
cmp    $0xff,%ecx
jg     12cd <main+0x16d>
mov    0x14(%rsp),%r8d
test   %r8d,%r8d
js     12cd <main+0x16d>
cmp    $0x100,%r8d
jge    12cd <main+0x16d>
lea    0xe18(%rip),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
lea    0xe0f(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    12c1 <main+0x161>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x18(%rsp),%rsi
call   1060 <getline@plt>
mov    0x8(%rsp),%rax
cmpb   $0x23,(%rax)
jne    12cd <main+0x16d>
movb   $0x0,0x2(%rsp)
mov    0x1(%rax),%cl
mov    %cl,(%rsp)
mov    0x2(%rax),%al
mov    %al,0x1(%rsp)
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %rax,%r14
mov    0x8(%rsp),%rax
mov    0x3(%rax),%cl
mov    %cl,(%rsp)
mov    0x4(%rax),%al
mov    %al,0x1(%rsp)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rax
mov    0x5(%rax),%cl
mov    %cl,(%rsp)
mov    0x6(%rax),%al
mov    %al,0x1(%rsp)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
lea    0xd6c(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%c \00"
@.str.1 = [11 x i8] c"%d, %d, %d\00"
@.str.2 = [11 x i8] c"%x%.2x%.2x\00"
@.str.3 = [5 x i8] c"#%s\0A\00"
@stdin = global i32 0
@.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 [7 x i8]
%7 = alloca i8*
%8 = alloca i64
%9 = alloca [3 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %1
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
%14 = load i8, i8* %2
%15 = sext i8 %14 to i32
switch i32 %15, label %94 [
i32 100, label %16
i32 104, label %45
]
16: ; preds = %0
%17 = 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)
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 0
br i1 %19, label %35, label %20
20: ; preds = %16
%21 = load i32, i32* %3
%22 = icmp sgt i32 %21, 255
br i1 %22, label %35, label %23
23: ; preds = %20
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 0
br i1 %25, label %35, label %26
26: ; preds = %23
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, 255
br i1 %28, label %35, label %29
29: ; preds = %26
%30 = load i32, i32* %5
%31 = icmp slt i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = load i32, i32* %5
%34 = icmp sgt i32 %33, 255
br i1 %34, label %35, label %37
35: ; preds = %32, %29, %26, %23, %20, %16
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %32
%38 = getelementptr inbounds [7 x i8], [7 x i8]* %6, i64 0, i64 0
%39 = load i32, i32* %3
%40 = load i32, i32* %4
%41 = load i32, i32* %5
%42 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %39, i32 %40, i32 %41)
%43 = getelementptr inbounds [7 x i8], [7 x i8]* %6, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %43)
br label %96
45: ; preds = %0
%46 = load i32, i32* @stdin
%47 = call i32 @getline(i8** %7, i64* %8, i32 %46)
%48 = load i8*, i8** %7
%49 = getelementptr inbounds i8, i8* %48, i64 0
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %51, 35
br i1 %52, label %53, label %55
53: ; preds = %45
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %45
%56 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 2
store i8 0, i8* %56
%57 = load i8*, i8** %7
%58 = getelementptr inbounds i8, i8* %57, i64 1
%59 = load i8, i8* %58
%60 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
store i8 %59, i8* %60
%61 = load i8*, i8** %7
%62 = getelementptr inbounds i8, i8* %61, i64 2
%63 = load i8, i8* %62
%64 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 1
store i8 %63, i8* %64
%65 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%66 = call i64 @strtol(i8* %65, i32* null, i32 16)
%67 = trunc i64 %66 to i32
store i32 %67, i32* %10
%68 = load i8*, i8** %7
%69 = getelementptr inbounds i8, i8* %68, i64 3
%70 = load i8, i8* %69
%71 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
store i8 %70, i8* %71
%72 = load i8*, i8** %7
%73 = getelementptr inbounds i8, i8* %72, i64 4
%74 = load i8, i8* %73
%75 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 1
store i8 %74, i8* %75
%76 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%77 = call i64 @strtol(i8* %76, i32* null, i32 16)
%78 = trunc i64 %77 to i32
store i32 %78, i32* %11
%79 = load i8*, i8** %7
%80 = getelementptr inbounds i8, i8* %79, i64 5
%81 = load i8, i8* %80
%82 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
store i8 %81, i8* %82
%83 = load i8*, i8** %7
%84 = getelementptr inbounds i8, i8* %83, i64 6
%85 = load i8, i8* %84
%86 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 1
store i8 %85, i8* %86
%87 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%88 = call i64 @strtol(i8* %87, i32* null, i32 16)
%89 = trunc i64 %88 to i32
store i32 %89, i32* %12
%90 = load i32, i32* %10
%91 = load i32, i32* %11
%92 = load i32, i32* %12
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %90, i32 %91, i32 %92)
br label %96
94: ; preds = %0
%95 = call i32 @exit(i32 1)
unreachable
96: ; preds = %55, %37
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%c \00"
@.str.1 = [11 x i8] c"%d, %d, %d\00"
@.str.2 = [11 x i8] c"%x%.2x%.2x\00"
@.str.3 = [5 x i8] c"#%s\0A\00"
@stdin = global i32 0
@.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 [7 x i8]
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [3 x i8]
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
%10 = load i8, i8* %1
%11 = sext i8 %10 to i32
switch i32 %11, label %70 [
i32 100, label %12
i32 104, label %35
]
12: ; preds = %0
%13 = bitcast i32* %2 to i8*
%14 = bitcast i32* %3 to i8*
%15 = bitcast i32* %4 to i8*
%16 = 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)
%17 = load i32, i32* %2
%18 = icmp ugt i32 %17, 255
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 0
%21 = select i1 %18, i1 true, i1 %20
%22 = icmp sgt i32 %19, 255
%23 = select i1 %21, i1 true, i1 %22
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 0
%26 = select i1 %23, i1 true, i1 %25
%27 = icmp sgt i32 %24, 255
%28 = select i1 %26, i1 true, i1 %27
br i1 %28, label %29, label %31
29: ; preds = %12
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %12
%32 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%33 = call i32 @sprintf(i8* %32, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %19, i32 %24)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %32)
br label %72
35: ; preds = %0
%36 = bitcast i8** %6 to i8*
%37 = bitcast i64* %7 to i8*
%38 = load i32, i32* @stdin
%39 = call i32 @getline(i8** %6, i64* %7, i32 %38)
%40 = load i8*, i8** %6
%41 = load i8, i8* %40
%42 = icmp eq i8 %41, 35
br i1 %42, label %45, label %43
43: ; preds = %35
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %35
%46 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%47 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 2
store i8 0, i8* %47
%48 = getelementptr inbounds i8, i8* %40, i64 1
%49 = load i8, i8* %48
store i8 %49, i8* %46
%50 = getelementptr inbounds i8, i8* %40, i64 2
%51 = load i8, i8* %50
%52 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 1
store i8 %51, i8* %52
%53 = call i64 @strtol(i8* nocapture %46, i32* null, i32 16)
%54 = trunc i64 %53 to i32
%55 = load i8*, i8** %6
%56 = getelementptr inbounds i8, i8* %55, i64 3
%57 = load i8, i8* %56
store i8 %57, i8* %46
%58 = getelementptr inbounds i8, i8* %55, i64 4
%59 = load i8, i8* %58
store i8 %59, i8* %52
%60 = call i64 @strtol(i8* nocapture %46, i32* null, i32 16)
%61 = trunc i64 %60 to i32
%62 = load i8*, i8** %6
%63 = getelementptr inbounds i8, i8* %62, i64 5
%64 = load i8, i8* %63
store i8 %64, i8* %46
%65 = getelementptr inbounds i8, i8* %62, i64 6
%66 = load i8, i8* %65
store i8 %66, i8* %52
%67 = call i64 @strtol(i8* nocapture %46, i32* null, i32 16)
%68 = trunc i64 %67 to i32
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %54, i32 %61, i32 %68)
br label %72
70: ; preds = %0
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %45, %31
ret i32 0
}