#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 exp(float const);
int /*<<< orphan*/ printf(char *, ...);
int const round(int const);
int main() {
  const int brightMax = 255;
  const float logSkal = 4;
  const int pwmMin = 0;
  const int pwmMax = 255;
  const int pwmStep = 1;
  const int brightScale = 1;
  int pwmForBrightness[brightMax + 1];
  printf("const uint8_t pwmtable[%d] = {", brightMax + 1);
  int first = 1;
  for (int bright = 0; bright <= brightMax; bright++) {
    int pwmOut =
        pwmMin +
        round((pwmMax - pwmMin) *
              ((exp((bright * logSkal) / brightMax) - 1) / (exp(logSkal) - 1)));
    pwmForBrightness[bright] = pwmOut;
    if (!first)
      printf(", ");
    first = 0;
    printf("%d", pwmOut);
  }
  printf("};\n");
  printf("const uint8_t brightnesstable[%d] = {",
         (pwmMax - pwmMin + 1) / pwmStep);
  first = 1;
  for (int pwmIn = pwmMin; pwmIn <= pwmMax; pwmIn += pwmStep) {
    int bright = 0;
    for (bright = 0; bright <= brightMax; bright++) {
      if (pwmForBrightness[bright] >= pwmIn) {
        break;
      }
    }
    if (!first)
      printf(", ");
    first = 0;
    printf("%d", bright * brightScale);
  }
  printf("};\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xff,-0x8(%rbp)
movss  0xeaf(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0xff,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    %rsp,%rax
mov    %rax,-0x28(%rbp)
lea    0xe88(%rip),%rdi
mov    $0x100,%esi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0xff,-0x30(%rbp)
jg     124a <main+0x11a>
cvtsi2ssl -0x30(%rbp),%xmm0
movss  0xe4c(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe44(%rip),%xmm1
divss  %xmm1,%xmm0
call   1040 <exp@plt>
sub    $0x1,%eax
mov    %eax,-0x444(%rbp)
movss  0xe26(%rip),%xmm0
call   1040 <exp@plt>
mov    %eax,%ecx
mov    -0x444(%rbp),%eax
sub    $0x1,%ecx
cltd
idiv   %ecx
imul   $0xff,%eax,%edi
call   1050 <round@plt>
add    $0x0,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%ecx
movslq -0x30(%rbp),%rax
mov    %ecx,-0x440(%rbp,%rax,4)
cmpl   $0x0,-0x2c(%rbp)
jne    1224 <main+0xf4>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x34(%rbp),%esi
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    119a <main+0x6a>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdd2(%rip),%rdi
mov    $0x100,%esi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x2c(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0xff,-0x38(%rbp)
jg     130e <main+0x1de>
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0xff,-0x3c(%rbp)
jg     12cd <main+0x19d>
movslq -0x3c(%rbp),%rax
mov    -0x440(%rbp,%rax,4),%eax
cmp    -0x38(%rbp),%eax
jl     12ba <main+0x18a>
jmp    12cd <main+0x19d>
jmp    12bf <main+0x18f>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1294 <main+0x164>
cmpl   $0x0,-0x2c(%rbp)
jne    12e5 <main+0x1b5>
lea    0xd49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x3c(%rbp),%esi
shl    $0x0,%esi
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1279 <main+0x149>
lea    0xd18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
lea    0xeb4(%rip),%rdi
mov    $0x100,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
call   1050 <exp@plt>
mov    %eax,%ebx
add    $0xffffffff,%ebx
movss  0xe8b(%rip),%xmm0
call   1050 <exp@plt>
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %eax,%edi
shl    $0x8,%edi
sub    %eax,%edi
call   1060 <round@plt>
mov    %eax,(%rsp)
lea    0xe90(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebx
lea    0xe75(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
movss  0xe31(%rip),%xmm1
mulss  %xmm1,%xmm0
divss  0xe29(%rip),%xmm0
call   1050 <exp@plt>
mov    %eax,%ebp
add    $0xffffffff,%ebp
movss  0xe13(%rip),%xmm0
call   1050 <exp@plt>
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %eax,%edi
shl    $0x8,%edi
sub    %eax,%edi
call   1060 <round@plt>
mov    %eax,%ebp
mov    %eax,(%rsp,%rbx,4)
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0x100,%rbx
jne    11c0 <main+0x80>
lea    0xe1c(%rip),%rdi
call   1030 <puts@plt>
lea    0xdea(%rip),%rdi
mov    $0x100,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdd1(%rip),%r14
lea    0xdcd(%rip),%r15
xor    %ebp,%ebp
xor    %eax,%eax
jmp    1289 <main+0x149>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
mov    $0x1,%al
cmp    $0x100,%ebp
je     12fe <main+0x1be>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
cmp    %ebp,(%rsp,%rbx,4)
jge    12e0 <main+0x1a0>
cmp    %ebp,0x4(%rsp,%rbx,4)
jge    12c0 <main+0x180>
cmp    %ebp,0x8(%rsp,%rbx,4)
jge    12d0 <main+0x190>
cmp    %ebp,0xc(%rsp,%rbx,4)
jge    12f0 <main+0x1b0>
add    $0x4,%rbx
cmp    $0x100,%rbx
jne    1290 <main+0x150>
mov    $0x100,%ebx
test   $0x1,%al
je     1270 <main+0x130>
jmp    12e4 <main+0x1a4>
nop
add    $0x1,%rbx
test   $0x1,%al
je     1270 <main+0x130>
jmp    12e4 <main+0x1a4>
nopw   0x0(%rax,%rax,1)
add    $0x2,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   $0x1,%al
je     1270 <main+0x130>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1270 <main+0x130>
add    $0x3,%rbx
test   $0x1,%al
je     1270 <main+0x130>
jmp    12e4 <main+0x1a4>
lea    0xd4e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"const uint8_t pwmtable[%d] = {\00"
@.str.1 = [3 x i8] c", \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"};\0A\00"
@.str.4 = [38 x i8] c"const uint8_t brightnesstable[%d] = {\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %1
store i32 255, i32* %2
store float 4.000000e+00, float* %3
store i32 0, i32* %4
store i32 255, i32* %5
store i32 1, i32* %6
store i32 1, i32* %7
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %8
%15 = alloca i32, i64 256
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 256)
store i32 1, i32* %9
store i32 0, i32* %10
br label %17
17: ; preds = %44, %0
%18 = load i32, i32* %10
%19 = icmp sle i32 %18, 255
br i1 %19, label %20, label %47
20: ; preds = %17
%21 = load i32, i32* %10
%22 = sitofp i32 %21 to float
%23 = fmul float %22, 4.000000e+00
%24 = fdiv float %23, 2.550000e+02
%25 = call i32 @exp(float %24)
%26 = sub nsw i32 %25, 1
%27 = call i32 @exp(float 4.000000e+00)
%28 = sub nsw i32 %27, 1
%29 = sdiv i32 %26, %28
%30 = mul nsw i32 255, %29
%31 = call i32 @round(i32 %30)
%32 = add nsw i32 0, %31
store i32 %32, i32* %11
%33 = load i32, i32* %11
%34 = load i32, i32* %10
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %15, i64 %35
store i32 %33, i32* %36
%37 = load i32, i32* %9
%38 = icmp ne i32 %37, 0
br i1 %38, label %41, label %39
39: ; preds = %20
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %41
41: ; preds = %39, %20
store i32 0, i32* %9
%42 = load i32, i32* %11
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %41
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
store i32 %46, i32* %10
br label %17
47: ; preds = %17
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 256)
store i32 1, i32* %9
store i32 0, i32* %12
br label %50
50: ; preds = %78, %47
%51 = load i32, i32* %12
%52 = icmp sle i32 %51, 255
br i1 %52, label %53, label %81
53: ; preds = %50
store i32 0, i32* %13
store i32 0, i32* %13
br label %54
54: ; preds = %66, %53
%55 = load i32, i32* %13
%56 = icmp sle i32 %55, 255
br i1 %56, label %57, label %69
57: ; preds = %54
%58 = load i32, i32* %13
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %15, i64 %59
%61 = load i32, i32* %60
%62 = load i32, i32* %12
%63 = icmp sge i32 %61, %62
br i1 %63, label %64, label %65
64: ; preds = %57
br label %69
65: ; preds = %57
br label %66
66: ; preds = %65
%67 = load i32, i32* %13
%68 = add nsw i32 %67, 1
store i32 %68, i32* %13
br label %54
69: ; preds = %64, %54
%70 = load i32, i32* %9
%71 = icmp ne i32 %70, 0
br i1 %71, label %74, label %72
72: ; preds = %69
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %74
74: ; preds = %72, %69
store i32 0, i32* %9
%75 = load i32, i32* %13
%76 = mul nsw i32 %75, 1
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %76)
br label %78
78: ; preds = %74
%79 = load i32, i32* %12
%80 = add nsw i32 %79, 1
store i32 %80, i32* %12
br label %50
81: ; preds = %50
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%83 = load i8*, i8** %8
%84 = load i32, i32* %1
ret i32 %84
}

LLVM IR (-O2):
@.str = [31 x i8] c"const uint8_t pwmtable[%d] = {\00"
@.str.1 = [3 x i8] c", \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.4 = [38 x i8] c"const uint8_t brightnesstable[%d] = {\00"
@str.5 = [3 x i8] c"};\00"
define i32 @main() {
%1 = alloca [256 x i32]
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 256)
%3 = tail call i32 @exp(float 0.000000e+00)
%4 = add nsw i32 %3, -1
%5 = tail call i32 @exp(float 4.000000e+00)
%6 = add nsw i32 %5, -1
%7 = sdiv i32 %4, %6
%8 = mul nsw i32 %7, 255
%9 = tail call i32 @round(i32 %8)
%10 = getelementptr inbounds [256 x i32], [256 x i32]* %1, i64 0, i64 0
store i32 %9, i32* %10
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %9)
br label %15
12: ; preds = %15
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.5, i64 0, i64 0))
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 256)
br label %33
15: ; preds = %0, %15
%16 = phi i64 [ 1, %0 ], [ %31, %15 ]
%17 = trunc i64 %16 to i32
%18 = sitofp i32 %17 to float
%19 = fmul float %18, 4.000000e+00
%20 = fdiv float %19, 2.550000e+02
%21 = tail call i32 @exp(float %20)
%22 = add nsw i32 %21, -1
%23 = tail call i32 @exp(float 4.000000e+00)
%24 = add nsw i32 %23, -1
%25 = sdiv i32 %22, %24
%26 = mul nsw i32 %25, 255
%27 = tail call i32 @round(i32 %26)
%28 = getelementptr inbounds [256 x i32], [256 x i32]* %1, i64 0, i64 %16
store i32 %27, i32* %28
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%31 = add nuw nsw i64 %16, 1
%32 = icmp eq i64 %31, 256
br i1 %32, label %12, label %15
33: ; preds = %12, %68
%34 = phi i32 [ 0, %12 ], [ %70, %68 ]
%35 = phi i1 [ false, %12 ], [ true, %68 ]
br label %38
36: ; preds = %68
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.5, i64 0, i64 0))
ret i32 0
38: ; preds = %58, %33
%39 = phi i64 [ 0, %33 ], [ %59, %58 ]
%40 = getelementptr inbounds [256 x i32], [256 x i32]* %1, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = icmp slt i32 %41, %34
br i1 %42, label %43, label %61
43: ; preds = %38
%44 = or i64 %39, 1
%45 = getelementptr inbounds [256 x i32], [256 x i32]* %1, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = icmp slt i32 %46, %34
br i1 %47, label %48, label %61
48: ; preds = %43
%49 = or i64 %39, 2
%50 = getelementptr inbounds [256 x i32], [256 x i32]* %1, i64 0, i64 %49
%51 = load i32, i32* %50
%52 = icmp slt i32 %51, %34
br i1 %52, label %53, label %61
53: ; preds = %48
%54 = or i64 %39, 3
%55 = getelementptr inbounds [256 x i32], [256 x i32]* %1, i64 0, i64 %54
%56 = load i32, i32* %55
%57 = icmp slt i32 %56, %34
br i1 %57, label %58, label %61
58: ; preds = %53
%59 = add nuw nsw i64 %39, 4
%60 = icmp eq i64 %59, 256
br i1 %60, label %64, label %38
61: ; preds = %53, %48, %43, %38
%62 = phi i64 [ %39, %38 ], [ %44, %43 ], [ %49, %48 ], [ %54, %53 ]
%63 = trunc i64 %62 to i32
br label %64
64: ; preds = %58, %61
%65 = phi i32 [ %63, %61 ], [ 256, %58 ]
br i1 %35, label %66, label %68
66: ; preds = %64
%67 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %68
68: ; preds = %66, %64
%69 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %65)
%70 = add nuw nsw i32 %34, 1
%71 = icmp eq i32 %70, 256
br i1 %71, label %36, label %33
}