#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 extract_colors(char *, float *);
char *test_extract_colors() {
  float colors[30];
  int res = extract_colors("tests/0001.png", colors);
  do {
    if (!(res == 0))
      return "extract_colors failed";
  } while (0);
  char expected[] = {0x6a, 0x58, 0x40, 0xa3, 0xb4, 0x9e, 0x22, 0x35,
                     0x4d, 0x9d, 0x74, 0x43, 0x3f, 0x6e, 0xae, 0xbf,
                     0x9d, 0x55, 0xa6, 0xc8, 0xe0, 0x6d, 0xab, 0xdb,
                     0xdc, 0xc3, 0x6f, 0xe1, 0xe8, 0xf0};
  for (int i = 0; i < 30; i++) {
    do {
      if (!(expected[i] == (char)(colors[i] * 255.0f)))
        return "extract_colors wrong";
    } while (0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_extract_colors>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
lea    -0x80(%rbp),%rsi
lea    0xede(%rip),%rdi
call   1030 <extract_colors@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
je     114e <test_extract_colors+0x3e>
lea    0xece(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1219 <test_extract_colors+0x109>
jmp    1153 <test_extract_colors+0x43>
mov    0xee6(%rip),%rax
mov    %rax,-0xb0(%rbp)
mov    0xee0(%rip),%rax
mov    %rax,-0xa8(%rbp)
mov    0xeda(%rip),%rax
mov    %rax,-0xa0(%rbp)
mov    0xed5(%rip),%eax
mov    %eax,-0x98(%rbp)
mov    0xecc(%rip),%ax
mov    %ax,-0x94(%rbp)
movl   $0x0,-0xb4(%rbp)
cmpl   $0x1e,-0xb4(%rbp)
jge    1211 <test_extract_colors+0x101>
jmp    11b3 <test_extract_colors+0xa3>
movslq -0xb4(%rbp),%rcx
movsbl -0xb0(%rbp,%rcx,1),%eax
ff
movss  -0x80(%rbp,%rcx,4),%xmm0
movss  0xe30(%rip),%xmm1
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%ecx
movsbl %cl,%ecx
cmp    %ecx,%eax
je     11f3 <test_extract_colors+0xe3>
lea    0xe3f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1219 <test_extract_colors+0x109>
jmp    11f8 <test_extract_colors+0xe8>
jmp    11fd <test_extract_colors+0xed>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    11a1 <test_extract_colors+0x91>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_extract_colors>:
sub    $0x78,%rsp
lea    0xee9(%rip),%rdi
mov    %rsp,%rsi
call   1030 <extract_colors@plt>
test   %eax,%eax
je     1133 <test_extract_colors+0x23>
lea    0xee5(%rip),%rax
add    $0x78,%rsp
ret
mov    $0x2,%ecx
lea    0xf01(%rip),%rdx
movss  0xeb9(%rip),%xmm0
lea    0xedb(%rip),%rax
xchg   %ax,%ax
movss  -0x8(%rsp,%rcx,4),%xmm1
mulss  %xmm0,%xmm1
cvttss2si %xmm1,%esi
cmp    %sil,-0x2(%rcx,%rdx,1)
jne    1199 <test_extract_colors+0x89>
movss  -0x4(%rsp,%rcx,4),%xmm1
mulss  %xmm0,%xmm1
cvttss2si %xmm1,%esi
cmp    %sil,-0x1(%rcx,%rdx,1)
jne    1199 <test_extract_colors+0x89>
movss  (%rsp,%rcx,4),%xmm1
mulss  %xmm0,%xmm1
cvttss2si %xmm1,%esi
cmp    %sil,(%rcx,%rdx,1)
jne    1199 <test_extract_colors+0x89>
add    $0x3,%rcx
cmp    $0x20,%rcx
jne    1150 <test_extract_colors+0x40>
xor    %eax,%eax
add    $0x78,%rsp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"tests/0001.png\00"
@.str.1 = [22 x i8] c"extract_colors failed\00"
@__const.test_extract_colors.expected = [30 x i8] c"jX@\A3\B4\9E\225M\9DtC?n\AE\BF\9DU\A6\C8\E0m\AB\DB\DC\C3o\E1\E8\F0"
@.str.2 = [21 x i8] c"extract_colors wrong\00"
define i8* @test_extract_colors() {
%1 = alloca i8*
%2 = alloca [30 x float]
%3 = alloca i32
%4 = alloca [30 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [30 x float], [30 x float]* %2, i64 0, i64 0
%7 = call i32 @extract_colors(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), float* %6)
store i32 %7, i32* %3
br label %8
8: ; preds = %0
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %8
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8** %1
br label %40
12: ; preds = %8
br label %13
13: ; preds = %12
%14 = bitcast [30 x i8]* %4 to i8*
store i32 0, i32* %5
br label %15
15: ; preds = %36, %13
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 30
br i1 %17, label %18, label %39
18: ; preds = %15
br label %19
19: ; preds = %18
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [30 x float], [30 x float]* %2, i64 0, i64 %26
%28 = load float, float* %27
%29 = fmul float %28, 2.550000e+02
%30 = fptosi float %29 to i8
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %24, %31
br i1 %32, label %34, label %33
33: ; preds = %19
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8** %1
br label %40
34: ; preds = %19
br label %35
35: ; preds = %34
br label %36
36: ; preds = %35
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %15
39: ; preds = %15
store i8* null, i8** %1
br label %40
40: ; preds = %39, %33, %11
%41 = load i8*, i8** %1
ret i8* %41
}

LLVM IR (-O2):
@.str = [15 x i8] c"tests/0001.png\00"
@.str.1 = [22 x i8] c"extract_colors failed\00"
@__const.test_extract_colors.expected = [30 x i8] c"jX@\A3\B4\9E\225M\9DtC?n\AE\BF\9DU\A6\C8\E0m\AB\DB\DC\C3o\E1\E8\F0"
@.str.2 = [21 x i8] c"extract_colors wrong\00"
define i8* @test_extract_colors() {
%1 = alloca [30 x float]
%2 = bitcast [30 x float]* %1 to i8*
%3 = getelementptr inbounds [30 x float], [30 x float]* %1, i64 0, i64 0
%4 = call i32 @extract_colors(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), float* %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %27, label %36
6: ; preds = %27
%7 = add nuw nsw i64 %28, 1
%8 = getelementptr inbounds [30 x i8], [30 x i8]* @__const.test_extract_colors.expected, i64 0, i64 %7
%9 = load i8, i8* %8
%10 = getelementptr inbounds [30 x float], [30 x float]* %1, i64 0, i64 %7
%11 = load float, float* %10
%12 = fmul float %11, 2.550000e+02
%13 = fptosi float %12 to i8
%14 = icmp eq i8 %9, %13
br i1 %14, label %15, label %36
15: ; preds = %6
%16 = add nuw nsw i64 %28, 2
%17 = getelementptr inbounds [30 x i8], [30 x i8]* @__const.test_extract_colors.expected, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = getelementptr inbounds [30 x float], [30 x float]* %1, i64 0, i64 %16
%20 = load float, float* %19
%21 = fmul float %20, 2.550000e+02
%22 = fptosi float %21 to i8
%23 = icmp eq i8 %18, %22
br i1 %23, label %24, label %36
24: ; preds = %15
%25 = add nuw nsw i64 %28, 3
%26 = icmp eq i64 %25, 30
br i1 %26, label %36, label %27
27: ; preds = %0, %24
%28 = phi i64 [ %25, %24 ], [ 0, %0 ]
%29 = getelementptr inbounds [30 x i8], [30 x i8]* @__const.test_extract_colors.expected, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = getelementptr inbounds [30 x float], [30 x float]* %1, i64 0, i64 %28
%32 = load float, float* %31
%33 = fmul float %32, 2.550000e+02
%34 = fptosi float %33 to i8
%35 = icmp eq i8 %30, %34
br i1 %35, label %6, label %36
36: ; preds = %27, %6, %15, %24, %0
%37 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), %0 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), %27 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), %6 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), %15 ], [ null, %24 ]
ret i8* %37
}