#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*/ QS_VASSERT(int, char *, float);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
void colorStr(char str[8], float r, float g, float b) {
  QS_VASSERT(r >= 0 && r <= (0x3F) + 0.01F, "r=%f", r);
  QS_VASSERT(g >= 0 && g <= (0x3F) + 0.01F, "g=%f", g);
  QS_VASSERT(b >= 0 && b <= (0x3F) + 0.01F, "b=%f", b);
  int R, G, B;
  R = r + 0.5F;
  G = g + 0.5F;
  B = b + 0.5F;
  snprintf(str, 8, "#%6.6X",
           (((R * 0xFF) / (0x3F)) << 16) + (((G * 0xFF) / (0x3F)) << 8) +
               (B * 0xFF) / (0x3F));
}


x86 assembly (clang, -O0):
<colorStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  %xmm1,-0x10(%rbp)
movss  %xmm2,-0x14(%rbp)
movss  -0xc(%rbp),%xmm0
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
mov    %al,-0x21(%rbp)
jb     1163 <colorStr+0x43>
movss  0xea7(%rip),%xmm0
ucomiss -0xc(%rbp),%xmm0
setae  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
movss  -0xc(%rbp),%xmm0
lea    0xe91(%rip),%rsi
call   1040 <QS_VASSERT@plt>
movss  -0x10(%rbp),%xmm0
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
mov    %al,-0x22(%rbp)
jb     11a4 <colorStr+0x84>
movss  0xe66(%rip),%xmm0
ucomiss -0x10(%rbp),%xmm0
setae  %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
movss  -0x10(%rbp),%xmm0
lea    0xe55(%rip),%rsi
call   1040 <QS_VASSERT@plt>
movss  -0x14(%rbp),%xmm0
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
mov    %al,-0x23(%rbp)
jb     11e5 <colorStr+0xc5>
movss  0xe25(%rip),%xmm0
ucomiss -0x14(%rbp),%xmm0
setae  %al
mov    %al,-0x23(%rbp)
mov    -0x23(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
movss  -0x14(%rbp),%xmm0
lea    0xe19(%rip),%rsi
call   1040 <QS_VASSERT@plt>
movss  0xdfe(%rip),%xmm0
addss  -0xc(%rbp),%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
movss  0xdea(%rip),%xmm0
addss  -0x10(%rbp),%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x1c(%rbp)
movss  0xdd6(%rip),%xmm0
addss  -0x14(%rbp),%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
imul   $0xff,-0x18(%rbp),%eax
mov    $0x3f,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
shl    $0x10,%ecx
imul   $0xff,-0x1c(%rbp),%eax
mov    $0x3f,%esi
cltd
idiv   %esi
shl    $0x8,%eax
add    %eax,%ecx
imul   $0xff,-0x20(%rbp),%eax
mov    $0x3f,%esi
cltd
idiv   %esi
add    %eax,%ecx
mov    $0x8,%esi
lea    0xd94(%rip),%rdx
call   1030 <snprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<colorStr>:
push   %rbx
sub    $0x10,%rsp
xorps  %xmm3,%xmm3
ucomiss %xmm3,%xmm0
setae  %al
movss  0xeca(%rip),%xmm3
ucomiss %xmm0,%xmm3
movss  %xmm0,0xc(%rsp)
movss  %xmm2,0x8(%rsp)
movss  %xmm1,0x4(%rsp)
mov    %rdi,%rbx
setae  %cl
and    %al,%cl
movzbl %cl,%edi
lea    0xeaf(%rip),%rsi
call   1040 <QS_VASSERT@plt>
movss  0x4(%rsp),%xmm0
ucomiss 0xe99(%rip),%xmm0
setae  %al
movss  0xe86(%rip),%xmm1
ucomiss %xmm0,%xmm1
setae  %cl
and    %al,%cl
movzbl %cl,%edi
lea    0xe85(%rip),%rsi
call   1040 <QS_VASSERT@plt>
movss  0x8(%rsp),%xmm0
ucomiss 0xe6a(%rip),%xmm0
setae  %al
movss  0xe57(%rip),%xmm1
ucomiss %xmm0,%xmm1
setae  %cl
and    %al,%cl
movzbl %cl,%edi
lea    0xe5b(%rip),%rsi
call   1040 <QS_VASSERT@plt>
movss  0xe3c(%rip),%xmm0
movss  0xc(%rsp),%xmm1
addss  %xmm0,%xmm1
cvttss2si %xmm1,%ecx
movss  0x4(%rsp),%xmm1
addss  %xmm0,%xmm1
cvttss2si %xmm1,%edx
movss  0x8(%rsp),%xmm1
addss  %xmm0,%xmm1
cvttss2si %xmm1,%eax
mov    %ecx,%esi
shl    $0x8,%esi
sub    %ecx,%esi
movslq %esi,%rcx
imul   $0xffffffff82082083,%rcx,%rsi
shr    $0x20,%rsi
add    %esi,%ecx
mov    %ecx,%esi
shr    $0x1f,%esi
shr    $0x5,%ecx
add    %esi,%ecx
shl    $0x10,%ecx
mov    %edx,%esi
shl    $0x8,%esi
sub    %edx,%esi
movslq %esi,%rdx
imul   $0xffffffff82082083,%rdx,%rsi
shr    $0x20,%rsi
add    %esi,%edx
mov    %edx,%esi
shr    $0x1f,%esi
shr    $0x5,%edx
add    %esi,%edx
shl    $0x8,%edx
add    %ecx,%edx
mov    %eax,%ecx
shl    $0x8,%ecx
sub    %eax,%ecx
movslq %ecx,%rcx
imul   $0xffffffff82082083,%rcx,%rax
shr    $0x20,%rax
add    %eax,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0x5,%ecx
add    %eax,%ecx
add    %edx,%ecx
lea    0xdb5(%rip),%rdx
mov    %rbx,%rdi
mov    $0x8,%esi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"r=%f\00"
@.str.1 = [5 x i8] c"g=%f\00"
@.str.2 = [5 x i8] c"b=%f\00"
@.str.3 = [7 x i8] c"#%6.6X\00"
define void @colorStr(i8* %0, float %1, float %2, float %3) {
%5 = alloca i8*
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store float %1, float* %6
store float %2, float* %7
store float %3, float* %8
%12 = load float, float* %6
%13 = fcmp oge float %12, 0.000000e+00
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = load float, float* %6
%16 = fcmp ole float %15, 0x404F8147A0000000
br label %17
17: ; preds = %14, %4
%18 = phi i1 [ false, %4 ], [ %16, %14 ]
%19 = zext i1 %18 to i32
%20 = load float, float* %6
%21 = call i32 @QS_VASSERT(i32 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), float %20)
%22 = load float, float* %7
%23 = fcmp oge float %22, 0.000000e+00
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = load float, float* %7
%26 = fcmp ole float %25, 0x404F8147A0000000
br label %27
27: ; preds = %24, %17
%28 = phi i1 [ false, %17 ], [ %26, %24 ]
%29 = zext i1 %28 to i32
%30 = load float, float* %7
%31 = call i32 @QS_VASSERT(i32 %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float %30)
%32 = load float, float* %8
%33 = fcmp oge float %32, 0.000000e+00
br i1 %33, label %34, label %37
34: ; preds = %27
%35 = load float, float* %8
%36 = fcmp ole float %35, 0x404F8147A0000000
br label %37
37: ; preds = %34, %27
%38 = phi i1 [ false, %27 ], [ %36, %34 ]
%39 = zext i1 %38 to i32
%40 = load float, float* %8
%41 = call i32 @QS_VASSERT(i32 %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), float %40)
%42 = load float, float* %6
%43 = fadd float %42, 5.000000e-01
%44 = fptosi float %43 to i32
store i32 %44, i32* %9
%45 = load float, float* %7
%46 = fadd float %45, 5.000000e-01
%47 = fptosi float %46 to i32
store i32 %47, i32* %10
%48 = load float, float* %8
%49 = fadd float %48, 5.000000e-01
%50 = fptosi float %49 to i32
store i32 %50, i32* %11
%51 = load i8*, i8** %5
%52 = load i32, i32* %9
%53 = mul nsw i32 %52, 255
%54 = sdiv i32 %53, 63
%55 = shl i32 %54, 16
%56 = load i32, i32* %10
%57 = mul nsw i32 %56, 255
%58 = sdiv i32 %57, 63
%59 = shl i32 %58, 8
%60 = add nsw i32 %55, %59
%61 = load i32, i32* %11
%62 = mul nsw i32 %61, 255
%63 = sdiv i32 %62, 63
%64 = add nsw i32 %60, %63
%65 = call i32 @snprintf(i8* %51, i32 8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %64)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"r=%f\00"
@.str.1 = [5 x i8] c"g=%f\00"
@.str.2 = [5 x i8] c"b=%f\00"
@.str.3 = [7 x i8] c"#%6.6X\00"
define void @colorStr(i8* %0, float %1, float %2, float %3) {
%5 = fcmp oge float %1, 0.000000e+00
%6 = fcmp ole float %1, 0x404F8147A0000000
%7 = and i1 %5, %6
%8 = zext i1 %7 to i32
%9 = tail call i32 @QS_VASSERT(i32 %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), float %1)
%10 = fcmp oge float %2, 0.000000e+00
%11 = fcmp ole float %2, 0x404F8147A0000000
%12 = and i1 %10, %11
%13 = zext i1 %12 to i32
%14 = tail call i32 @QS_VASSERT(i32 %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float %2)
%15 = fcmp oge float %3, 0.000000e+00
%16 = fcmp ole float %3, 0x404F8147A0000000
%17 = and i1 %15, %16
%18 = zext i1 %17 to i32
%19 = tail call i32 @QS_VASSERT(i32 %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), float %3)
%20 = fadd float %1, 5.000000e-01
%21 = fptosi float %20 to i32
%22 = fadd float %2, 5.000000e-01
%23 = fptosi float %22 to i32
%24 = fadd float %3, 5.000000e-01
%25 = fptosi float %24 to i32
%26 = mul nsw i32 %21, 255
%27 = sdiv i32 %26, 63
%28 = shl i32 %27, 16
%29 = mul nsw i32 %23, 255
%30 = sdiv i32 %29, 63
%31 = shl i32 %30, 8
%32 = add nsw i32 %31, %28
%33 = mul nsw i32 %25, 255
%34 = sdiv i32 %33, 63
%35 = add nsw i32 %32, %34
%36 = tail call i32 @snprintf(i8* %0, i32 8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %35)
ret void
}