#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*/ convert_to_dec(char *, int /*<<< orphan*/, int *);
int /*<<< orphan*/ convert_to_hex(char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ strlen(char *);
int main() {
  char num_sys;
  int con_nums[3] = {0};
  char number[7];
  scanf("%c", &num_sys);
  if (num_sys == 'h') {
    scanf("%s", number);
    convert_to_dec(number, strlen(number), con_nums);
    printf("rgb(");
    for (int i = 0; i < 3; ++i) {
      printf("%d", con_nums[i]);
      if (i < 2) {
        printf(", ");
      }
    }
    printf(")\n");
  } else if (num_sys == 'd') {
    scanf("%d, %d, %d", &con_nums[0], &con_nums[1], &con_nums[2]);
    convert_to_hex(number, con_nums);
    printf("%s\n", number);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x14(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
lea    0xe7a(%rip),%rdi
lea    -0x5(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x68,%eax
jne    1243 <main+0xe3>
lea    -0x1b(%rbp),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1080 <scanf@plt>
lea    -0x1b(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x1b(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
lea    -0x14(%rbp),%rdx
call   1040 <convert_to_dec@plt>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0x3,-0x20(%rbp)
jge    1230 <main+0xd0>
movslq -0x20(%rbp),%rax
mov    -0x14(%rbp,%rax,4),%esi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x2,-0x20(%rbp)
jge    121d <main+0xbd>
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1222 <main+0xc2>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11e5 <main+0x85>
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1296 <main+0x136>
movsbl -0x5(%rbp),%eax
cmp    $0x64,%eax
jne    1291 <main+0x131>
lea    -0x14(%rbp),%rsi
lea    -0x14(%rbp),%rdx
add    $0x4,%rdx
lea    -0x14(%rbp),%rcx
add    $0x8,%rcx
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1080 <scanf@plt>
lea    -0x1b(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1030 <convert_to_hex@plt>
lea    -0x1b(%rbp),%rsi
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1296 <main+0x136>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movl   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe81(%rip),%rdi
lea    0xf(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0xf(%rsp),%al
cmp    $0x64,%al
je     122f <main+0xcf>
cmp    $0x68,%al
jne    1267 <main+0x107>
lea    0xe5d(%rip),%rdi
lea    0x21(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <convert_to_dec@plt>
lea    0xe33(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x10(%rsp),%esi
lea    0xe31(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe15(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x14(%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x18(%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdec(%rip),%rdi
jmp    1262 <main+0x102>
lea    0x14(%rsp),%rdx
lea    0x18(%rsp),%rcx
lea    0xdce(%rip),%rdi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
lea    0x21(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <convert_to_hex@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x28,%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 = [5 x i8] c"rgb(\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [3 x i8] c", \00"
@.str.5 = [3 x i8] c")\0A\00"
@.str.6 = [11 x i8] c"%d, %d, %d\00"
@.str.7 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [3 x i32]
%4 = alloca [7 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [3 x i32]* %3 to i8*
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%8 = load i8, i8* %2
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 104
br i1 %10, label %11, label %39
11: ; preds = %0
%12 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%15 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%18 = call i32 @convert_to_dec(i8* %14, i32 %16, i32* %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %5
br label %20
20: ; preds = %34, %11
%21 = load i32, i32* %5
%22 = icmp slt i32 %21, 3
br i1 %22, label %23, label %37
23: ; preds = %20
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %5
%30 = icmp slt i32 %29, 2
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %31, %23
br label %34
34: ; preds = %33
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %20
37: ; preds = %20
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %54
39: ; preds = %0
%40 = load i8, i8* %2
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 100
br i1 %42, label %43, label %53
43: ; preds = %39
%44 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%45 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 1
%46 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 2
%47 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32* %44, i32* %45, i32* %46)
%48 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%49 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%50 = call i32 @convert_to_hex(i8* %48, i32* %49)
%51 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %43, %39
br label %54
54: ; preds = %53, %37
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [5 x i8] c"rgb(\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [3 x i8] c", \00"
@.str.6 = [11 x i8] c"%d, %d, %d\00"
@str = [2 x i8] c")\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca [3 x i32]
%3 = alloca [7 x i8]
%4 = bitcast [3 x i32]* %2 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* %1)
%7 = load i8, i8* %1
switch i8 %7, label %32 [
i8 104, label %8
i8 100, label %25
]
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 = call i32 @strlen(i8* %5)
%11 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%12 = call i32 @convert_to_dec(i8* %5, i32 %10, i32* %11)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* %11
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 1
%18 = load i32, i32* %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%21 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 2
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %32
25: ; preds = %0
%26 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 0
%27 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 1
%28 = getelementptr inbounds [3 x i32], [3 x i32]* %2, i64 0, i64 2
%29 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32* %26, i32* %27, i32* %28)
%30 = call i32 @convert_to_hex(i8* %5, i32* %26)
%31 = call i32 @puts(i8* %5)
br label %32
32: ; preds = %0, %25, %8
ret i32 0
}