#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 strlen(char *);
int strtoul(char *, int /*<<< orphan*/ *, int);
void gethex(char *col, int rgb[]) {
  char b[3];
  int i;
  b[2] = 0;
  if (strlen(col) != 6)
    return;
  for (i = 0; i < 3; i++) {
    b[0] = col[i * 2];
    b[1] = col[i + 2 + 1];
    rgb[i] = strtoul(b, NULL, 16) * 1000 / 255;
  }
}


x86 assembly (clang, -O0):
<gethex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x6,%eax
je     114b <gethex+0x2b>
jmp    11c0 <gethex+0xa0>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    11c0 <gethex+0xa0>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x13(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x2,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x12(%rbp)
lea    -0x13(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtoul@plt>
imul   $0x3e8,%eax,%eax
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1152 <gethex+0x32>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethex>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movb   $0x0,0xf(%rsp)
call   1030 <strlen@plt>
cmp    $0x6,%eax
jne    1205 <gethex+0xe5>
mov    (%rbx),%al
mov    %al,0xd(%rsp)
mov    0x3(%rbx),%al
mov    %al,0xe(%rsp)
lea    0xd(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtoul@plt>
imul   $0x3e8,%eax,%eax
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %ecx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x7,%eax
add    %ecx,%eax
mov    %eax,(%r14)
mov    0x2(%rbx),%al
mov    %al,0xd(%rsp)
mov    0x4(%rbx),%al
mov    %al,0xe(%rsp)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtoul@plt>
imul   $0x3e8,%eax,%eax
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %ecx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x7,%eax
add    %ecx,%eax
mov    %eax,0x4(%r14)
mov    0x4(%rbx),%al
mov    %al,0xd(%rsp)
mov    0x5(%rbx),%al
mov    %al,0xe(%rsp)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtoul@plt>
imul   $0x3e8,%eax,%eax
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %ecx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x7,%eax
add    %ecx,%eax
mov    %eax,0x8(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @gethex(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [3 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
store i8 0, i8* %7
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = icmp ne i32 %9, 6
br i1 %10, label %11, label %12
11: ; preds = %2
br label %43
12: ; preds = %2
store i32 0, i32* %6
br label %13
13: ; preds = %40, %12
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %43
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = load i32, i32* %6
%19 = mul nsw i32 %18, 2
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = load i8, i8* %21
%23 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 %22, i8* %23
%24 = load i8*, i8** %3
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 2
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %24, i64 %28
%30 = load i8, i8* %29
%31 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 %30, i8* %31
%32 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%33 = call i32 @strtoul(i8* %32, i32* null, i32 16)
%34 = mul nsw i32 %33, 1000
%35 = sdiv i32 %34, 255
%36 = load i32*, i32** %4
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
store i32 %35, i32* %39
br label %40
40: ; preds = %16
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %13
43: ; preds = %11, %13
ret void
}

LLVM IR (-O2):
define void @gethex(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
store i8 0, i8* %5
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp eq i32 %6, 6
br i1 %7, label %8, label %31
8: ; preds = %2
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
%10 = load i8, i8* %0
store i8 %10, i8* %4
%11 = getelementptr inbounds i8, i8* %0, i64 3
%12 = load i8, i8* %11
store i8 %12, i8* %9
%13 = call i32 @strtoul(i8* nocapture %4, i32* null, i32 16)
%14 = mul nsw i32 %13, 1000
%15 = sdiv i32 %14, 255
store i32 %15, i32* %1
%16 = getelementptr inbounds i8, i8* %0, i64 2
%17 = load i8, i8* %16
store i8 %17, i8* %4
%18 = getelementptr inbounds i8, i8* %0, i64 4
%19 = load i8, i8* %18
store i8 %19, i8* %9
%20 = call i32 @strtoul(i8* nocapture %4, i32* null, i32 16)
%21 = mul nsw i32 %20, 1000
%22 = sdiv i32 %21, 255
%23 = getelementptr inbounds i32, i32* %1, i64 1
store i32 %22, i32* %23
%24 = load i8, i8* %18
store i8 %24, i8* %4
%25 = getelementptr inbounds i8, i8* %0, i64 5
%26 = load i8, i8* %25
store i8 %26, i8* %9
%27 = call i32 @strtoul(i8* nocapture %4, i32* null, i32 16)
%28 = mul nsw i32 %27, 1000
%29 = sdiv i32 %28, 255
%30 = getelementptr inbounds i32, i32* %1, i64 2
store i32 %29, i32* %30
br label %31
31: ; preds = %8, %2
ret void
}