#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(char *, int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ h_to_d(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
scalar_t__ strlen(char *);
int main() {
  char type, hex[8], rgb[20];
  int lenght;
  type = getchar();
  getchar();
  if (type == 'd') {
    fgets(rgb, 20, stdin);
    lenght = (unsigned)strlen(rgb);
    d_to_h(rgb, lenght);
  } else if (type == 'h') {
    fgets(hex, 8, stdin);
    h_to_d(hex);
  } else {
    printf(" Type d or h, nothing else! ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %al,-0x5(%rbp)
mov    $0x0,%al
call   1070 <getchar@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x64,%eax
jne    11c1 <main+0x61>
lea    -0x30(%rbp),%rdi
mov    0x2e50(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1060 <fgets@plt>
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1050 <d_to_h@plt>
jmp    1204 <main+0xa4>
movsbl -0x5(%rbp),%eax
cmp    $0x68,%eax
jne    11f3 <main+0x93>
lea    -0xd(%rbp),%rdi
mov    0x2e0f(%rip),%rax
mov    (%rax),%edx
mov    $0x8,%esi
call   1060 <fgets@plt>
lea    -0xd(%rbp),%rdi
call   1080 <h_to_d@plt>
jmp    11ff <main+0x9f>
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
jmp    1204 <main+0xa4>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0x68,%bl
je     11ac <main+0x4c>
cmp    $0x64,%bl
jne    11cf <main+0x6f>
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <d_to_h@plt>
jmp    11db <main+0x7b>
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x8,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1080 <h_to_d@plt>
jmp    11db <main+0x7b>
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [29 x i8] c" Type d or h, nothing else! \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [8 x i8]
%4 = alloca [20 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = call signext i8 (...) @getchar()
store i8 %6, i8* %2
%7 = call signext i8 (...) @getchar()
%8 = load i8, i8* %2
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 100
br i1 %10, label %11, label %21
11: ; preds = %0
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %12, i32 20, i32 %13)
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%16 = call i64 @strlen(i8* %15)
%17 = trunc i64 %16 to i32
store i32 %17, i32* %5
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%19 = load i32, i32* %5
%20 = call i32 @d_to_h(i8* %18, i32 %19)
br label %34
21: ; preds = %0
%22 = load i8, i8* %2
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 104
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%27 = load i32, i32* @stdin
%28 = call i32 @fgets(i8* %26, i32 8, i32 %27)
%29 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%30 = call i32 @h_to_d(i8* %29)
br label %33
31: ; preds = %21
%32 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %31, %25
br label %34
34: ; preds = %33, %11
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [29 x i8] c" Type d or h, nothing else! \00"
define i32 @main() {
%1 = alloca [8 x i8]
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = tail call signext i8 (...) @getchar()
%6 = tail call signext i8 (...) @getchar()
switch i8 %5, label %17 [
i8 100, label %7
i8 104, label %13
]
7: ; preds = %0
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %4, i32 20, i32 %8)
%10 = call i64 @strlen(i8* %4)
%11 = trunc i64 %10 to i32
%12 = call i32 @d_to_h(i8* %4, i32 %11)
br label %19
13: ; preds = %0
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %3, i32 8, i32 %14)
%16 = call i32 @h_to_d(i8* %3)
br label %19
17: ; preds = %0
%18 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %13, %17, %7
ret i32 0
}