#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 Hexvalue(int);
int Numbervalue(char);
int /*<<< orphan*/ printf(char *, int, int, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  char mode, HexNumber[7];
  int number1, number2, number3;
  scanf("%c", &mode);
  if (mode == 'h') {
    scanf("%s", HexNumber);
    number1 = Numbervalue(HexNumber[1]) * 16 + Numbervalue(HexNumber[2]);
    number2 = Numbervalue(HexNumber[3]) * 16 + Numbervalue(HexNumber[4]);
    number3 = Numbervalue(HexNumber[5]) * 16 + Numbervalue(HexNumber[6]);
    printf("\nrgb(%d,%d,%d)", number1, number2, number3);
  } else {
    scanf("%d,%d,%d", &number1, &number2, &number3);
    if (number1 < 0) {
      number1 = 0;
    }
    if (number1 > 255) {
      number1 = 255;
    }
    if (number2 < 0) {
      number2 = 0;
    }
    if (number2 > 255) {
      number2 = 255;
    }
    if (number3 < 0) {
      number3 = 0;
    }
    if (number3 > 255) {
      number3 = 255;
    }
    printf("\n#%c%c", Hexvalue(number1 / 16), Hexvalue(number1 % 16));
    printf("%c%c", Hexvalue(number2 / 16), Hexvalue(number2 % 16));
    printf("%c%c\n", Hexvalue(number3 / 16), Hexvalue(number3 % 16));
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec9(%rip),%rdi
lea    -0x5(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x68,%eax
jne    1202 <main+0xc2>
lea    -0xc(%rbp),%rsi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
movsbl -0xb(%rbp),%edi
call   1030 <Numbervalue@plt>
shl    $0x4,%eax
mov    %eax,-0x24(%rbp)
movsbl -0xa(%rbp),%edi
call   1030 <Numbervalue@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
movsbl -0x9(%rbp),%edi
call   1030 <Numbervalue@plt>
shl    $0x4,%eax
mov    %eax,-0x20(%rbp)
movsbl -0x8(%rbp),%edi
call   1030 <Numbervalue@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
movsbl -0x7(%rbp),%edi
call   1030 <Numbervalue@plt>
shl    $0x4,%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x6(%rbp),%edi
call   1030 <Numbervalue@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1339 <main+0x1f9>
lea    0xe09(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
mov    $0x0,%al
call   1060 <scanf@plt>
cmpl   $0x0,-0x10(%rbp)
jge    122d <main+0xed>
movl   $0x0,-0x10(%rbp)
cmpl   $0xff,-0x10(%rbp)
jle    1241 <main+0x101>
movl   $0xff,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1252 <main+0x112>
movl   $0x0,-0x14(%rbp)
cmpl   $0xff,-0x14(%rbp)
jle    1266 <main+0x126>
movl   $0xff,-0x14(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1277 <main+0x137>
movl   $0x0,-0x18(%rbp)
cmpl   $0xff,-0x18(%rbp)
jle    128b <main+0x14b>
movl   $0xff,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1050 <Hexvalue@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1050 <Hexvalue@plt>
mov    -0x30(%rbp),%esi
mov    %eax,%edx
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1050 <Hexvalue@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1050 <Hexvalue@plt>
mov    -0x2c(%rbp),%esi
mov    %eax,%edx
lea    0xd25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1050 <Hexvalue@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1050 <Hexvalue@plt>
mov    -0x28(%rbp),%esi
mov    %eax,%edx
lea    0xcf0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xed0(%rip),%rdi
lea    0xf(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpb   $0x68,0xf(%rsp)
jne    11e7 <main+0xa7>
lea    0xe93(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
movsbl 0x11(%rsp),%edi
call   1030 <Numbervalue@plt>
mov    %eax,%r14d
shl    $0x4,%r14d
movsbl 0x12(%rsp),%edi
call   1030 <Numbervalue@plt>
add    %eax,%r14d
movsbl 0x13(%rsp),%edi
call   1030 <Numbervalue@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x14(%rsp),%edi
call   1030 <Numbervalue@plt>
add    %eax,%ebp
movsbl 0x15(%rsp),%edi
call   1030 <Numbervalue@plt>
mov    %eax,%ebx
shl    $0x4,%ebx
movsbl 0x16(%rsp),%edi
call   1030 <Numbervalue@plt>
add    %eax,%ebx
lea    0xe2f(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1320 <main+0x1e0>
lea    0xe24(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x10(%rsp),%edi
test   %edi,%edi
js     1223 <main+0xe3>
cmp    $0x100,%edi
jb     122d <main+0xed>
movl   $0xff,0x10(%rsp)
mov    $0xff,%edi
jmp    122d <main+0xed>
movl   $0x0,0x10(%rsp)
xor    %edi,%edi
mov    0x1c(%rsp),%eax
test   %eax,%eax
js     1246 <main+0x106>
cmp    $0x100,%eax
jb     124e <main+0x10e>
movl   $0xff,0x1c(%rsp)
jmp    124e <main+0x10e>
movl   $0x0,0x1c(%rsp)
mov    0x18(%rsp),%eax
test   %eax,%eax
js     1267 <main+0x127>
cmp    $0x100,%eax
jb     126f <main+0x12f>
movl   $0xff,0x18(%rsp)
jmp    126f <main+0x12f>
movl   $0x0,0x18(%rsp)
shr    $0x4,%edi
and    $0xf,%edi
call   1050 <Hexvalue@plt>
mov    %eax,%ebx
mov    0x10(%rsp),%edi
lea    0xf(%rdi),%eax
test   %edi,%edi
cmovns %edi,%eax
and    $0xfffffff0,%eax
sub    %eax,%edi
call   1050 <Hexvalue@plt>
lea    0xd82(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1c(%rsp),%eax
lea    0xf(%rax),%edi
test   %eax,%eax
cmovns %eax,%edi
sar    $0x4,%edi
call   1050 <Hexvalue@plt>
mov    %eax,%ebx
mov    0x1c(%rsp),%edi
lea    0xf(%rdi),%eax
test   %edi,%edi
cmovns %edi,%eax
and    $0xfffffff0,%eax
sub    %eax,%edi
call   1050 <Hexvalue@plt>
lea    0xd46(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rsp),%eax
lea    0xf(%rax),%edi
test   %eax,%eax
cmovns %eax,%edi
sar    $0x4,%edi
call   1050 <Hexvalue@plt>
mov    %eax,%ebx
mov    0x18(%rsp),%edi
lea    0xf(%rdi),%eax
test   %edi,%edi
cmovns %edi,%eax
and    $0xfffffff0,%eax
sub    %eax,%edi
call   1050 <Hexvalue@plt>
lea    0xd0d(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [15 x i8] c"\0Argb(%d,%d,%d)\00"
@.str.3 = [9 x i8] c"%d,%d,%d\00"
@.str.4 = [7 x i8] c"\0A#%c%c\00"
@.str.5 = [5 x i8] c"%c%c\00"
@.str.6 = [6 x i8] c"%c%c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [7 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%8 = load i8, i8* %2
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 104
br i1 %10, label %11, label %42
11: ; preds = %0
%12 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 1
%15 = load i8, i8* %14
%16 = call i32 @Numbervalue(i8 signext %15)
%17 = mul nsw i32 %16, 16
%18 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 2
%19 = load i8, i8* %18
%20 = call i32 @Numbervalue(i8 signext %19)
%21 = add nsw i32 %17, %20
store i32 %21, i32* %4
%22 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 3
%23 = load i8, i8* %22
%24 = call i32 @Numbervalue(i8 signext %23)
%25 = mul nsw i32 %24, 16
%26 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 4
%27 = load i8, i8* %26
%28 = call i32 @Numbervalue(i8 signext %27)
%29 = add nsw i32 %25, %28
store i32 %29, i32* %5
%30 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 5
%31 = load i8, i8* %30
%32 = call i32 @Numbervalue(i8 signext %31)
%33 = mul nsw i32 %32, 16
%34 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 6
%35 = load i8, i8* %34
%36 = call i32 @Numbervalue(i8 signext %35)
%37 = add nsw i32 %33, %36
store i32 %37, i32* %6
%38 = load i32, i32* %4
%39 = load i32, i32* %5
%40 = load i32, i32* %6
%41 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %38, i32 %39, i32 %40)
br label %89
42: ; preds = %0
%43 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* %4, i32* %5, i32* %6)
%44 = load i32, i32* %4
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42
store i32 0, i32* %4
br label %47
47: ; preds = %46, %42
%48 = load i32, i32* %4
%49 = icmp sgt i32 %48, 255
br i1 %49, label %50, label %51
50: ; preds = %47
store i32 255, i32* %4
br label %51
51: ; preds = %50, %47
%52 = load i32, i32* %5
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %51
store i32 0, i32* %5
br label %55
55: ; preds = %54, %51
%56 = load i32, i32* %5
%57 = icmp sgt i32 %56, 255
br i1 %57, label %58, label %59
58: ; preds = %55
store i32 255, i32* %5
br label %59
59: ; preds = %58, %55
%60 = load i32, i32* %6
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %59
store i32 0, i32* %6
br label %63
63: ; preds = %62, %59
%64 = load i32, i32* %6
%65 = icmp sgt i32 %64, 255
br i1 %65, label %66, label %67
66: ; preds = %63
store i32 255, i32* %6
br label %67
67: ; preds = %66, %63
%68 = load i32, i32* %4
%69 = sdiv i32 %68, 16
%70 = call i32 @Hexvalue(i32 %69)
%71 = load i32, i32* %4
%72 = srem i32 %71, 16
%73 = call i32 @Hexvalue(i32 %72)
%74 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %70, i32 %73)
%75 = load i32, i32* %5
%76 = sdiv i32 %75, 16
%77 = call i32 @Hexvalue(i32 %76)
%78 = load i32, i32* %5
%79 = srem i32 %78, 16
%80 = call i32 @Hexvalue(i32 %79)
%81 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %77, i32 %80)
%82 = load i32, i32* %6
%83 = sdiv i32 %82, 16
%84 = call i32 @Hexvalue(i32 %83)
%85 = load i32, i32* %6
%86 = srem i32 %85, 16
%87 = call i32 @Hexvalue(i32 %86)
%88 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %84, i32 %87)
br label %89
89: ; preds = %67, %11
%90 = load i32, i32* %1
ret i32 %90
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [15 x i8] c"\0Argb(%d,%d,%d)\00"
@.str.3 = [9 x i8] c"%d,%d,%d\00"
@.str.4 = [7 x i8] c"\0A#%c%c\00"
@.str.5 = [5 x i8] c"%c%c\00"
@.str.6 = [6 x i8] c"%c%c\0A\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca [7 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%11 = load i8, i8* %1
%12 = icmp eq i8 %11, 104
br i1 %12, label %13, label %40
13: ; preds = %0
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%15 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 1
%16 = load i8, i8* %15
%17 = call i32 @Numbervalue(i8 signext %16)
%18 = shl nsw i32 %17, 4
%19 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 2
%20 = load i8, i8* %19
%21 = call i32 @Numbervalue(i8 signext %20)
%22 = add nsw i32 %21, %18
%23 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 3
%24 = load i8, i8* %23
%25 = call i32 @Numbervalue(i8 signext %24)
%26 = shl nsw i32 %25, 4
%27 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 4
%28 = load i8, i8* %27
%29 = call i32 @Numbervalue(i8 signext %28)
%30 = add nsw i32 %29, %26
%31 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 5
%32 = load i8, i8* %31
%33 = call i32 @Numbervalue(i8 signext %32)
%34 = shl nsw i32 %33, 4
%35 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 6
%36 = load i8, i8* %35
%37 = call i32 @Numbervalue(i8 signext %36)
%38 = add nsw i32 %37, %34
%39 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %22, i32 %30, i32 %38)
br label %85
40: ; preds = %0
%41 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%42 = load i32, i32* %3
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %40
store i32 0, i32* %3
br label %48
45: ; preds = %40
%46 = icmp ugt i32 %42, 255
br i1 %46, label %47, label %48
47: ; preds = %45
store i32 255, i32* %3
br label %48
48: ; preds = %44, %47, %45
%49 = phi i32 [ 0, %44 ], [ 255, %47 ], [ %42, %45 ]
%50 = load i32, i32* %4
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %48
store i32 0, i32* %4
br label %56
53: ; preds = %48
%54 = icmp ugt i32 %50, 255
br i1 %54, label %55, label %56
55: ; preds = %53
store i32 255, i32* %4
br label %56
56: ; preds = %52, %55, %53
%57 = load i32, i32* %5
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %56
store i32 0, i32* %5
br label %63
60: ; preds = %56
%61 = icmp ugt i32 %57, 255
br i1 %61, label %62, label %63
62: ; preds = %60
store i32 255, i32* %5
br label %63
63: ; preds = %59, %62, %60
%64 = lshr i32 %49, 4
%65 = and i32 %64, 15
%66 = call i32 @Hexvalue(i32 %65)
%67 = load i32, i32* %3
%68 = srem i32 %67, 16
%69 = call i32 @Hexvalue(i32 %68)
%70 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %66, i32 %69)
%71 = load i32, i32* %4
%72 = sdiv i32 %71, 16
%73 = call i32 @Hexvalue(i32 %72)
%74 = load i32, i32* %4
%75 = srem i32 %74, 16
%76 = call i32 @Hexvalue(i32 %75)
%77 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %73, i32 %76)
%78 = load i32, i32* %5
%79 = sdiv i32 %78, 16
%80 = call i32 @Hexvalue(i32 %79)
%81 = load i32, i32* %5
%82 = srem i32 %81, 16
%83 = call i32 @Hexvalue(i32 %82)
%84 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %80, i32 %83)
br label %85
85: ; preds = %63, %13
ret i32 0
}