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


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

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xea2(%rip),%rdi
lea    0x3(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x3(%rsp),%al
cmp    $0x64,%al
je     11b5 <main+0x65>
cmp    $0x68,%al
jne    11ed <main+0x9d>
lea    0xe86(%rip),%rdi
lea    0x11(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <hex_to_dec@plt>
mov    0x4(%rsp),%esi
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
lea    0xe5a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ed <main+0x9d>
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0xe51(%rip),%rdi
lea    0x4(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
lea    0x11(%rsp),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <dec_to_hex@plt>
mov    %rbx,%rdi
call   1030 <puts@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 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [7 x i8]
%4 = alloca [3 x i32]
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* %2)
%6 = load i8, i8* %2
%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]* %3, 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]* %3, i64 0, i64 0
%13 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
%14 = call i32 @hex_to_dec(i8* %12, i32* %13)
%15 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %4, 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* %2
%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]* %4, i64 0, i64 0
%28 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 1
%29 = getelementptr inbounds [3 x i32], [3 x i32]* %4, 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]* %4, i64 0, i64 0
%32 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%33 = call i32 @dec_to_hex(i32* %31, i8* %32)
%34 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %34)
br label %37
36: ; preds = %22
store i32 0, i32* %1
br label %39
37: ; preds = %26
br label %38
38: ; preds = %37, %9
store i32 0, i32* %1
br label %39
39: ; preds = %38, %36
%40 = load i32, i32* %1
ret i32 %40
}

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"
define i32 @main() {
%1 = alloca i8
%2 = alloca [7 x i8]
%3 = alloca [3 x i32]
%4 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%5 = bitcast [3 x i32]* %3 to i8*
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%7 = load i8, i8* %1
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* %4)
%10 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%11 = call i32 @hex_to_dec(i8* %4, i32* %10)
%12 = load i32, i32* %10
%13 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 1
%14 = load i32, i32* %13
%15 = getelementptr inbounds [3 x i32], [3 x i32]* %3, 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]* %3, i64 0, i64 0
%20 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 1
%21 = getelementptr inbounds [3 x i32], [3 x i32]* %3, 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 @dec_to_hex(i32* %19, i8* %4)
%24 = call i32 @puts(i8* %4)
br label %25
25: ; preds = %8, %18, %0
ret i32 0
}