#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*/ printf(char *, int, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *, ...);
int /*<<< orphan*/ stdin;
int main() {
  char inp[16];
  while (fgets(inp, 16, stdin) != NULL) {
    if (inp[0] == '#') {
      int color;
      sscanf(inp, "#%X", &color);
      int r = (color >> 16) & 0xff;
      int g = (color >> 8) & 0xff;
      int b = color & 0xff;
      printf("%d %d %d\n", r, g, b);
    } else {
      int r, g, b;
      sscanf(inp, "%d %d %d", &r, &g, &b);
      int color = r << 16 | g << 8 | b;
      printf("#%06X\n", color);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
mov    0x2e9e(%rip),%rax
mov    (%rax),%edx
mov    $0x10,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     120e <main+0xde>
movsbl -0x20(%rbp),%eax
cmp    $0x23,%eax
jne    11c6 <main+0x96>
lea    -0x20(%rbp),%rdi
lea    0xe88(%rip),%rsi
lea    -0x24(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    -0x24(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1209 <main+0xd9>
lea    -0x20(%rbp),%rdi
lea    0xe3d(%rip),%rsi
lea    -0x34(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x3c(%rbp),%r8
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    -0x34(%rbp),%eax
shl    $0x10,%eax
mov    -0x38(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
or     -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%esi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    113f <main+0xf>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2ea3(%rip),%r13
mov    0x0(%r13),%edx
lea    0x10(%rsp),%rdi
mov    $0x10,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     1209 <main+0xd9>
lea    0x10(%rsp),%rbx
lea    0x4(%rsp),%r15
lea    0xc(%rsp),%rbp
lea    0x8(%rsp),%r14
lea    0xe9b(%rip),%r12
jmp    11ce <main+0x9e>
xchg   %ax,%ax
mov    %rbx,%rdi
lea    0xe84(%rip),%rsi
mov    %r15,%rdx
mov    %rbp,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    0x4(%rsp),%eax
shl    $0x10,%eax
mov    0xc(%rsp),%esi
shl    $0x8,%esi
or     %eax,%esi
or     0x8(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x10,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     1209 <main+0xd9>
cmpb   $0x23,0x10(%rsp)
jne    1180 <main+0x50>
mov    %rbx,%rdi
lea    0xe21(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    0x4(%rsp),%eax
movzbl %ah,%edx
movzbl %al,%ecx
shr    $0x10,%eax
movzbl %al,%esi
lea    0xe04(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11b8 <main+0x88>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c"#%X\00"
@.str.1 = [10 x i8] c"%d %d %d\0A\00"
@.str.2 = [9 x i8] c"%d %d %d\00"
@.str.3 = [7 x i8] c"#%06X\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
br label %11
11: ; preds = %48, %0
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%13 = load i32, i32* @stdin
%14 = call i32* @fgets(i8* %12, i32 16, i32 %13)
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %49
16: ; preds = %11
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 35
br i1 %20, label %21, label %36
21: ; preds = %16
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%23 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
%24 = load i32, i32* %3
%25 = ashr i32 %24, 16
%26 = and i32 %25, 255
store i32 %26, i32* %4
%27 = load i32, i32* %3
%28 = ashr i32 %27, 8
%29 = and i32 %28, 255
store i32 %29, i32* %5
%30 = load i32, i32* %3
%31 = and i32 %30, 255
store i32 %31, i32* %6
%32 = load i32, i32* %4
%33 = load i32, i32* %5
%34 = load i32, i32* %6
%35 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 %33, i32 %34)
br label %48
36: ; preds = %16
%37 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%38 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %37, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %7, i32* %8, i32* %9)
%39 = load i32, i32* %7
%40 = shl i32 %39, 16
%41 = load i32, i32* %8
%42 = shl i32 %41, 8
%43 = or i32 %40, %42
%44 = load i32, i32* %9
%45 = or i32 %43, %44
store i32 %45, i32* %10
%46 = load i32, i32* %10
%47 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %36, %21
br label %11
49: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [4 x i8] c"#%X\00"
@.str.1 = [10 x i8] c"%d %d %d\0A\00"
@.str.2 = [9 x i8] c"%d %d %d\00"
@.str.3 = [7 x i8] c"#%06X\0A\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32* @fgets(i8* %6, i32 16, i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %41, label %10
10: ; preds = %0
%11 = bitcast i32* %3 to i8*
%12 = bitcast i32* %4 to i8*
%13 = bitcast i32* %5 to i8*
%14 = bitcast i32* %2 to i8*
br label %15
15: ; preds = %10, %37
%16 = load i8, i8* %6
%17 = icmp eq i8 %16, 35
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
%20 = load i32, i32* %2
%21 = lshr i32 %20, 16
%22 = and i32 %21, 255
%23 = lshr i32 %20, 8
%24 = and i32 %23, 255
%25 = and i32 %20, 255
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %24, i32 %25)
br label %37
27: ; preds = %15
%28 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%29 = load i32, i32* %3
%30 = shl i32 %29, 16
%31 = load i32, i32* %4
%32 = shl i32 %31, 8
%33 = or i32 %32, %30
%34 = load i32, i32* %5
%35 = or i32 %33, %34
%36 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %27, %18
%38 = load i32, i32* @stdin
%39 = call i32* @fgets(i8* %6, i32 16, i32 %38)
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %15
41: ; preds = %37, %0
ret i32 0
}