#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 */
struct color {
  int dummy;
};

/* Variables and functions */
struct color *color_new(double, double, double);
int /*<<< orphan*/ is_color(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
unsigned int strtol(char *, int /*<<< orphan*/ *, int);
struct color *str_to_color(const char *str) {
  char tmp[5];
  unsigned int red, green, blue;
  if (!is_color(str))
    return NULL;
  strncpy(tmp, str + 1, 4);
  tmp[4] = '\0';
  red = strtol(tmp, NULL, 16);
  strncpy(tmp, str + 5, 4);
  tmp[4] = '\0';
  green = strtol(tmp, NULL, 16);
  strncpy(tmp, str + 9, 4);
  tmp[4] = '\0';
  blue = strtol(tmp, NULL, 16);
  return color_new(((double)red) / 65535, ((double)green) / 65535,
                   ((double)blue) / 65535);
}


x86 assembly (clang, -O0):
<str_to_color>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <is_color@plt>
cmp    $0x0,%eax
jne    116b <str_to_color+0x2b>
movq   $0x0,-0x8(%rbp)
jmp    123b <str_to_color+0xfb>
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
lea    -0x15(%rbp),%rdi
mov    %rdi,-0x38(%rbp)
mov    $0x4,%edx
mov    %edx,-0x3c(%rbp)
call   1030 <strncpy@plt>
mov    -0x38(%rbp),%rdi
movb   $0x0,-0x11(%rbp)
xor    %eax,%eax
mov    %eax,%esi
mov    %rsi,-0x30(%rbp)
mov    $0x10,%edx
mov    %edx,-0x28(%rbp)
call   1040 <strtol@plt>
mov    -0x3c(%rbp),%edx
mov    -0x38(%rbp),%rdi
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
add    $0x5,%rsi
call   1030 <strncpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%edx
movb   $0x0,-0x11(%rbp)
call   1040 <strtol@plt>
mov    -0x3c(%rbp),%edx
mov    -0x38(%rbp),%rdi
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
add    $0x9,%rsi
call   1030 <strncpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%edx
movb   $0x0,-0x11(%rbp)
call   1040 <strtol@plt>
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xdf2(%rip),%xmm2
divsd  %xmm2,%xmm0
mov    -0x20(%rbp),%eax
cvtsi2sd %rax,%xmm1
divsd  %xmm2,%xmm1
mov    -0x24(%rbp),%eax
cvtsi2sd %rax,%xmm2
movsd  0xdd2(%rip),%xmm3
divsd  %xmm3,%xmm2
call   1060 <color_new@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_to_color>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <is_color@plt>
test   %eax,%eax
je     1204 <str_to_color+0xc4>
lea    0x1(%rbx),%rsi
lea    0x3(%rsp),%r14
mov    %r14,%rdi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x7(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,%r15d
lea    0x5(%rbx),%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x7(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,%ebp
add    $0x9,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x7(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %r15d,%ecx
cvtsi2sd %rcx,%xmm0
movsd  0xe1d(%rip),%xmm3
divsd  %xmm3,%xmm0
mov    %ebp,%ecx
cvtsi2sd %rcx,%xmm1
divsd  %xmm3,%xmm1
mov    %eax,%eax
cvtsi2sd %rax,%xmm2
divsd  %xmm3,%xmm2
call   1060 <color_new@plt>
jmp    1206 <str_to_color+0xc6>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.color = type { i32 }
define %struct.color* @str_to_color(i8* %0) {
%2 = alloca %struct.color*
%3 = alloca i8*
%4 = alloca [5 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @is_color(i8* %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %1
store %struct.color* null, %struct.color** %2
br label %44
12: ; preds = %1
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = call i32 @strncpy(i8* %13, i8* %15, i32 4)
%17 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 4
store i8 0, i8* %17
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%19 = call i32 @strtol(i8* %18, i32* null, i32 16)
store i32 %19, i32* %5
%20 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i64 5
%23 = call i32 @strncpy(i8* %20, i8* %22, i32 4)
%24 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 4
store i8 0, i8* %24
%25 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%26 = call i32 @strtol(i8* %25, i32* null, i32 16)
store i32 %26, i32* %6
%27 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 9
%30 = call i32 @strncpy(i8* %27, i8* %29, i32 4)
%31 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 4
store i8 0, i8* %31
%32 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%33 = call i32 @strtol(i8* %32, i32* null, i32 16)
store i32 %33, i32* %7
%34 = load i32, i32* %5
%35 = uitofp i32 %34 to double
%36 = fdiv double %35, 6.553500e+04
%37 = load i32, i32* %6
%38 = uitofp i32 %37 to double
%39 = fdiv double %38, 6.553500e+04
%40 = load i32, i32* %7
%41 = uitofp i32 %40 to double
%42 = fdiv double %41, 6.553500e+04
%43 = call %struct.color* @color_new(double %36, double %39, double %42)
store %struct.color* %43, %struct.color** %2
br label %44
44: ; preds = %12, %11
%45 = load %struct.color*, %struct.color** %2
ret %struct.color* %45
}

LLVM IR (-O2):
%struct.color = type { i32 }
define %struct.color* @str_to_color(i8* %0) {
%2 = alloca [5 x i8]
%3 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @is_color(i8* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %24, label %6
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = call i32 @strncpy(i8* %3, i8* %7, i32 4)
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 4
store i8 0, i8* %9
%10 = call i32 @strtol(i8* nocapture %3, i32* null, i32 16)
%11 = getelementptr inbounds i8, i8* %0, i64 5
%12 = call i32 @strncpy(i8* %3, i8* %11, i32 4)
store i8 0, i8* %9
%13 = call i32 @strtol(i8* nocapture %3, i32* null, i32 16)
%14 = getelementptr inbounds i8, i8* %0, i64 9
%15 = call i32 @strncpy(i8* %3, i8* %14, i32 4)
store i8 0, i8* %9
%16 = call i32 @strtol(i8* nocapture %3, i32* null, i32 16)
%17 = uitofp i32 %10 to double
%18 = fdiv double %17, 6.553500e+04
%19 = uitofp i32 %13 to double
%20 = fdiv double %19, 6.553500e+04
%21 = uitofp i32 %16 to double
%22 = fdiv double %21, 6.553500e+04
%23 = call %struct.color* @color_new(double %18, double %20, double %22)
br label %24
24: ; preds = %1, %6
%25 = phi %struct.color* [ %23, %6 ], [ null, %1 ]
ret %struct.color* %25
}