#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*/ decHex(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ getchar();
int hexDec(char, char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stdin;
char *strtok(char *, char *);
char tolower(char);
int main() {
  char type, *curtoken, input[14];
  int i;
  do {
    scanf("%c", &type);
  } while (type != 'h' && type != 'd');
  getchar();
  fgets(input, 14, stdin);
  if (type == 'h') {
    for (i = 0; i < 7; i++) {
      input[i] = tolower(input[i]);
    }
    printf("rgb(%d, %d, %d)", hexDec(input[1], input[2]),
           hexDec(input[3], input[4]), hexDec(input[5], input[6]));
  } else {
    curtoken = strtok(input, ", ");
    printf("#");
    while (curtoken != NULL) {
      decHex(curtoken);
      curtoken = strtok(NULL, ", \n");
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
lea    -0x5(%rbp),%rsi
call   1090 <scanf@plt>
movsbl -0x5(%rbp),%ecx
xor    %eax,%eax
cmp    $0x68,%ecx
mov    %al,-0x25(%rbp)
je     11be <main+0x3e>
movsbl -0x5(%rbp),%eax
cmp    $0x64,%eax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    118f <main+0xf>
mov    $0x0,%al
call   1070 <getchar@plt>
lea    -0x1e(%rbp),%rdi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
mov    $0xe,%esi
call   1060 <fgets@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x68,%eax
jne    1279 <main+0xf9>
movl   $0x0,-0x24(%rbp)
cmpl   $0x7,-0x24(%rbp)
jge    122b <main+0xab>
movslq -0x24(%rbp),%rax
movsbl -0x1e(%rbp,%rax,1),%edi
call   1080 <tolower@plt>
mov    %al,%cl
movslq -0x24(%rbp),%rax
mov    %cl,-0x1e(%rbp,%rax,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11fb <main+0x7b>
mov    -0x1d(%rbp),%al
movsbl %al,%edi
movsbl -0x1c(%rbp),%esi
call   1040 <hexDec@plt>
mov    %eax,-0x30(%rbp)
mov    -0x1b(%rbp),%al
movsbl %al,%edi
movsbl -0x1a(%rbp),%esi
call   1040 <hexDec@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x19(%rbp),%al
movsbl %al,%edi
movsbl -0x18(%rbp),%esi
call   1040 <hexDec@plt>
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    %eax,%ecx
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12cd <main+0x14d>
lea    -0x1e(%rbp),%rdi
lea    0xd8f(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x10(%rbp)
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     12c8 <main+0x148>
mov    -0x10(%rbp),%rdi
call   1030 <decHex@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd5e(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x10(%rbp)
jmp    129b <main+0x11b>
jmp    12cd <main+0x14d>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe61(%rip),%r14
lea    0x1(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
call   10a0 <scanf@plt>
movzbl 0x1(%rsp),%eax
cmp    $0x68,%al
je     11c8 <main+0x38>
cmp    $0x64,%al
jne    11b0 <main+0x20>
xor    %eax,%eax
call   1080 <getchar@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
lea    0x2(%rsp),%rdi
mov    $0xe,%esi
call   1070 <fgets@plt>
cmpb   $0x68,0x1(%rsp)
jne    129b <main+0x10b>
movsbl 0x2(%rsp),%edi
call   1090 <tolower@plt>
mov    %al,0x2(%rsp)
movsbl 0x3(%rsp),%edi
call   1090 <tolower@plt>
mov    %al,0x3(%rsp)
movsbl 0x4(%rsp),%edi
call   1090 <tolower@plt>
mov    %al,0x4(%rsp)
movsbl 0x5(%rsp),%edi
call   1090 <tolower@plt>
mov    %al,0x5(%rsp)
movsbl 0x6(%rsp),%edi
call   1090 <tolower@plt>
mov    %al,0x6(%rsp)
movsbl 0x7(%rsp),%edi
call   1090 <tolower@plt>
mov    %al,0x7(%rsp)
movsbl 0x8(%rsp),%edi
call   1090 <tolower@plt>
mov    %al,0x8(%rsp)
movsbl 0x3(%rsp),%edi
movsbl 0x4(%rsp),%esi
call   1050 <hexDec@plt>
mov    %eax,%ebx
movsbl 0x5(%rsp),%edi
movsbl 0x6(%rsp),%esi
call   1050 <hexDec@plt>
mov    %eax,%ebp
movsbl 0x7(%rsp),%edi
movsbl 0x8(%rsp),%esi
call   1050 <hexDec@plt>
lea    0xd77(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12ea <main+0x15a>
lea    0xd71(%rip),%rsi
lea    0x2(%rsp),%rdi
call   10b0 <strtok@plt>
mov    %rax,%rbx
mov    $0x23,%edi
call   1030 <putchar@plt>
test   %rbx,%rbx
je     12ea <main+0x15a>
lea    0xd51(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1040 <decHex@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   10b0 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    12d0 <main+0x140>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@stdin = global i32 0
@.str.1 = [16 x i8] c"rgb(%d, %d, %d)\00"
@.str.2 = [3 x i8] c", \00"
@.str.3 = [2 x i8] c"#\00"
@.str.4 = [4 x i8] c", \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8*
%4 = alloca [14 x i8]
%5 = alloca i32
store i32 0, i32* %1
br label %6
6: ; preds = %16, %0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %8
8: ; preds = %6
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 104
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i8, i8* %2
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 100
br label %16
16: ; preds = %12, %8
%17 = phi i1 [ false, %8 ], [ %15, %12 ]
br i1 %17, label %6, label %18
18: ; preds = %16
%19 = call i32 (...) @getchar()
%20 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 0
%21 = load i32, i32* @stdin
%22 = call i32 @fgets(i8* %20, i32 14, i32 %21)
%23 = load i8, i8* %2
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 104
br i1 %25, label %26, label %59
26: ; preds = %18
store i32 0, i32* %5
br label %27
27: ; preds = %39, %26
%28 = load i32, i32* %5
%29 = icmp slt i32 %28, 7
br i1 %29, label %30, label %42
30: ; preds = %27
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = call signext i8 @tolower(i8 signext %34)
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 %37
store i8 %35, i8* %38
br label %39
39: ; preds = %30
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %27
42: ; preds = %27
%43 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 1
%44 = load i8, i8* %43
%45 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 2
%46 = load i8, i8* %45
%47 = call i32 @hexDec(i8 signext %44, i8 signext %46)
%48 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 3
%49 = load i8, i8* %48
%50 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 4
%51 = load i8, i8* %50
%52 = call i32 @hexDec(i8 signext %49, i8 signext %51)
%53 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 5
%54 = load i8, i8* %53
%55 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 6
%56 = load i8, i8* %55
%57 = call i32 @hexDec(i8 signext %54, i8 signext %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %47, i32 %52, i32 %57)
br label %71
59: ; preds = %18
%60 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 0
%61 = call i8* @strtok(i8* %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i8* %61, i8** %3
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %63
63: ; preds = %66, %59
%64 = load i8*, i8** %3
%65 = icmp ne i8* %64, null
br i1 %65, label %66, label %70
66: ; preds = %63
%67 = load i8*, i8** %3
%68 = call i32 @decHex(i8* %67)
%69 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
store i8* %69, i8** %3
br label %63
70: ; preds = %63
br label %71
71: ; preds = %70, %42
%72 = load i32, i32* %1
ret i32 %72
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@stdin = global i32 0
@.str.1 = [16 x i8] c"rgb(%d, %d, %d)\00"
@.str.2 = [3 x i8] c", \00"
@.str.4 = [4 x i8] c", \0A\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca [14 x i8]
%3 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %4, %0
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%6 = load i8, i8* %1
switch i8 %6, label %4 [
i8 104, label %7
i8 100, label %7
]
7: ; preds = %4, %4
%8 = call i32 (...) @getchar()
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %3, i32 14, i32 %9)
%11 = load i8, i8* %1
%12 = icmp eq i8 %11, 104
br i1 %12, label %13, label %44
13: ; preds = %7
%14 = load i8, i8* %3
%15 = call signext i8 @tolower(i8 signext %14)
store i8 %15, i8* %3
%16 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 1
%17 = load i8, i8* %16
%18 = call signext i8 @tolower(i8 signext %17)
store i8 %18, i8* %16
%19 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 2
%20 = load i8, i8* %19
%21 = call signext i8 @tolower(i8 signext %20)
store i8 %21, i8* %19
%22 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 3
%23 = load i8, i8* %22
%24 = call signext i8 @tolower(i8 signext %23)
store i8 %24, i8* %22
%25 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 4
%26 = load i8, i8* %25
%27 = call signext i8 @tolower(i8 signext %26)
store i8 %27, i8* %25
%28 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 5
%29 = load i8, i8* %28
%30 = call signext i8 @tolower(i8 signext %29)
store i8 %30, i8* %28
%31 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 6
%32 = load i8, i8* %31
%33 = call signext i8 @tolower(i8 signext %32)
store i8 %33, i8* %31
%34 = load i8, i8* %16
%35 = load i8, i8* %19
%36 = call i32 @hexDec(i8 signext %34, i8 signext %35)
%37 = load i8, i8* %22
%38 = load i8, i8* %25
%39 = call i32 @hexDec(i8 signext %37, i8 signext %38)
%40 = load i8, i8* %28
%41 = load i8, i8* %31
%42 = call i32 @hexDec(i8 signext %40, i8 signext %41)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %36, i32 %39, i32 %42)
br label %53
44: ; preds = %7
%45 = call i8* @strtok(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @putchar(i32 35)
%47 = icmp eq i8* %45, null
br i1 %47, label %53, label %48
48: ; preds = %44, %48
%49 = phi i8* [ %51, %48 ], [ %45, %44 ]
%50 = call i32 @decHex(i8* %49)
%51 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%52 = icmp eq i8* %51, null
br i1 %52, label %53, label %48
53: ; preds = %48, %44, %13
ret i32 0
}