#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 */
typedef scalar_t__ uint8_t;

/* Variables and functions */
float linearize_sRGB(float);
void linearize_8bit(int width, int height, uint8_t *_s, float *_d) {
#pragma omp parallel for
  for (int y = 0; y < height; y++) {
    float *d = _d + 3 * width * y;
    uint8_t *s = _s + 3 * width * y;
    for (int x = 0; x < width; x++) {
      d[0] = linearize_sRGB((float)s[0] / 255.f);
      d[1] = linearize_sRGB((float)s[1] / 255.f);
      d[2] = linearize_sRGB((float)s[2] / 255.f);
      d += 3;
      s += 3;
    }
  }
}


x86 assembly (clang, -O0):
<linearize_8bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1223 <linearize_8bit+0x113>
mov    -0x18(%rbp),%rax
imul   $0x3,-0x4(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
imul   $0x3,-0x4(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1210 <linearize_8bit+0x100>
mov    -0x30(%rbp),%rax
cvtsi2ssq (%rax),%xmm0
movss  0xe6f(%rip),%xmm1
divss  %xmm1,%xmm0
call   1030 <linearize_sRGB@plt>
mov    -0x28(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
cvtsi2ssq 0x8(%rax),%xmm0
movss  0xe4c(%rip),%xmm1
divss  %xmm1,%xmm0
call   1030 <linearize_sRGB@plt>
mov    -0x28(%rbp),%rax
movss  %xmm0,0x4(%rax)
mov    -0x30(%rbp),%rax
cvtsi2ssq 0x10(%rax),%xmm0
movss  0xe28(%rip),%xmm1
divss  %xmm1,%xmm0
call   1030 <linearize_sRGB@plt>
mov    -0x28(%rbp),%rax
movss  %xmm0,0x8(%rax)
mov    -0x28(%rbp),%rax
add    $0xc,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x18,%rax
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1174 <linearize_8bit+0x64>
jmp    1215 <linearize_8bit+0x105>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112d <linearize_8bit+0x1d>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linearize_8bit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %esi,%esi
jle    11eb <linearize_8bit+0xdb>
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %edi,%r15d
lea    (%r15,%r15,2),%eax
cltq
mov    %esi,%ecx
mov    %rcx,0x8(%rsp)
lea    0x0(,%rax,8),%rcx
mov    %rcx,(%rsp)
shl    $0x2,%rax
mov    %rax,0x10(%rsp)
xor    %r13d,%r13d
movss  0xea4(%rip),%xmm1
jmp    1174 <linearize_8bit+0x64>
xchg   %ax,%ax
add    $0x1,%r13
add    (%rsp),%rbx
add    0x10(%rsp),%r14
cmp    0x8(%rsp),%r13
je     11eb <linearize_8bit+0xdb>
test   %r15d,%r15d
jle    1160 <linearize_8bit+0x50>
xor    %ebp,%ebp
mov    %r15d,%r12d
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2ssq (%rbx,%rbp,2),%xmm0
divss  %xmm1,%xmm0
call   1030 <linearize_sRGB@plt>
movss  %xmm0,(%r14,%rbp,1)
xorps  %xmm0,%xmm0
cvtsi2ssq 0x8(%rbx,%rbp,2),%xmm0
divss  0xe56(%rip),%xmm0
call   1030 <linearize_sRGB@plt>
movss  %xmm0,0x4(%r14,%rbp,1)
xorps  %xmm0,%xmm0
cvtsi2ssq 0x10(%rbx,%rbp,2),%xmm0
divss  0xe38(%rip),%xmm0
call   1030 <linearize_sRGB@plt>
movss  0xe2b(%rip),%xmm1
movss  %xmm0,0x8(%r14,%rbp,1)
add    $0xc,%rbp
add    $0xffffffff,%r12d
jne    1180 <linearize_8bit+0x70>
jmp    1160 <linearize_8bit+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @linearize_8bit(i32 %0, i32 %1, i64* nocapture %2, float* nocapture writeonly %3) {
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %11
6: ; preds = %4
%7 = mul nsw i32 %0, 3
%8 = icmp sgt i32 %0, 0
%9 = sext i32 %7 to i64
%10 = zext i32 %1 to i64
br label %12
11: ; preds = %18, %4
ret void
12: ; preds = %6, %18
%13 = phi i64 [ 0, %6 ], [ %19, %18 ]
%14 = mul nsw i64 %13, %9
br i1 %8, label %15, label %18
15: ; preds = %12
%16 = getelementptr inbounds i64, i64* %2, i64 %14
%17 = getelementptr inbounds float, float* %3, i64 %14
br label %21
18: ; preds = %21, %12
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %19, %10
br i1 %20, label %11, label %12
21: ; preds = %15, %21
%22 = phi i32 [ %43, %21 ], [ 0, %15 ]
%23 = phi i64* [ %42, %21 ], [ %16, %15 ]
%24 = phi float* [ %41, %21 ], [ %17, %15 ]
%25 = load i64, i64* %23
%26 = sitofp i64 %25 to float
%27 = fdiv float %26, 2.550000e+02
%28 = tail call float @linearize_sRGB(float %27)
store float %28, float* %24
%29 = getelementptr inbounds i64, i64* %23, i64 1
%30 = load i64, i64* %29
%31 = sitofp i64 %30 to float
%32 = fdiv float %31, 2.550000e+02
%33 = tail call float @linearize_sRGB(float %32)
%34 = getelementptr inbounds float, float* %24, i64 1
store float %33, float* %34
%35 = getelementptr inbounds i64, i64* %23, i64 2
%36 = load i64, i64* %35
%37 = sitofp i64 %36 to float
%38 = fdiv float %37, 2.550000e+02
%39 = tail call float @linearize_sRGB(float %38)
%40 = getelementptr inbounds float, float* %24, i64 2
store float %39, float* %40
%41 = getelementptr inbounds float, float* %24, i64 3
%42 = getelementptr inbounds i64, i64* %23, i64 3
%43 = add nuw nsw i32 %22, 1
%44 = icmp eq i32 %43, %0
br i1 %44, label %18, label %21
}