#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 int /*<<< orphan*/ uint8_t;

/* Variables and functions */
float floorf(float);
float powf(float, float);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  float r;
  uint8_t srgb;
  int i;
  printf("static const float srgb_to_linear[256] =\n");
  printf("{\n");
  for (i = 0; i < 256; i++) {
    r = i / 256.0f;
    r = (r > 0.04045f) ? powf((r + 0.055f) / 1.055f, 2.4f) : r / 12.92f;
    printf((i < 255) ? "    %f,\n" : "    %f\n", r);
  }
  printf("};\n");
  printf("static const uint8_t linear_to_srgb[4096] =\n");
  printf("{\n");
  for (i = 0; i < 4096; i++) {
    r = i / 4096.0f;
    r = (r > 0.0031308f) ? (1.055f * powf(r, 1.0f / 2.4f) - 0.055f)
                         : r * 12.92f;
    r = floorf(r * 256.0f);
    srgb = (uint8_t)((r < 0) ? 0 : (r <= 255) ? r : 255);
    printf((i < 4095) ? "    %d,\n" : "    %d\n", srgb);
  }
  printf("};\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xedf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xefb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jge    122b <main+0xfb>
cvtsi2ssl -0x1c(%rbp),%xmm0
movss  0xe95(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
movss  0xe87(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    11d2 <main+0xa2>
movss  0xe7e(%rip),%xmm0
addss  -0x14(%rbp),%xmm0
movss  0xe55(%rip),%xmm1
divss  %xmm1,%xmm0
movss  0xe61(%rip),%xmm1
call   1030 <powf@plt>
movss  %xmm0,-0x20(%rbp)
jmp    11e8 <main+0xb8>
movss  -0x14(%rbp),%xmm0
movss  0xe29(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x1c(%rbp),%ecx
lea    0xe66(%rip),%rdi
lea    0xe56(%rip),%rax
cmp    $0xff,%ecx
cmovl  %rax,%rdi
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1169 <main+0x39>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1000,-0x1c(%rbp)
jge    1392 <main+0x262>
cvtsi2ssl -0x1c(%rbp),%xmm0
movss  0xd8e(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
movss  0xd74(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    12c9 <main+0x199>
movss  -0x14(%rbp),%xmm0
movss  0xd72(%rip),%xmm1
call   1030 <powf@plt>
movss  0xd5d(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xd55(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
jmp    12db <main+0x1ab>
movss  0xd37(%rip),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  0xd2b(%rip),%xmm0
mulss  -0x14(%rbp),%xmm0
call   1050 <floorf@plt>
movss  %xmm0,-0x14(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x14(%rbp),%xmm0
jbe    1316 <main+0x1e6>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
jmp    1353 <main+0x223>
movss  0xcfe(%rip),%xmm0
ucomiss -0x14(%rbp),%xmm0
jb     1337 <main+0x207>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
jmp    1349 <main+0x219>
movss  0xcdd(%rip),%xmm0
movss  %xmm0,-0x2c(%rbp)
jmp    1349 <main+0x219>
movss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x28(%rbp),%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%ecx
lea    0xd3b(%rip),%rdi
lea    0xd2b(%rip),%rax
cmp    $0xfff,%ecx
cmovl  %rax,%rdi
mov    -0x18(%rbp),%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    125c <main+0x12c>
lea    0xcd1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xf0b(%rip),%rdi
call   1030 <puts@plt>
lea    0xf54(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
lea    0xecf(%rip),%r14
lea    0xed1(%rip),%rbp
jmp    119b <main+0x5b>
xchg   %ax,%ax
divss  0xe90(%rip),%xmm0
cmp    $0xff,%ebx
mov    %rbp,%rdi
cmovb  %r14,%rdi
cvtss2sd %xmm0,%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x1,%ebx
cmp    $0x100,%ebx
je     11d2 <main+0x92>
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
mulss  0xe56(%rip),%xmm0
ucomiss 0xe53(%rip),%xmm0
jbe    1170 <main+0x30>
addss  0xe51(%rip),%xmm0
divss  0xe4d(%rip),%xmm0
movss  0xe49(%rip),%xmm1
call   1040 <powf@plt>
jmp    1178 <main+0x38>
lea    0xed4(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
lea    0xe48(%rip),%r14
lea    0xe4a(%rip),%rbx
xor    %ebp,%ebp
jmp    125f <main+0x11f>
nopl   0x0(%rax,%rax,1)
mulss  0xdf0(%rip),%xmm0
mulss  0xe08(%rip),%xmm0
call   1060 <floorf@plt>
movaps %xmm0,%xmm1
minss  0xdfc(%rip),%xmm1
cmpltss 0xdf7(%rip),%xmm0
andnps %xmm1,%xmm0
cvttss2si %xmm0,%esi
cmp    $0xfff,%ebp
mov    %rbx,%rdi
cmovb  %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebp
cmp    $0x1000,%ebp
je     1296 <main+0x156>
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
mulss  0xdaa(%rip),%xmm0
ucomiss 0xda7(%rip),%xmm0
jbe    1210 <main+0xd0>
movss  0xda1(%rip),%xmm1
call   1040 <powf@plt>
mulss  0xd84(%rip),%xmm0
addss  0xd90(%rip),%xmm0
jmp    1218 <main+0xd8>
lea    0xe10(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"static const float srgb_to_linear[256] =\0A\00"
@.str.1 = [3 x i8] c"{\0A\00"
@.str.2 = [9 x i8] c" %f,\0A\00"
@.str.3 = [8 x i8] c" %f\0A\00"
@.str.4 = [4 x i8] c"};\0A\00"
@.str.5 = [45 x i8] c"static const uint8_t linear_to_srgb[4096] =\0A\00"
@.str.6 = [9 x i8] c" %d,\0A\00"
@.str.7 = [8 x i8] c" %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca float
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %8
br label %11
11: ; preds = %37, %2
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 256
br i1 %13, label %14, label %40
14: ; preds = %11
%15 = load i32, i32* %8
%16 = sitofp i32 %15 to float
%17 = fdiv float %16, 2.560000e+02
store float %17, float* %6
%18 = load float, float* %6
%19 = fcmp ogt float %18, 0x3FA4B5DCC0000000
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load float, float* %6
%22 = fadd float %21, 0x3FAC28F5C0000000
%23 = fdiv float %22, 0x3FF0E147A0000000
%24 = call float @powf(float %23, float 0x4003333340000000)
br label %28
25: ; preds = %14
%26 = load float, float* %6
%27 = fdiv float %26, 0x4029D70A40000000
br label %28
28: ; preds = %25, %20
%29 = phi float [ %24, %20 ], [ %27, %25 ]
store float %29, float* %6
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 255
%32 = zext i1 %31 to i64
%33 = select i1 %31, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0)
%34 = load float, float* %6
%35 = fpext float %34 to double
%36 = call i32 (i8*, ...) @printf(i8* %33, double %35)
br label %37
37: ; preds = %28
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
br label %11
40: ; preds = %11
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0))
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %8
br label %44
44: ; preds = %85, %40
%45 = load i32, i32* %8
%46 = icmp slt i32 %45, 4096
br i1 %46, label %47, label %88
47: ; preds = %44
%48 = load i32, i32* %8
%49 = sitofp i32 %48 to float
%50 = fdiv float %49, 4.096000e+03
store float %50, float* %6
%51 = load float, float* %6
%52 = fcmp ogt float %51, 0x3F69A5C380000000
br i1 %52, label %53, label %57
53: ; preds = %47
%54 = load float, float* %6
%55 = call float @powf(float %54, float 0x3FDAAAAAA0000000)
%56 = call float @llvm.fmuladd.f32(float 0x3FF0E147A0000000, float %55, float 0xBFAC28F5C0000000)
br label %60
57: ; preds = %47
%58 = load float, float* %6
%59 = fmul float %58, 0x4029D70A40000000
br label %60
60: ; preds = %57, %53
%61 = phi float [ %56, %53 ], [ %59, %57 ]
store float %61, float* %6
%62 = load float, float* %6
%63 = fmul float %62, 2.560000e+02
%64 = call float @llvm.floor.f32(float %63)
store float %64, float* %6
%65 = load float, float* %6
%66 = fcmp olt float %65, 0.000000e+00
br i1 %66, label %67, label %68
67: ; preds = %60
br label %76
68: ; preds = %60
%69 = load float, float* %6
%70 = fcmp ole float %69, 2.550000e+02
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = load float, float* %6
br label %74
73: ; preds = %68
br label %74
74: ; preds = %73, %71
%75 = phi float [ %72, %71 ], [ 2.550000e+02, %73 ]
br label %76
76: ; preds = %74, %67
%77 = phi float [ 0.000000e+00, %67 ], [ %75, %74 ]
%78 = fptosi float %77 to i32
store i32 %78, i32* %7
%79 = load i32, i32* %8
%80 = icmp slt i32 %79, 4095
%81 = zext i1 %80 to i64
%82 = select i1 %80, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0)
%83 = load i32, i32* %7
%84 = call i32 (i8*, ...) @printf(i8* %82, i32 %83)
br label %85
85: ; preds = %76
%86 = load i32, i32* %8
%87 = add nsw i32 %86, 1
store i32 %87, i32* %8
br label %44
88: ; preds = %44
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [9 x i8] c" %f,\0A\00"
@.str.3 = [8 x i8] c" %f\0A\00"
@.str.6 = [9 x i8] c" %d,\0A\00"
@.str.7 = [8 x i8] c" %d\0A\00"
@str = [41 x i8] c"static const float srgb_to_linear[256] =\00"
@str.10 = [44 x i8] c"static const uint8_t linear_to_srgb[4096] =\00"
@str.11 = [2 x i8] c"{\00"
@str.12 = [3 x i8] c"};\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.11, i64 0, i64 0))
br label %5
5: ; preds = %2, %16
%6 = phi i32 [ 0, %2 ], [ %22, %16 ]
%7 = sitofp i32 %6 to float
%8 = fmul float %7, 3.906250e-03
%9 = fcmp ogt float %8, 0x3FA4B5DCC0000000
br i1 %9, label %10, label %14
10: ; preds = %5
%11 = fadd float %8, 0x3FAC28F5C0000000
%12 = fdiv float %11, 0x3FF0E147A0000000
%13 = tail call float @powf(float %12, float 0x4003333340000000)
br label %16
14: ; preds = %5
%15 = fdiv float %8, 0x4029D70A40000000
br label %16
16: ; preds = %14, %10
%17 = phi float [ %13, %10 ], [ %15, %14 ]
%18 = icmp ult i32 %6, 255
%19 = select i1 %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0)
%20 = fpext float %17 to double
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %19, double %20)
%22 = add nuw nsw i32 %6, 1
%23 = icmp eq i32 %22, 256
br i1 %23, label %24, label %5
24: ; preds = %16
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.12, i64 0, i64 0))
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.10, i64 0, i64 0))
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.11, i64 0, i64 0))
br label %28
28: ; preds = %24, %38
%29 = phi i32 [ 0, %24 ], [ %50, %38 ]
%30 = sitofp i32 %29 to float
%31 = fmul float %30, 0x3F30000000000000
%32 = fcmp ogt float %31, 0x3F69A5C380000000
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = tail call float @powf(float %31, float 0x3FDAAAAAA0000000)
%35 = tail call float @llvm.fmuladd.f32(float %34, float 0x3FF0E147A0000000, float 0xBFAC28F5C0000000)
br label %38
36: ; preds = %28
%37 = fmul float %31, 0x4029D70A40000000
br label %38
38: ; preds = %36, %33
%39 = phi float [ %35, %33 ], [ %37, %36 ]
%40 = fmul float %39, 2.560000e+02
%41 = tail call float @llvm.floor.f32(float %40)
%42 = fcmp olt float %41, 0.000000e+00
%43 = fcmp ole float %41, 2.550000e+02
%44 = select i1 %43, float %41, float 2.550000e+02
%45 = select i1 %42, float 0.000000e+00, float %44
%46 = fptosi float %45 to i32
%47 = icmp ult i32 %29, 4095
%48 = select i1 %47, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0)
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %48, i32 %46)
%50 = add nuw nsw i32 %29, 1
%51 = icmp eq i32 %50, 4096
br i1 %51, label %52, label %28
52: ; preds = %38
%53 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.12, i64 0, i64 0))
ret i32 0
}