#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*/ conv_h_to_d();
char getchar();
int /*<<< orphan*/ printf(char *, int, int, int);
int /*<<< orphan*/ scanf(char *, int *, int *, int *);
int main() {
  int r;
  int g;
  int b;
  char a;
  do {
    a = getchar();
  } while (a != 'd' && a != 'h');
  if (a == 'd') {
    do {
      scanf("%d, %d, %d", &r, &g, &b);
    } while (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255);
    printf("#%x%x%x\n", r, g, b);
    return 0;
  }
  if (a == 'h') {
    conv_h_to_d();
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0x64,%ecx
mov    %al,-0x12(%rbp)
je     1178 <main+0x38>
movsbl -0x11(%rbp),%eax
cmp    $0x68,%eax
setne  %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    114f <main+0xf>
movsbl -0x11(%rbp),%eax
cmp    $0x64,%eax
jne    1237 <main+0xf7>
jmp    1195 <main+0x55>
lea    0xe64(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1060 <scanf@plt>
mov    $0x1,%al
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x13(%rbp)
jl     120b <main+0xcb>
mov    $0x1,%al
cmpl   $0xff,-0x8(%rbp)
mov    %al,-0x13(%rbp)
jg     120b <main+0xcb>
mov    $0x1,%al
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x13(%rbp)
jl     120b <main+0xcb>
mov    $0x1,%al
cmpl   $0xff,-0xc(%rbp)
mov    %al,-0x13(%rbp)
jg     120b <main+0xcb>
mov    $0x1,%al
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x13(%rbp)
jl     120b <main+0xcb>
cmpl   $0xff,-0x10(%rbp)
setg   %al
mov    %al,-0x13(%rbp)
mov    -0x13(%rbp),%al
test   $0x1,%al
jne    1195 <main+0x55>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xde5(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    125e <main+0x11e>
movsbl -0x11(%rbp),%eax
cmp    $0x68,%eax
jne    1257 <main+0x117>
mov    $0x0,%al
call   1050 <conv_h_to_d@plt>
movl   $0x0,-0x4(%rbp)
jmp    125e <main+0x11e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0x68,%al
je     11cb <main+0x8b>
cmp    $0x64,%al
jne    1150 <main+0x10>
lea    0xe9a(%rip),%r14
lea    0x14(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1060 <scanf@plt>
mov    0x14(%rsp),%esi
cmp    $0xff,%esi
ja     1180 <main+0x40>
mov    0x10(%rsp),%edx
test   %edx,%edx
js     1180 <main+0x40>
cmp    $0xff,%edx
jg     1180 <main+0x40>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
js     1180 <main+0x40>
cmp    $0xff,%ecx
jg     1180 <main+0x40>
lea    0xe47(%rip),%rdi
call   1030 <printf@plt>
jmp    11d2 <main+0x92>
xor    %eax,%eax
call   1050 <conv_h_to_d@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%d, %d, %d\00"
@.str.1 = [9 x i8] c"#%x%x%x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 0, i32* %1
br label %6
6: ; preds = %16, %0
%7 = call signext i8 (...) @getchar()
store i8 %7, i8* %5
br label %8
8: ; preds = %6
%9 = load i8, i8* %5
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 100
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i8, i8* %5
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 104
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 = load i8, i8* %5
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 100
br i1 %21, label %22, label %50
22: ; preds = %18
br label %23
23: ; preds = %43, %22
%24 = call i32 @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i32* %4)
br label %25
25: ; preds = %23
%26 = load i32, i32* %2
%27 = icmp slt i32 %26, 0
br i1 %27, label %43, label %28
28: ; preds = %25
%29 = load i32, i32* %2
%30 = icmp sgt i32 %29, 255
br i1 %30, label %43, label %31
31: ; preds = %28
%32 = load i32, i32* %3
%33 = icmp slt i32 %32, 0
br i1 %33, label %43, label %34
34: ; preds = %31
%35 = load i32, i32* %3
%36 = icmp sgt i32 %35, 255
br i1 %36, label %43, label %37
37: ; preds = %34
%38 = load i32, i32* %4
%39 = icmp slt i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %37
%41 = load i32, i32* %4
%42 = icmp sgt i32 %41, 255
br label %43
43: ; preds = %40, %37, %34, %31, %28, %25
%44 = phi i1 [ true, %37 ], [ true, %34 ], [ true, %31 ], [ true, %28 ], [ true, %25 ], [ %42, %40 ]
br i1 %44, label %23, label %45
45: ; preds = %43
%46 = load i32, i32* %2
%47 = load i32, i32* %3
%48 = load i32, i32* %4
%49 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %46, i32 %47, i32 %48)
store i32 0, i32* %1
br label %57
50: ; preds = %18
%51 = load i8, i8* %5
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 104
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 (...) @conv_h_to_d()
store i32 0, i32* %1
br label %57
56: ; preds = %50
store i32 0, i32* %1
br label %57
57: ; preds = %56, %54, %45
%58 = load i32, i32* %1
ret i32 %58
}

LLVM IR (-O2):
@.str = [11 x i8] c"%d, %d, %d\00"
@.str.1 = [9 x i8] c"#%x%x%x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
br label %7
7: ; preds = %7, %0
%8 = tail call signext i8 (...) @getchar()
switch i8 %8, label %7 [
i8 100, label %9
i8 104, label %25
]
9: ; preds = %7, %9
%10 = call i32 @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%11 = load i32, i32* %1
%12 = icmp ugt i32 %11, 255
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 0
%15 = select i1 %12, i1 true, i1 %14
%16 = icmp sgt i32 %13, 255
%17 = select i1 %15, i1 true, i1 %16
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 0
%20 = select i1 %17, i1 true, i1 %19
%21 = icmp sgt i32 %18, 255
%22 = select i1 %20, i1 true, i1 %21
br i1 %22, label %9, label %23
23: ; preds = %9
%24 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %13, i32 %18)
br label %27
25: ; preds = %7
%26 = tail call i32 (...) @conv_h_to_d()
br label %27
27: ; preds = %25, %23
ret i32 0
}