#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ BsiGenerateTables(int /*<<< orphan*/ *, char *, double, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
int main(int argc, char *argv[]) {
  FILE *output;
  ;
  if (argc > 2) {
    fprintf(stderr, "Usage: %s [output file]\n", argv[0]);
    return 1;
  }
  if (argc == 2) {
    output = fopen(argv[1], "wb");
    if (!output) {
      fprintf(stderr, "Failed to open %s for writing\n", argv[1]);
      return 1;
    }
  } else
    output = stdout;
  fprintf(
      output,
      "/* Generated by bsincgen, do not edit! */\n\n"
      "static_assert(BSINC_SCALE_COUNT == %d, \"Unexpected BSINC_SCALE_COUNT "
      "value!\");\n"
      "static_assert(BSINC_PHASE_COUNT == %d, \"Unexpected BSINC_PHASE_COUNT "
      "value!\");\n"
      "static_assert(FRACTIONONE == %d, \"Unexpected FRACTIONONE value!\");\n\n"
      "typedef struct BSincTable {\n"
      "    const float scaleBase, scaleRange;\n"
      "    const int m[BSINC_SCALE_COUNT];\n"
      "    const int filterOffset[BSINC_SCALE_COUNT];\n"
      "    alignas(16) const float Tab[];\n"
      "} BSincTable;\n\n",
      (16), (16), (1 << (12)));
  BsiGenerateTables(output, "bsinc24", 60.0, 23);
  BsiGenerateTables(output, "bsinc12", 40.0, 11);
  if (output != stdout)
    fclose(output);
  output = NULL;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    118b <main+0x4b>
mov    0x2e79(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe98(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    127c <main+0x13c>
cmpl   $0x2,-0x8(%rbp)
jne    11e9 <main+0xa9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe85(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e4 <main+0xa4>
mov    0x2e21(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    127c <main+0x13c>
jmp    11f7 <main+0xb7>
mov    0x2de8(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe49(%rip),%rsi
mov    $0x10,%ecx
mov    $0x1000,%r8d
mov    %ecx,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0x1000(%rip),%rsi
movsd  0xddf(%rip),%xmm0
mov    $0x17,%edx
call   1030 <BsiGenerateTables@plt>
mov    -0x18(%rbp),%rdi
lea    0xfeb(%rip),%rsi
movsd  0xdba(%rip),%xmm0
mov    $0xb,%edx
call   1030 <BsiGenerateTables@plt>
mov    -0x18(%rbp),%rax
mov    0x2d7d(%rip),%rcx
cmp    (%rcx),%rax
je     126d <main+0x12d>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbp
cmp    $0x3,%edi
jl     1171 <main+0x31>
mov    0x2e8e(%rip),%rax
movslq (%rax),%rdi
mov    0x0(%rbp),%rdx
lea    0xeb0(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%ebp
jmp    121e <main+0xde>
cmp    $0x2,%edi
jne    11a5 <main+0x65>
mov    0x8(%rbp),%rdi
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11af <main+0x6f>
mov    0x2e4b(%rip),%rax
movslq (%rax),%rdi
mov    0x8(%rbp),%rdx
lea    0xe89(%rip),%rsi
jmp    1160 <main+0x20>
mov    0x2e2c(%rip),%rax
mov    (%rax),%rbx
lea    0xe95(%rip),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    $0x10,%edx
mov    $0x10,%ecx
mov    $0x1000,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0x1048(%rip),%rsi
movsd  0xe1f(%rip),%xmm0
mov    %rbx,%rdi
mov    $0x17,%edx
call   1030 <BsiGenerateTables@plt>
lea    0x1034(%rip),%rsi
movsd  0xe0b(%rip),%xmm0
mov    %rbx,%rdi
mov    $0xb,%edx
call   1030 <BsiGenerateTables@plt>
mov    0x2dc7(%rip),%rax
cmp    (%rax),%rbx
je     121e <main+0xde>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"Usage: %s [output file]\0A\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [31 x i8] c"Failed to open %s for writing\0A\00"
@stdout = global i32* null
@.str.3 = [470 x i8] c"/* Generated by bsincgen, do not edit! */\0A\0Astatic_assert(BSINC_SCALE_COUNT == %d, \22Unexpected BSINC_SCALE_COUNT value!\22);\0Astatic_assert(BSINC_PHASE_COUNT == %d, \22Unexpected BSINC_PHASE_COUNT value!\22);\0Astatic_assert(FRACTIONONE == %d, \22Unexpected FRACTIONONE value!\22);\0A\0Atypedef struct BSincTable {\0A const float scaleBase, scaleRange;\0A const int m[BSINC_SCALE_COUNT];\0A const int filterOffset[BSINC_SCALE_COUNT];\0A alignas(16) const float Tab[];\0A} BSincTable;\0A\0A\00"
@.str.4 = [8 x i8] c"bsinc24\00"
@.str.5 = [8 x i8] c"bsinc12\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 2
br i1 %8, label %9, label %17
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i32*
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %52
17: ; preds = %2
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %36
20: ; preds = %17
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = icmp ne i32* %25, null
br i1 %26, label %35, label %27
27: ; preds = %20
%28 = load i32, i32* @stderr
%29 = sext i32 %28 to i64
%30 = inttoptr i64 %29 to i32*
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %33)
store i32 1, i32* %3
br label %52
35: ; preds = %20
br label %38
36: ; preds = %17
%37 = load i32*, i32** @stdout
store i32* %37, i32** %6
br label %38
38: ; preds = %36, %35
%39 = load i32*, i32** %6
%40 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([470 x i8], [470 x i8]* @.str.3, i64 0, i64 0), i32 16, i32 16, i32 4096)
%41 = load i32*, i32** %6
%42 = call i32 @BsiGenerateTables(i32* %41, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double 6.000000e+01, i32 23)
%43 = load i32*, i32** %6
%44 = call i32 @BsiGenerateTables(i32* %43, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), double 4.000000e+01, i32 11)
%45 = load i32*, i32** %6
%46 = load i32*, i32** @stdout
%47 = icmp ne i32* %45, %46
br i1 %47, label %48, label %51
48: ; preds = %38
%49 = load i32*, i32** %6
%50 = call i32 @fclose(i32* %49)
br label %51
51: ; preds = %48, %38
store i32* null, i32** %6
store i32 0, i32* %3
br label %52
52: ; preds = %51, %27, %9
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"Usage: %s [output file]\0A\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [31 x i8] c"Failed to open %s for writing\0A\00"
@stdout = global i32* null
@.str.3 = [470 x i8] c"/* Generated by bsincgen, do not edit! */\0A\0Astatic_assert(BSINC_SCALE_COUNT == %d, \22Unexpected BSINC_SCALE_COUNT value!\22);\0Astatic_assert(BSINC_PHASE_COUNT == %d, \22Unexpected BSINC_PHASE_COUNT value!\22);\0Astatic_assert(FRACTIONONE == %d, \22Unexpected FRACTIONONE value!\22);\0A\0Atypedef struct BSincTable {\0A const float scaleBase, scaleRange;\0A const int m[BSINC_SCALE_COUNT];\0A const int filterOffset[BSINC_SCALE_COUNT];\0A alignas(16) const float Tab[];\0A} BSincTable;\0A\0A\00"
@.str.4 = [8 x i8] c"bsinc24\00"
@.str.5 = [8 x i8] c"bsinc12\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 2
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i32*
%8 = load i8*, i8** %1
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %34
10: ; preds = %2
%11 = icmp eq i32 %0, 2
br i1 %11, label %12, label %23
12: ; preds = %10
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %25
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i32*
%21 = load i8*, i8** %13
%22 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %34
23: ; preds = %10
%24 = load i32*, i32** @stdout
br label %25
25: ; preds = %12, %23
%26 = phi i32* [ %15, %12 ], [ %24, %23 ]
%27 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([470 x i8], [470 x i8]* @.str.3, i64 0, i64 0), i32 16, i32 16, i32 4096)
%28 = tail call i32 @BsiGenerateTables(i32* %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), double 6.000000e+01, i32 23)
%29 = tail call i32 @BsiGenerateTables(i32* %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), double 4.000000e+01, i32 11)
%30 = load i32*, i32** @stdout
%31 = icmp eq i32* %26, %30
br i1 %31, label %34, label %32
32: ; preds = %25
%33 = tail call i32 @fclose(i32* %26)
br label %34
34: ; preds = %25, %32, %17, %4
%35 = phi i32 [ 1, %4 ], [ 1, %17 ], [ 0, %32 ], [ 0, %25 ]
ret i32 %35
}