#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 hex_to_rgb_help(char);
int /*<<< orphan*/ printf(char *, ...);
void hex_to_rgb(char *hex) {
  int swot, number1, number2, r, b, g, counter;
  for (counter = 0; counter <= 7; counter++) {
    if (counter % 2 != 0) {
      swot = hex_to_rgb_help(hex[counter]);
      number1 = swot * 16;
    }
    if (counter % 2 == 0) {
      swot = hex_to_rgb_help(hex[counter]);
      number2 = swot;
    }
    if (counter == 2) {
      r = number1 + number2;
    }
    if (counter == 4) {
      g = number1 + number2;
    }
    if (counter == 6) {
      b = number1 + number2;
    }
  }
  printf("rgb(%d,%d,%d)", r, g, b);
  printf("\n");
}


x86 assembly (clang, -O0):
<hex_to_rgb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x7,-0x24(%rbp)
jg     11e8 <hex_to_rgb+0xc8>
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     116e <hex_to_rgb+0x4e>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <hex_to_rgb_help@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x10(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    119c <hex_to_rgb+0x7c>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <hex_to_rgb_help@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x24(%rbp)
jne    11af <hex_to_rgb+0x8f>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x4,-0x24(%rbp)
jne    11c2 <hex_to_rgb+0xa2>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x6,-0x24(%rbp)
jne    11d5 <hex_to_rgb+0xb5>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11da <hex_to_rgb+0xba>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1133 <hex_to_rgb+0x13>
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_to_rgb>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1050 <hex_to_rgb_help@plt>
movsbl 0x1(%rbx),%edi
call   1050 <hex_to_rgb_help@plt>
mov    %eax,%r14d
shl    $0x4,%r14d
movsbl 0x2(%rbx),%edi
call   1050 <hex_to_rgb_help@plt>
add    %eax,%r14d
movsbl 0x3(%rbx),%edi
call   1050 <hex_to_rgb_help@plt>
mov    %eax,%r15d
shl    $0x4,%r15d
movsbl 0x4(%rbx),%edi
call   1050 <hex_to_rgb_help@plt>
add    %eax,%r15d
movsbl 0x5(%rbx),%edi
call   1050 <hex_to_rgb_help@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x6(%rbx),%edi
call   1050 <hex_to_rgb_help@plt>
add    %eax,%ebp
movsbl 0x7(%rbx),%edi
call   1050 <hex_to_rgb_help@plt>
lea    0xe5d(%rip),%rdi
mov    %r14d,%esi
mov    %r15d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"rgb(%d,%d,%d)\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @hex_to_rgb(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %9
br label %10
10: ; preds = %60, %1
%11 = load i32, i32* %9
%12 = icmp sle i32 %11, 7
br i1 %12, label %13, label %63
13: ; preds = %10
%14 = load i32, i32* %9
%15 = srem i32 %14, 2
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = load i8*, i8** %2
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = call i32 @hex_to_rgb_help(i8 signext %22)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = mul nsw i32 %24, 16
store i32 %25, i32* %4
br label %26
26: ; preds = %17, %13
%27 = load i32, i32* %9
%28 = srem i32 %27, 2
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %26
%31 = load i8*, i8** %2
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = call i32 @hex_to_rgb_help(i8 signext %35)
store i32 %36, i32* %3
%37 = load i32, i32* %3
store i32 %37, i32* %5
br label %38
38: ; preds = %30, %26
%39 = load i32, i32* %9
%40 = icmp eq i32 %39, 2
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = load i32, i32* %4
%43 = load i32, i32* %5
%44 = add nsw i32 %42, %43
store i32 %44, i32* %6
br label %45
45: ; preds = %41, %38
%46 = load i32, i32* %9
%47 = icmp eq i32 %46, 4
br i1 %47, label %48, label %52
48: ; preds = %45
%49 = load i32, i32* %4
%50 = load i32, i32* %5
%51 = add nsw i32 %49, %50
store i32 %51, i32* %8
br label %52
52: ; preds = %48, %45
%53 = load i32, i32* %9
%54 = icmp eq i32 %53, 6
br i1 %54, label %55, label %59
55: ; preds = %52
%56 = load i32, i32* %4
%57 = load i32, i32* %5
%58 = add nsw i32 %56, %57
store i32 %58, i32* %7
br label %59
59: ; preds = %55, %52
br label %60
60: ; preds = %59
%61 = load i32, i32* %9
%62 = add nsw i32 %61, 1
store i32 %62, i32* %9
br label %10
63: ; preds = %10
%64 = load i32, i32* %6
%65 = load i32, i32* %8
%66 = load i32, i32* %7
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %64, i32 %65, i32 %66)
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

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