#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 */
double atoi(char *);
int hex_to_dec(char);
int strlen(char *);
int parse_hexstr(char *hex, double *rgba) {
  if (!hex || hex[0] != '#' || strlen(hex) < 7)
    return 0;
  rgba[0] = (hex_to_dec(hex[1]) * 16 + hex_to_dec(hex[2])) / 255.0;
  rgba[1] = (hex_to_dec(hex[3]) * 16 + hex_to_dec(hex[4])) / 255.0;
  rgba[2] = (hex_to_dec(hex[5]) * 16 + hex_to_dec(hex[6])) / 255.0;
  if (strlen(hex) > 7)
    rgba[3] = atoi(hex + 7) / 100.0;
  else
    rgba[3] = 1.0;
  return 1;
}


x86 assembly (clang, -O0):
<parse_hexstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116d <parse_hexstr+0x3d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    116d <parse_hexstr+0x3d>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x7,%eax
jge    1179 <parse_hexstr+0x49>
movl   $0x0,-0x4(%rbp)
jmp    1289 <parse_hexstr+0x159>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1040 <hex_to_dec@plt>
shl    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1040 <hex_to_dec@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe54(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%edi
call   1040 <hex_to_dec@plt>
shl    $0x4,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x4(%rax),%edi
call   1040 <hex_to_dec@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe15(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
movsbl 0x5(%rax),%edi
call   1040 <hex_to_dec@plt>
shl    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x6(%rax),%edi
call   1040 <hex_to_dec@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  0xdd5(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x7,%eax
jle    1271 <parse_hexstr+0x141>
mov    -0x10(%rbp),%rdi
add    $0x7,%rdi
call   1050 <atoi@plt>
movsd  0xdb1(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,0x18(%rax)
jmp    1282 <parse_hexstr+0x152>
mov    -0x18(%rbp),%rax
movsd  0xd8b(%rip),%xmm0
movsd  %xmm0,0x18(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_hexstr>:
push   %rbp
push   %r14
push   %rbx
xor    %ebp,%ebp
test   %rdi,%rdi
je     121b <parse_hexstr+0xeb>
mov    %rdi,%rbx
cmpb   $0x23,(%rdi)
jne    121b <parse_hexstr+0xeb>
mov    %rsi,%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x7,%eax
jl     121b <parse_hexstr+0xeb>
movsbl 0x1(%rbx),%edi
call   1040 <hex_to_dec@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x2(%rbx),%edi
call   1040 <hex_to_dec@plt>
add    %ebp,%eax
cvtsi2sd %eax,%xmm0
divsd  0xe7c(%rip),%xmm0
movsd  %xmm0,(%r14)
movsbl 0x3(%rbx),%edi
call   1040 <hex_to_dec@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x4(%rbx),%edi
call   1040 <hex_to_dec@plt>
add    %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xe4f(%rip),%xmm0
movsd  %xmm0,0x8(%r14)
movsbl 0x5(%rbx),%edi
call   1040 <hex_to_dec@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x6(%rbx),%edi
call   1040 <hex_to_dec@plt>
add    %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xe21(%rip),%xmm0
movsd  %xmm0,0x10(%r14)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x8,%eax
jl     1208 <parse_hexstr+0xd8>
add    $0x7,%rbx
mov    %rbx,%rdi
call   1050 <atoi@plt>
divsd  0xe0a(%rip),%xmm0
jmp    1210 <parse_hexstr+0xe0>
movsd  0xdf8(%rip),%xmm0
movsd  %xmm0,0x18(%r14)
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @parse_hexstr(i8* %0, double* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca double*
store i8* %0, i8** %4
store double* %1, double** %5
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 35
br i1 %13, label %18, label %14
14: ; preds = %8
%15 = load i8*, i8** %4
%16 = call i32 @strlen(i8* %15)
%17 = icmp slt i32 %16, 7
br i1 %17, label %18, label %19
18: ; preds = %14, %8, %2
store i32 0, i32* %3
br label %76
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = load i8, i8* %21
%23 = call i32 @hex_to_dec(i8 signext %22)
%24 = mul nsw i32 %23, 16
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 2
%27 = load i8, i8* %26
%28 = call i32 @hex_to_dec(i8 signext %27)
%29 = add nsw i32 %24, %28
%30 = sitofp i32 %29 to double
%31 = fdiv double %30, 2.550000e+02
%32 = load double*, double** %5
%33 = getelementptr inbounds double, double* %32, i64 0
store double %31, double* %33
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 3
%36 = load i8, i8* %35
%37 = call i32 @hex_to_dec(i8 signext %36)
%38 = mul nsw i32 %37, 16
%39 = load i8*, i8** %4
%40 = getelementptr inbounds i8, i8* %39, i64 4
%41 = load i8, i8* %40
%42 = call i32 @hex_to_dec(i8 signext %41)
%43 = add nsw i32 %38, %42
%44 = sitofp i32 %43 to double
%45 = fdiv double %44, 2.550000e+02
%46 = load double*, double** %5
%47 = getelementptr inbounds double, double* %46, i64 1
store double %45, double* %47
%48 = load i8*, i8** %4
%49 = getelementptr inbounds i8, i8* %48, i64 5
%50 = load i8, i8* %49
%51 = call i32 @hex_to_dec(i8 signext %50)
%52 = mul nsw i32 %51, 16
%53 = load i8*, i8** %4
%54 = getelementptr inbounds i8, i8* %53, i64 6
%55 = load i8, i8* %54
%56 = call i32 @hex_to_dec(i8 signext %55)
%57 = add nsw i32 %52, %56
%58 = sitofp i32 %57 to double
%59 = fdiv double %58, 2.550000e+02
%60 = load double*, double** %5
%61 = getelementptr inbounds double, double* %60, i64 2
store double %59, double* %61
%62 = load i8*, i8** %4
%63 = call i32 @strlen(i8* %62)
%64 = icmp sgt i32 %63, 7
br i1 %64, label %65, label %72
65: ; preds = %19
%66 = load i8*, i8** %4
%67 = getelementptr inbounds i8, i8* %66, i64 7
%68 = call double @atoi(i8* %67)
%69 = fdiv double %68, 1.000000e+02
%70 = load double*, double** %5
%71 = getelementptr inbounds double, double* %70, i64 3
store double %69, double* %71
br label %75
72: ; preds = %19
%73 = load double*, double** %5
%74 = getelementptr inbounds double, double* %73, i64 3
store double 1.000000e+00, double* %74
br label %75
75: ; preds = %72, %65
store i32 1, i32* %3
br label %76
76: ; preds = %75, %18
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
define i32 @parse_hexstr(i8* %0, double* nocapture writeonly %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %52, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 35
br i1 %6, label %7, label %52
7: ; preds = %4
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp slt i32 %8, 7
br i1 %9, label %52, label %10
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %0, i64 1
%12 = load i8, i8* %11
%13 = tail call i32 @hex_to_dec(i8 signext %12)
%14 = shl nsw i32 %13, 4
%15 = getelementptr inbounds i8, i8* %0, i64 2
%16 = load i8, i8* %15
%17 = tail call i32 @hex_to_dec(i8 signext %16)
%18 = add nsw i32 %17, %14
%19 = sitofp i32 %18 to double
%20 = fdiv double %19, 2.550000e+02
store double %20, double* %1
%21 = getelementptr inbounds i8, i8* %0, i64 3
%22 = load i8, i8* %21
%23 = tail call i32 @hex_to_dec(i8 signext %22)
%24 = shl nsw i32 %23, 4
%25 = getelementptr inbounds i8, i8* %0, i64 4
%26 = load i8, i8* %25
%27 = tail call i32 @hex_to_dec(i8 signext %26)
%28 = add nsw i32 %27, %24
%29 = sitofp i32 %28 to double
%30 = fdiv double %29, 2.550000e+02
%31 = getelementptr inbounds double, double* %1, i64 1
store double %30, double* %31
%32 = getelementptr inbounds i8, i8* %0, i64 5
%33 = load i8, i8* %32
%34 = tail call i32 @hex_to_dec(i8 signext %33)
%35 = shl nsw i32 %34, 4
%36 = getelementptr inbounds i8, i8* %0, i64 6
%37 = load i8, i8* %36
%38 = tail call i32 @hex_to_dec(i8 signext %37)
%39 = add nsw i32 %38, %35
%40 = sitofp i32 %39 to double
%41 = fdiv double %40, 2.550000e+02
%42 = getelementptr inbounds double, double* %1, i64 2
store double %41, double* %42
%43 = tail call i32 @strlen(i8* %0)
%44 = icmp sgt i32 %43, 7
br i1 %44, label %45, label %49
45: ; preds = %10
%46 = getelementptr inbounds i8, i8* %0, i64 7
%47 = tail call double @atoi(i8* %46)
%48 = fdiv double %47, 1.000000e+02
br label %49
49: ; preds = %10, %45
%50 = phi double [ %48, %45 ], [ 1.000000e+00, %10 ]
%51 = getelementptr inbounds double, double* %1, i64 3
store double %50, double* %51
br label %52
52: ; preds = %49, %2, %4, %7
%53 = phi i32 [ 0, %7 ], [ 0, %4 ], [ 0, %2 ], [ 1, %49 ]
ret i32 %53
}