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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x15(%rbp),%rsi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
movsbl -0x15(%rbp),%eax
cmp    $0x64,%eax
jne    11cf <main+0x8f>
lea    0xe72(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1060 <call@plt>
mov    -0x10(%rbp),%edi
call   1060 <call@plt>
mov    -0x14(%rbp),%edi
call   1060 <call@plt>
jmp    132d <main+0x1ed>
movsbl -0x15(%rbp),%eax
cmp    $0x68,%eax
jne    1328 <main+0x1e8>
lea    -0x1f(%rbp),%rsi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
cmpl   $0x23,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
cltq
cmpb   $0x0,-0x1f(%rbp,%rax,1)
je     1323 <main+0x1e3>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x38(%rbp)
movslq -0x8(%rbp),%rax
movsbl -0x1f(%rbp,%rax,1),%edi
call   1040 <sort@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x34(%rbp)
movslq -0x8(%rbp),%rax
movsbl -0x1f(%rbp,%rax,1),%edi
call   1040 <sort@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x30(%rbp)
movslq -0x8(%rbp),%rax
movsbl -0x1f(%rbp,%rax,1),%edi
call   1040 <sort@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x2c(%rbp)
movslq -0x8(%rbp),%rax
movsbl -0x1f(%rbp,%rax,1),%edi
call   1040 <sort@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x28(%rbp)
movslq -0x8(%rbp),%rax
movsbl -0x1f(%rbp,%rax,1),%edi
call   1040 <sort@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x24(%rbp)
movslq -0x8(%rbp),%rax
movsbl -0x1f(%rbp,%rax,1),%edi
call   1040 <sort@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xcf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1328 <main+0x1e8>
jmp    132d <main+0x1ed>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movl   $0x0,0x8(%rsp)
movl   $0x0,0x1c(%rsp)
movl   $0x0,0x18(%rsp)
lea    0xe89(%rip),%rdi
lea    0x7(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x7(%rsp),%al
cmp    $0x68,%al
je     11da <main+0x8a>
cmp    $0x64,%al
jne    1262 <main+0x112>
lea    0xe69(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x1c(%rsp),%rdx
lea    0x18(%rsp),%rcx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    $0x23,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%edi
call   1070 <call@plt>
mov    0x1c(%rsp),%edi
call   1070 <call@plt>
mov    0x18(%rsp),%edi
call   1070 <call@plt>
jmp    1262 <main+0x112>
lea    0xe2b(%rip),%rdi
lea    0xe(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpb   $0x0,0xe(%rsp)
je     1262 <main+0x112>
movsbl 0xf(%rsp),%edi
call   1050 <sort@plt>
mov    %eax,%r14d
shl    $0x4,%r14d
movsbl 0x10(%rsp),%edi
call   1050 <sort@plt>
add    %eax,%r14d
mov    %r14d,0x8(%rsp)
movsbl 0x11(%rsp),%edi
call   1050 <sort@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x12(%rsp),%edi
call   1050 <sort@plt>
add    %eax,%ebp
movsbl 0x13(%rsp),%edi
call   1050 <sort@plt>
mov    %eax,%ebx
shl    $0x4,%ebx
movsbl 0x14(%rsp),%edi
call   1050 <sort@plt>
add    %eax,%ebx
lea    0xdbb(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
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 = [9 x i8] c"%d,%d,%d\00"
@.str.2 = [2 x i8] c"#\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [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 i32
%6 = alloca [1 x i8]
%7 = alloca [10 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%8 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 100
br i1 %13, label %14, label %23
14: ; preds = %0
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* %3
%18 = call i32 @call(i32 %17)
%19 = load i32, i32* %4
%20 = call i32 @call(i32 %19)
%21 = load i32, i32* %5
%22 = call i32 @call(i32 %21)
br label %107
23: ; preds = %0
%24 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 104
br i1 %27, label %28, label %106
28: ; preds = %23
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%30 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = load i32, i32* %2
%32 = icmp eq i32 %31, 35
%33 = zext i1 %32 to i32
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = icmp ne i8 %36, 0
br i1 %37, label %38, label %105
38: ; preds = %28
%39 = load i32, i32* %2
%40 = add nsw i32 %39, 1
store i32 %40, i32* %2
%41 = load i32, i32* %3
%42 = mul nsw i32 %41, 16
%43 = load i32, i32* %2
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = call i32 @sort(i8 signext %46)
%48 = add nsw i32 %42, %47
store i32 %48, i32* %3
%49 = load i32, i32* %2
%50 = add nsw i32 %49, 1
store i32 %50, i32* %2
%51 = load i32, i32* %3
%52 = mul nsw i32 %51, 16
%53 = load i32, i32* %2
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = call i32 @sort(i8 signext %56)
%58 = add nsw i32 %52, %57
store i32 %58, i32* %3
%59 = load i32, i32* %2
%60 = add nsw i32 %59, 1
store i32 %60, i32* %2
%61 = load i32, i32* %4
%62 = mul nsw i32 %61, 16
%63 = load i32, i32* %2
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 %64
%66 = load i8, i8* %65
%67 = call i32 @sort(i8 signext %66)
%68 = add nsw i32 %62, %67
store i32 %68, i32* %4
%69 = load i32, i32* %2
%70 = add nsw i32 %69, 1
store i32 %70, i32* %2
%71 = load i32, i32* %4
%72 = mul nsw i32 %71, 16
%73 = load i32, i32* %2
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 %74
%76 = load i8, i8* %75
%77 = call i32 @sort(i8 signext %76)
%78 = add nsw i32 %72, %77
store i32 %78, i32* %4
%79 = load i32, i32* %2
%80 = add nsw i32 %79, 1
store i32 %80, i32* %2
%81 = load i32, i32* %5
%82 = mul nsw i32 %81, 16
%83 = load i32, i32* %2
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 %84
%86 = load i8, i8* %85
%87 = call i32 @sort(i8 signext %86)
%88 = add nsw i32 %82, %87
store i32 %88, i32* %5
%89 = load i32, i32* %2
%90 = add nsw i32 %89, 1
store i32 %90, i32* %2
%91 = load i32, i32* %5
%92 = mul nsw i32 %91, 16
%93 = load i32, i32* %2
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 %94
%96 = load i8, i8* %95
%97 = call i32 @sort(i8 signext %96)
%98 = add nsw i32 %92, %97
store i32 %98, i32* %5
%99 = load i32, i32* %2
%100 = add nsw i32 %99, 1
store i32 %100, i32* %2
%101 = load i32, i32* %3
%102 = load i32, i32* %4
%103 = load i32, i32* %5
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %101, i32 %102, i32 %103)
br label %105
105: ; preds = %38, %28
br label %106
106: ; preds = %105, %23
br label %107
107: ; preds = %106, %14
ret i32 0
}

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