#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*/ printf(char *, int, int, int);
int transform(char);
void h_to_d(char *hex) {
  int count, total = 0, r, g, b;
  for (count = 1; count < 7; count++) {
    if (count % 2 == 1) {
      total = transform(hex[count]) * 16;
    } else {
      total = total + transform(hex[count]);
      if (count == 2)
        r = total;
      if (count == 4)
        g = total;
      if (count == 6)
        b = total;
    }
  }
  printf("rgb(%d, %d, %d)", r, g, b);
}


x86 assembly (clang, -O0):
<h_to_d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x7,-0xc(%rbp)
jge    11dd <h_to_d+0xbd>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1174 <h_to_d+0x54>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <transform@plt>
shl    $0x4,%eax
mov    %eax,-0x10(%rbp)
jmp    11ca <h_to_d+0xaa>
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <transform@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x2,-0xc(%rbp)
jne    11a5 <h_to_d+0x85>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x4,-0xc(%rbp)
jne    11b5 <h_to_d+0x95>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x6,-0xc(%rbp)
jne    11c5 <h_to_d+0xa5>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11ca <h_to_d+0xaa>
jmp    11cf <h_to_d+0xaf>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113a <h_to_d+0x1a>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe13(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<h_to_d>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
movsbl 0x1(%rdi),%edi
call   1030 <transform@plt>
mov    %eax,%r14d
shl    $0x4,%r14d
movsbl 0x2(%r15),%edi
call   1030 <transform@plt>
add    %eax,%r14d
movsbl 0x3(%r15),%edi
call   1030 <transform@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x4(%r15),%edi
call   1030 <transform@plt>
add    %eax,%ebp
movsbl 0x5(%r15),%edi
call   1030 <transform@plt>
mov    %eax,%ebx
shl    $0x4,%ebx
movsbl 0x6(%r15),%edi
call   1030 <transform@plt>
add    %eax,%ebx
lea    0xe7c(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

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

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