#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 get_int(char);
int /*<<< orphan*/ printf(char *, int, int, int);
int /*<<< orphan*/ scanf(char *, char *);
void hex_to_dec() {
  int counter_h, counter_d, dec[3];
  char hex[7];
  scanf("%s", hex);
  for (counter_h = 1, counter_d = 0; counter_h < 7;
       counter_h += 2, counter_d++) {
    dec[counter_d] = get_int(hex[counter_h]) * 16 + get_int(hex[counter_h + 1]);
  }
  printf("rgb(%d, %d, %d) \n", dec[0], dec[1], dec[2]);
}


x86 assembly (clang, -O0):
<hex_to_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x1b(%rbp),%rsi
lea    0xebd(%rip),%rdi
call   1040 <scanf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x7,-0x4(%rbp)
jge    11aa <hex_to_dec+0x7a>
movslq -0x4(%rbp),%rax
movsbl -0x1b(%rbp,%rax,1),%edi
call   1050 <get_int@plt>
shl    $0x4,%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x1b(%rbp,%rax,1),%edi
call   1050 <get_int@plt>
mov    -0x20(%rbp),%ecx
add    %eax,%ecx
movslq -0x8(%rbp),%rax
mov    %ecx,-0x14(%rbp,%rax,4)
mov    -0x4(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1156 <hex_to_dec+0x26>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_to_dec>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
lea    0x9(%rsp),%rsi
call   1040 <scanf@plt>
movsbl 0xa(%rsp),%edi
call   1050 <get_int@plt>
mov    %eax,%r14d
shl    $0x4,%r14d
movsbl 0xb(%rsp),%edi
call   1050 <get_int@plt>
add    %eax,%r14d
movsbl 0xc(%rsp),%edi
call   1050 <get_int@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0xd(%rsp),%edi
call   1050 <get_int@plt>
add    %eax,%ebp
movsbl 0xe(%rsp),%edi
call   1050 <get_int@plt>
mov    %eax,%ebx
shl    $0x4,%ebx
movsbl 0xf(%rsp),%edi
call   1050 <get_int@plt>
add    %eax,%ebx
lea    0xe5f(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [18 x i8] c"rgb(%d, %d, %d) \0A\00"
define void @hex_to_dec() {
%1 = alloca [7 x i8]
%2 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 1
%5 = load i8, i8* %4
%6 = call i32 @get_int(i8 signext %5)
%7 = shl nsw i32 %6, 4
%8 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 2
%9 = load i8, i8* %8
%10 = call i32 @get_int(i8 signext %9)
%11 = add nsw i32 %10, %7
%12 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 3
%13 = load i8, i8* %12
%14 = call i32 @get_int(i8 signext %13)
%15 = shl nsw i32 %14, 4
%16 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 4
%17 = load i8, i8* %16
%18 = call i32 @get_int(i8 signext %17)
%19 = add nsw i32 %18, %15
%20 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 5
%21 = load i8, i8* %20
%22 = call i32 @get_int(i8 signext %21)
%23 = shl nsw i32 %22, 4
%24 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 6
%25 = load i8, i8* %24
%26 = call i32 @get_int(i8 signext %25)
%27 = add nsw i32 %26, %23
%28 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %19, i32 %27)
ret void
}