#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*/ d_to_h(int *, char *);
int /*<<< orphan*/ h_to_d(char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int dec[3];
  char choose, hex[7];
  scanf("%c", &choose);
  if (choose == 'h') {
    scanf("%s", hex);
    h_to_d(hex, dec);
    printf("rgb(%d, %d, %d)\n", dec[0], dec[1], dec[2]);
  } else if (choose == 'd') {
    scanf("%d,%d,%d", &dec[0], &dec[1], &dec[2]);
    d_to_h(dec, hex);
    printf("%s \n", hex);
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x11(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x68,%eax
jne    11a9 <main+0x69>
lea    -0x18(%rbp),%rsi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <h_to_d@plt>
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120d <main+0xcd>
movsbl -0x11(%rbp),%eax
cmp    $0x64,%eax
jne    11fc <main+0xbc>
lea    -0x10(%rbp),%rsi
lea    -0x10(%rbp),%rdx
add    $0x4,%rdx
lea    -0x10(%rbp),%rcx
add    $0x8,%rcx
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <d_to_h@plt>
lea    -0x18(%rbp),%rsi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1208 <main+0xc8>
movl   $0x0,-0x4(%rbp)
jmp    120d <main+0xcd>
jmp    120d <main+0xcd>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xeb2(%rip),%rdi
lea    0x3(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x3(%rsp),%al
cmp    $0x64,%al
je     11a9 <main+0x69>
cmp    $0x68,%al
jne    11ea <main+0xaa>
lea    0xe92(%rip),%rdi
lea    0x11(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <h_to_d@plt>
mov    0x4(%rsp),%esi
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
lea    0xe66(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11ea <main+0xaa>
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0xe5d(%rip),%rdi
lea    0x4(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0x11(%rsp),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <d_to_h@plt>
lea    0xe40(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [17 x i8] c"rgb(%d, %d, %d)\0A\00"
@.str.3 = [9 x i8] c"%d,%d,%d\00"
@.str.4 = [5 x i8] c"%s \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x i32]
%3 = alloca i8
%4 = alloca [7 x i8]
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%6 = load i8, i8* %3
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 104
br i1 %8, label %9, label %22
9: ; preds = %0
%10 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%14 = call i32 @h_to_d(i8* %12, i32* %13)
%15 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 2
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 %18, i32 %20)
br label %38
22: ; preds = %0
%23 = load i8, i8* %3
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 100
br i1 %25, label %26, label %36
26: ; preds = %22
%27 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%28 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 1
%29 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 2
%30 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* %27, i32* %28, i32* %29)
%31 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%32 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%33 = call i32 @d_to_h(i32* %31, i8* %32)
%34 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %34)
br label %37
36: ; preds = %22
store i32 0, i32* %1
br label %38
37: ; preds = %26
br label %38
38: ; preds = %36, %37, %9
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [17 x i8] c"rgb(%d, %d, %d)\0A\00"
@.str.3 = [9 x i8] c"%d,%d,%d\00"
@.str.4 = [5 x i8] c"%s \0A\00"
define i32 @main() {
%1 = alloca [3 x i32]
%2 = alloca i8
%3 = alloca [7 x i8]
%4 = bitcast [3 x i32]* %1 to i8*
%5 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%7 = load i8, i8* %2
switch i8 %7, label %25 [
i8 104, label %8
i8 100, label %18
]
8: ; preds = %0
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%10 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%11 = call i32 @h_to_d(i8* %5, i32* %10)
%12 = load i32, i32* %10
%13 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
%14 = load i32, i32* %13
%15 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
%16 = load i32, i32* %15
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32 %14, i32 %16)
br label %25
18: ; preds = %0
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%20 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
%21 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
%22 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* %19, i32* %20, i32* %21)
%23 = call i32 @d_to_h(i32* %19, i8* %5)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %5)
br label %25
25: ; preds = %8, %18, %0
ret i32 0
}