#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 */
char getchar();
int hex_decimal_convert(char, int);
int /*<<< orphan*/ printf(char *, int, int, int);
void hex_to_dec() {
  char input[8];
  int count;
  int red, green, blue;
  for (count = 0; count < 8; count++) {
    input[count] = getchar();
  }
  for (count = 1; count < 3; count++) {
    red = hex_decimal_convert(input[count], count) * 16 +
          hex_decimal_convert(input[count + 1], count);
  }
  for (count = 3; count < 5; count++) {
    green = hex_decimal_convert(input[count], count) * 16 +
            hex_decimal_convert(input[count + 1], count);
  }
  for (count = 5; count < 7; count++) {
    blue = hex_decimal_convert(input[count], count) * 16 +
           hex_decimal_convert(input[count + 1], count);
  }
  printf("rgb(%d, %d, %d)\n", red, green, blue);
}


x86 assembly (clang, -O0):
<hex_to_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    1168 <hex_to_dec+0x38>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,%cl
movslq -0xc(%rbp),%rax
mov    %cl,-0x8(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113f <hex_to_dec+0xf>
movl   $0x1,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    11c1 <hex_to_dec+0x91>
movslq -0xc(%rbp),%rax
mov    -0x8(%rbp,%rax,1),%al
mov    -0xc(%rbp),%esi
movsbl %al,%edi
call   1030 <hex_decimal_convert@plt>
shl    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x8(%rbp,%rax,1),%al
mov    -0xc(%rbp),%esi
movsbl %al,%edi
call   1030 <hex_decimal_convert@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116f <hex_to_dec+0x3f>
movl   $0x3,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jge    121a <hex_to_dec+0xea>
movslq -0xc(%rbp),%rax
mov    -0x8(%rbp,%rax,1),%al
mov    -0xc(%rbp),%esi
movsbl %al,%edi
call   1030 <hex_decimal_convert@plt>
shl    $0x4,%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x8(%rbp,%rax,1),%al
mov    -0xc(%rbp),%esi
movsbl %al,%edi
call   1030 <hex_decimal_convert@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c8 <hex_to_dec+0x98>
movl   $0x5,-0xc(%rbp)
cmpl   $0x7,-0xc(%rbp)
jge    1273 <hex_to_dec+0x143>
movslq -0xc(%rbp),%rax
mov    -0x8(%rbp,%rax,1),%al
mov    -0xc(%rbp),%esi
movsbl %al,%edi
call   1030 <hex_decimal_convert@plt>
shl    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x8(%rbp,%rax,1),%al
mov    -0xc(%rbp),%esi
movsbl %al,%edi
call   1030 <hex_decimal_convert@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1221 <hex_to_dec+0xf1>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xd7d(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_to_dec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%r13d
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %al,0x6(%rsp)
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %al,0x7(%rsp)
movsbl %bl,%edi
mov    $0x1,%esi
call   1030 <hex_decimal_convert@plt>
movsbl %bpl,%ebx
mov    %ebx,%edi
mov    $0x1,%esi
call   1030 <hex_decimal_convert@plt>
mov    %ebx,%edi
mov    $0x2,%esi
call   1030 <hex_decimal_convert@plt>
mov    %eax,%r15d
movsbl %r12b,%ebx
mov    %ebx,%edi
mov    $0x2,%esi
call   1030 <hex_decimal_convert@plt>
mov    %eax,%r12d
mov    %ebx,%edi
mov    $0x3,%esi
call   1030 <hex_decimal_convert@plt>
movsbl %r14b,%ebx
mov    %ebx,%edi
mov    $0x3,%esi
call   1030 <hex_decimal_convert@plt>
mov    %ebx,%edi
mov    $0x4,%esi
call   1030 <hex_decimal_convert@plt>
mov    %eax,%ebx
movsbl %r13b,%ebp
mov    %ebp,%edi
mov    $0x4,%esi
call   1030 <hex_decimal_convert@plt>
mov    %eax,%r14d
mov    %ebp,%edi
mov    $0x5,%esi
call   1030 <hex_decimal_convert@plt>
movsbl 0x6(%rsp),%ebp
mov    %ebp,%edi
mov    $0x5,%esi
call   1030 <hex_decimal_convert@plt>
mov    %ebp,%edi
mov    $0x6,%esi
call   1030 <hex_decimal_convert@plt>
mov    %eax,%ebp
movsbl 0x7(%rsp),%edi
mov    $0x6,%esi
call   1030 <hex_decimal_convert@plt>
shl    $0x4,%ebx
add    %r14d,%ebx
shl    $0x4,%r15d
add    %r12d,%r15d
shl    $0x4,%ebp
add    %eax,%ebp
lea    0xda9(%rip),%rdi
mov    %r15d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"rgb(%d, %d, %d)\0A\00"
define void @hex_to_dec() {
%1 = alloca [8 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %2
br label %6
6: ; preds = %14, %0
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 8
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = call signext i8 (...) @getchar()
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 %12
store i8 %10, i8* %13
br label %14
14: ; preds = %9
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
store i32 %16, i32* %2
br label %6
17: ; preds = %6
store i32 1, i32* %2
br label %18
18: ; preds = %37, %17
%19 = load i32, i32* %2
%20 = icmp slt i32 %19, 3
br i1 %20, label %21, label %40
21: ; preds = %18
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = load i32, i32* %2
%27 = call i32 @hex_decimal_convert(i8 signext %25, i32 %26)
%28 = mul nsw i32 %27, 16
%29 = load i32, i32* %2
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = load i32, i32* %2
%35 = call i32 @hex_decimal_convert(i8 signext %33, i32 %34)
%36 = add nsw i32 %28, %35
store i32 %36, i32* %3
br label %37
37: ; preds = %21
%38 = load i32, i32* %2
%39 = add nsw i32 %38, 1
store i32 %39, i32* %2
br label %18
40: ; preds = %18
store i32 3, i32* %2
br label %41
41: ; preds = %60, %40
%42 = load i32, i32* %2
%43 = icmp slt i32 %42, 5
br i1 %43, label %44, label %63
44: ; preds = %41
%45 = load i32, i32* %2
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = load i32, i32* %2
%50 = call i32 @hex_decimal_convert(i8 signext %48, i32 %49)
%51 = mul nsw i32 %50, 16
%52 = load i32, i32* %2
%53 = add nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = load i32, i32* %2
%58 = call i32 @hex_decimal_convert(i8 signext %56, i32 %57)
%59 = add nsw i32 %51, %58
store i32 %59, i32* %4
br label %60
60: ; preds = %44
%61 = load i32, i32* %2
%62 = add nsw i32 %61, 1
store i32 %62, i32* %2
br label %41
63: ; preds = %41
store i32 5, i32* %2
br label %64
64: ; preds = %83, %63
%65 = load i32, i32* %2
%66 = icmp slt i32 %65, 7
br i1 %66, label %67, label %86
67: ; preds = %64
%68 = load i32, i32* %2
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 %69
%71 = load i8, i8* %70
%72 = load i32, i32* %2
%73 = call i32 @hex_decimal_convert(i8 signext %71, i32 %72)
%74 = mul nsw i32 %73, 16
%75 = load i32, i32* %2
%76 = add nsw i32 %75, 1
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 %77
%79 = load i8, i8* %78
%80 = load i32, i32* %2
%81 = call i32 @hex_decimal_convert(i8 signext %79, i32 %80)
%82 = add nsw i32 %74, %81
store i32 %82, i32* %5
br label %83
83: ; preds = %67
%84 = load i32, i32* %2
%85 = add nsw i32 %84, 1
store i32 %85, i32* %2
br label %64
86: ; preds = %64
%87 = load i32, i32* %3
%88 = load i32, i32* %4
%89 = load i32, i32* %5
%90 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %87, i32 %88, i32 %89)
ret void
}

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