#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 */
double pow(int, double);
int round(double);
int a_dither_trc(int input) {
  static int inited = 0;
  static int trc[1024];
  if (!inited) {
    int i;
    inited = 1;
    for (i = 0; i < 1024; i++)
      trc[i] = round(pow(i / 1023.0, 0.75) * 1023.999);
  }
  if (input < 0)
    input = 0;
  if (input > 1023)
    input = 1023;
  return trc[input];
}


x86 assembly (clang, -O0):
<a_dither_trc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,0x2f0e(%rip)
jne    11ac <a_dither_trc+0x8c>
movl   $0x1,0x2efe(%rip)
movl   $0x0,-0x8(%rbp)
cmpl   $0x400,-0x8(%rbp)
jge    11a7 <a_dither_trc+0x87>
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xead(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
movsd  0xe95(%rip),%xmm0
call   1030 <pow@plt>
movsd  0xe80(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1040 <round@plt>
mov    %eax,%edx
movslq -0x8(%rbp),%rcx
lea    0x2eba(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1149 <a_dither_trc+0x29>
jmp    11ac <a_dither_trc+0x8c>
cmpl   $0x0,-0x4(%rbp)
jge    11bd <a_dither_trc+0x9d>
movl   $0x0,-0x4(%rbp)
cmpl   $0x3ff,-0x4(%rbp)
jle    11d1 <a_dither_trc+0xb1>
movl   $0x3ff,-0x4(%rbp)
movslq -0x4(%rbp),%rcx
lea    0x2e74(%rip),%rax
mov    (%rax,%rcx,4),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<a_dither_trc>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
cmpb   $0x0,0x2f12(%rip)
jne    11ca <a_dither_trc+0xaa>
movb   $0x1,0x2f05(%rip)
xor    %ebx,%ebx
lea    0x2f0c(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  0xea1(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
movsd  0xe99(%rip),%xmm0
call   1030 <pow@plt>
movsd  0xe94(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1040 <round@plt>
lea    0x1(%rbx),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mov    %eax,0x0(%rbp,%rbx,4)
divsd  0xe65(%rip),%xmm0
cvttsd2si %xmm0,%edi
movsd  0xe61(%rip),%xmm0
call   1030 <pow@plt>
mulsd  0xe5c(%rip),%xmm0
call   1040 <round@plt>
mov    %eax,0x4(%rbp,%rbx,4)
add    $0x2,%rbx
cmp    $0x400,%rbx
jne    1150 <a_dither_trc+0x30>
xor    %eax,%eax
test   %r14d,%r14d
cmovns %r14d,%eax
cmp    $0x3ff,%eax
mov    $0x3ff,%ecx
cmovb  %eax,%ecx
lea    0x2e69(%rip),%rax
mov    (%rax,%rcx,4),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@a_dither_trc.inited = internal global i32 0
@a_dither_trc.trc = internal global [1024 x i32] zeroinitializer
define i32 @a_dither_trc(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* @a_dither_trc.inited
%5 = icmp ne i32 %4, 0
br i1 %5, label %25, label %6
6: ; preds = %1
store i32 1, i32* @a_dither_trc.inited
store i32 0, i32* %3
br label %7
7: ; preds = %21, %6
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 1024
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = load i32, i32* %3
%12 = sitofp i32 %11 to double
%13 = fdiv double %12, 1.023000e+03
%14 = fptosi double %13 to i32
%15 = call double @pow(i32 %14, double 7.500000e-01)
%16 = fmul double %15, 0x408FFFFDF3B645A2
%17 = call i32 @round(double %16)
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [1024 x i32], [1024 x i32]* @a_dither_trc.trc, i64 0, i64 %19
store i32 %17, i32* %20
br label %21
21: ; preds = %10
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %7
24: ; preds = %7
br label %25
25: ; preds = %24, %1
%26 = load i32, i32* %2
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 0, i32* %2
br label %29
29: ; preds = %28, %25
%30 = load i32, i32* %2
%31 = icmp sgt i32 %30, 1023
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 1023, i32* %2
br label %33
33: ; preds = %32, %29
%34 = load i32, i32* %2
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [1024 x i32], [1024 x i32]* @a_dither_trc.trc, i64 0, i64 %35
%37 = load i32, i32* %36
ret i32 %37
}

LLVM IR (-O2):
@a_dither_trc.inited = internal unnamed_addr global i1 false
@a_dither_trc.trc = internal unnamed_addr global [1024 x i32] zeroinitializer
define i32 @a_dither_trc(i32 %0) {
%2 = load i1, i1* @a_dither_trc.inited
br i1 %2, label %25, label %3
3: ; preds = %1
store i1 true, i1* @a_dither_trc.inited
br label %4
4: ; preds = %4, %3
%5 = phi i64 [ 0, %3 ], [ %23, %4 ]
%6 = trunc i64 %5 to i32
%7 = sitofp i32 %6 to double
%8 = fdiv double %7, 1.023000e+03
%9 = fptosi double %8 to i32
%10 = tail call double @pow(i32 %9, double 7.500000e-01)
%11 = fmul double %10, 0x408FFFFDF3B645A2
%12 = tail call i32 @round(double %11)
%13 = getelementptr inbounds [1024 x i32], [1024 x i32]* @a_dither_trc.trc, i64 0, i64 %5
store i32 %12, i32* %13
%14 = or i64 %5, 1
%15 = trunc i64 %14 to i32
%16 = sitofp i32 %15 to double
%17 = fdiv double %16, 1.023000e+03
%18 = fptosi double %17 to i32
%19 = tail call double @pow(i32 %18, double 7.500000e-01)
%20 = fmul double %19, 0x408FFFFDF3B645A2
%21 = tail call i32 @round(double %20)
%22 = getelementptr inbounds [1024 x i32], [1024 x i32]* @a_dither_trc.trc, i64 0, i64 %14
store i32 %21, i32* %22
%23 = add nuw nsw i64 %5, 2
%24 = icmp eq i64 %23, 1024
br i1 %24, label %25, label %4
25: ; preds = %4, %1
%26 = icmp sgt i32 %0, 0
%27 = select i1 %26, i32 %0, i32 0
%28 = icmp ult i32 %27, 1023
%29 = select i1 %28, i32 %27, i32 1023
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds [1024 x i32], [1024 x i32]* @a_dither_trc.trc, i64 0, i64 %30
%32 = load i32, i32* %31
ret i32 %32
}