#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ print_hex(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stdin;
int strlen(char *);
char *strtok(char *, char *);
int to_decimal(char, char);
int /*<<< orphan*/ to_lower(char *, int);
int main() {
  int i, length;
  char option, color[13], *temp;
  scanf("%c", &option);
  getchar();
  if (option == 'h') {
    fgets(color, 14, stdin);
    length = strlen(color);
    length = color[length - 1] == '\n' ? length - 1 : length;
    to_lower(color, length);
    printf("rgb(%d, %d, %d)", to_decimal(color[1], color[2]),
           to_decimal(color[3], color[4]), to_decimal(color[5], color[6]));
  } else if (option == 'd') {
    fgets(color, 14, stdin);
    temp = strtok(color, ", ");
    getchar();
    printf("#");
    while (temp != NULL) {
      sscanf(temp, "%d", &i);
      print_hex(i);
      temp = strtok(NULL, ", ");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe4a(%rip),%rdi
lea    -0xd(%rbp),%rsi
call   10b0 <scanf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
movsbl -0xd(%rbp),%eax
cmp    $0x68,%eax
jne    1280 <main+0xe0>
lea    -0x1a(%rbp),%rdi
mov    0x2e0a(%rip),%rax
mov    (%rax),%edx
mov    $0xe,%esi
call   1060 <fgets@plt>
lea    -0x1a(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x1a(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    121a <main+0x7a>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1220 <main+0x80>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    -0x1a(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <to_lower@plt>
mov    -0x19(%rbp),%al
movsbl %al,%edi
movsbl -0x18(%rbp),%esi
call   1090 <to_decimal@plt>
mov    %eax,-0x34(%rbp)
mov    -0x17(%rbp),%al
movsbl %al,%edi
movsbl -0x16(%rbp),%esi
call   1090 <to_decimal@plt>
mov    %eax,-0x30(%rbp)
mov    -0x15(%rbp),%al
movsbl %al,%edi
movsbl -0x14(%rbp),%esi
call   1090 <to_decimal@plt>
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    %eax,%ecx
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1317 <main+0x177>
movsbl -0xd(%rbp),%eax
cmp    $0x64,%eax
jne    1312 <main+0x172>
lea    -0x1a(%rbp),%rdi
mov    0x2d50(%rip),%rax
mov    (%rax),%edx
mov    $0xe,%esi
call   1060 <fgets@plt>
lea    -0x1a(%rbp),%rdi
lea    0xd64(%rip),%rsi
call   10c0 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1070 <getchar@plt>
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
je     130d <main+0x16d>
mov    -0x28(%rbp),%rdi
lea    0xd35(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   10a0 <sscanf@plt>
mov    -0x8(%rbp),%edi
call   1080 <print_hex@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd14(%rip),%rsi
call   10c0 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    12cd <main+0x12d>
jmp    1312 <main+0x172>
jmp    1317 <main+0x177>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xe3d(%rip),%rdi
lea    0xe(%rsp),%rsi
call   10c0 <scanf@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
mov    0xe(%rsp),%al
cmp    $0x64,%al
je     126c <main+0xbc>
cmp    $0x68,%al
jne    12f9 <main+0x149>
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
lea    0xf(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xe,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%rsi
lea    -0x1(%rsi),%rax
cmpb   $0xa,0xe(%rsp,%rsi,1)
cmove  %eax,%esi
mov    %rbx,%rdi
call   1060 <to_lower@plt>
movsbl 0x10(%rsp),%edi
movsbl 0x11(%rsp),%esi
call   10a0 <to_decimal@plt>
mov    %eax,%ebx
movsbl 0x12(%rsp),%edi
movsbl 0x13(%rsp),%esi
call   10a0 <to_decimal@plt>
mov    %eax,%ebp
movsbl 0x14(%rsp),%edi
movsbl 0x15(%rsp),%esi
call   10a0 <to_decimal@plt>
lea    0xda9(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12f9 <main+0x149>
mov    0x2d75(%rip),%rax
mov    (%rax),%edx
lea    0xf(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xe,%esi
call   1070 <fgets@plt>
lea    0xd85(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <strtok@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1080 <getchar@plt>
mov    $0x23,%edi
call   1030 <putchar@plt>
test   %rbx,%rbx
je     12f9 <main+0x149>
lea    0xd60(%rip),%r14
lea    0x1c(%rsp),%r15
lea    0xd51(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   10b0 <sscanf@plt>
mov    0x1c(%rsp),%edi
call   1090 <print_hex@plt>
xor    %edi,%edi
mov    %r12,%rsi
call   10d0 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    12d0 <main+0x120>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca [13 x i8]
%6 = alloca i8*
store i32 0, i32* %1
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%8 = call i32 (...) @getchar()
%9 = load i8, i8* %4
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 104
br i1 %11, label %12, label %51
12: ; preds = %0
%13 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %13, i32 14, i32 %14)
%16 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 10
br i1 %24, label %25, label %28
25: ; preds = %12
%26 = load i32, i32* %3
%27 = sub nsw i32 %26, 1
br label %30
28: ; preds = %12
%29 = load i32, i32* %3
br label %30
30: ; preds = %28, %25
%31 = phi i32 [ %27, %25 ], [ %29, %28 ]
store i32 %31, i32* %3
%32 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%33 = load i32, i32* %3
%34 = call i32 @to_lower(i8* %32, i32 %33)
%35 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 1
%36 = load i8, i8* %35
%37 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 2
%38 = load i8, i8* %37
%39 = call i32 @to_decimal(i8 signext %36, i8 signext %38)
%40 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 3
%41 = load i8, i8* %40
%42 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 4
%43 = load i8, i8* %42
%44 = call i32 @to_decimal(i8 signext %41, i8 signext %43)
%45 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 5
%46 = load i8, i8* %45
%47 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 6
%48 = load i8, i8* %47
%49 = call i32 @to_decimal(i8 signext %46, i8 signext %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %39, i32 %44, i32 %49)
br label %74
51: ; preds = %0
%52 = load i8, i8* %4
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 100
br i1 %54, label %55, label %73
55: ; preds = %51
%56 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%57 = load i32, i32* @stdin
%58 = call i32 @fgets(i8* %56, i32 14, i32 %57)
%59 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%60 = call i8* @strtok(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i8* %60, i8** %6
%61 = call i32 (...) @getchar()
%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, %55
%64 = load i8*, i8** %6
%65 = icmp ne i8* %64, null
br i1 %65, label %66, label %72
66: ; preds = %63
%67 = load i8*, i8** %6
%68 = call i32 @sscanf(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%69 = load i32, i32* %2
%70 = call i32 @print_hex(i32 %69)
%71 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i8* %71, i8** %6
br label %63
72: ; preds = %63
br label %73
73: ; preds = %72, %51
br label %74
74: ; preds = %73, %30
ret i32 0
}

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 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [13 x i8]
%4 = bitcast i32* %1 to i8*
%5 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%7 = call i32 (...) @getchar()
%8 = load i8, i8* %2
switch i8 %8, label %50 [
i8 104, label %9
i8 100, label %36
]
9: ; preds = %0
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %5, i32 14, i32 %10)
%12 = call i32 @strlen(i8* %5)
%13 = add nsw i32 %12, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 10
%18 = select i1 %17, i32 %13, i32 %12
%19 = call i32 @to_lower(i8* %5, i32 %18)
%20 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 1
%21 = load i8, i8* %20
%22 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 2
%23 = load i8, i8* %22
%24 = call i32 @to_decimal(i8 signext %21, i8 signext %23)
%25 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 3
%26 = load i8, i8* %25
%27 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 4
%28 = load i8, i8* %27
%29 = call i32 @to_decimal(i8 signext %26, i8 signext %28)
%30 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 5
%31 = load i8, i8* %30
%32 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 6
%33 = load i8, i8* %32
%34 = call i32 @to_decimal(i8 signext %31, i8 signext %33)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %29, i32 %34)
br label %50
36: ; preds = %0
%37 = load i32, i32* @stdin
%38 = call i32 @fgets(i8* %5, i32 14, i32 %37)
%39 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 (...) @getchar()
%41 = call i32 @putchar(i32 35)
%42 = icmp eq i8* %39, null
br i1 %42, label %50, label %43
43: ; preds = %36, %43
%44 = phi i8* [ %48, %43 ], [ %39, %36 ]
%45 = call i32 @sscanf(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%46 = load i32, i32* %1
%47 = call i32 @print_hex(i32 %46)
%48 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %43
50: ; preds = %43, %36, %0, %9
ret i32 0
}