#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*/ build_crc_table(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int i, sztbl;
  FILE *tf;
  if (argc < 2) {
    printf("Use %s file-to-create\n", argv[0]);
    return (-1);
  }
  sztbl = 256;
  if (argc > 2) {
    sztbl = strtol(argv[2], NULL, 0);
  }
  if (!(sztbl == 256) && !(sztbl == 65536)) {
    printf("Invalid table size 256 or 65536\n");
    return (-1);
  }
  printf("\nGenerating CRC-32c table file <%s> size %d\n", argv[1], sztbl);
  if ((tf = fopen(argv[1], "w")) == NULL) {
    printf("Unable to open %s\n", argv[1]);
    return (-1);
  }
  fprintf(tf, "\nunsigned long  crc_c[%d] =\n{\n", sztbl);
  for (i = 0; i < sztbl; i++) {
    fprintf(tf, "0x%08lXL, ", build_crc_table(i));
    if ((i & 3) == 3)
      fprintf(tf, "\n");
  }
  fprintf(tf, "};\n\n#endif\n");
  fclose(tf);
  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)
cmpl   $0x2,-0x8(%rbp)
jge    11a1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12fb <main+0x19b>
movl   $0x100,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11c8 <main+0x68>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x100,-0x18(%rbp)
je     11fc <main+0x9c>
cmpl   $0x10000,-0x18(%rbp)
je     11fc <main+0x9c>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12fb <main+0x19b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x18(%rbp),%edx
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe41(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1259 <main+0xf9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12fb <main+0x19b>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12d9 <main+0x179>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <build_crc_table@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xdfb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%eax
and    $0x3,%eax
cmp    $0x3,%eax
jne    12c6 <main+0x166>
mov    -0x20(%rbp),%rdi
lea    0xd77(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12cb <main+0x16b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1275 <main+0x115>
mov    -0x20(%rbp),%rdi
lea    0xdc0(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x1,%edi
jg     11ae <main+0x1e>
mov    (%r14),%rsi
lea    0xe57(%rip),%rdi
jmp    1295 <main+0x105>
mov    $0x100,%r15d
cmp    $0x2,%edi
je     11dd <main+0x4d>
mov    0x10(%r14),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <strtol@plt>
mov    %eax,%r15d
cmp    $0x100,%eax
je     11dd <main+0x4d>
cmp    $0x10000,%r15d
jne    12ac <main+0x11c>
mov    0x8(%r14),%rsi
lea    0xe2f(%rip),%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r14),%rdi
lea    0xe47(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     128a <main+0xfa>
mov    %rax,%rbx
lea    0xe44(%rip),%rsi
mov    %rax,%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xe4f(%rip),%r14
xor    %ebp,%ebp
jmp    1238 <main+0xa8>
nopl   (%rax)
add    $0x1,%ebp
cmp    %ebp,%r15d
je     1265 <main+0xd5>
mov    %ebp,%edi
call   10b0 <build_crc_table@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %ebp,%eax
not    %eax
test   $0x3,%al
jne    1230 <main+0xa0>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
jmp    1230 <main+0xa0>
lea    0xe17(%rip),%rdi
mov    $0xb,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    12a1 <main+0x111>
mov    0x8(%r14),%rsi
lea    0xdb1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xddc(%rip),%rdi
call   1030 <puts@plt>
jmp    129c <main+0x10c>

LLVM IR (-O0):
@.str = [23 x i8] c"Use %s file-to-create\0A\00"
@.str.1 = [33 x i8] c"Invalid table size 256 or 65536\0A\00"
@.str.2 = [45 x i8] c"\0AGenerating CRC-32c table file <%s> size %d\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [19 x i8] c"Unable to open %s\0A\00"
@.str.5 = [31 x i8] c"\0Aunsigned long crc_c[%d] =\0A{\0A\00"
@.str.6 = [11 x i8] c"0x%08lXL, \00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [12 x i8] c"};\0A\0A#endif\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 -1, i32* %3
br label %76
16: ; preds = %2
store i32 256, i32* %7
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 2
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @strtol(i8* %22, i32* null, i32 0)
store i32 %23, i32* %7
br label %24
24: ; preds = %19, %16
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, 256
br i1 %26, label %32, label %27
27: ; preds = %24
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, 65536
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %76
32: ; preds = %27, %24
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = load i32, i32* %7
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %35, i32 %36)
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %41, i32** %8
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %48
43: ; preds = %32
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %46)
store i32 -1, i32* %3
br label %76
48: ; preds = %32
%49 = load i32*, i32** %8
%50 = load i32, i32* %7
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %50)
store i32 0, i32* %6
br label %52
52: ; preds = %68, %48
%53 = load i32, i32* %6
%54 = load i32, i32* %7
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %71
56: ; preds = %52
%57 = load i32*, i32** %8
%58 = load i32, i32* %6
%59 = call i32 @build_crc_table(i32 %58)
%60 = call i32 (i32*, i8*, ...) @fprintf(i32* %57, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %59)
%61 = load i32, i32* %6
%62 = and i32 %61, 3
%63 = icmp eq i32 %62, 3
br i1 %63, label %64, label %67
64: ; preds = %56
%65 = load i32*, i32** %8
%66 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %67
67: ; preds = %64, %56
br label %68
68: ; preds = %67
%69 = load i32, i32* %6
%70 = add nsw i32 %69, 1
store i32 %70, i32* %6
br label %52
71: ; preds = %52
%72 = load i32*, i32** %8
%73 = call i32 (i32*, i8*, ...) @fprintf(i32* %72, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%74 = load i32*, i32** %8
%75 = call i32 @fclose(i32* %74)
store i32 0, i32* %3
br label %76
76: ; preds = %71, %43, %30, %11
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@.str = [23 x i8] c"Use %s file-to-create\0A\00"
@.str.2 = [45 x i8] c"\0AGenerating CRC-32c table file <%s> size %d\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [19 x i8] c"Unable to open %s\0A\00"
@.str.5 = [31 x i8] c"\0Aunsigned long crc_c[%d] =\0A{\0A\00"
@.str.6 = [11 x i8] c"0x%08lXL, \00"
@.str.8 = [12 x i8] c"};\0A\0A#endif\0A\00"
@str = [32 x i8] c"Invalid table size 256 or 65536\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %42
7: ; preds = %2
%8 = icmp eq i32 %0, 2
br i1 %8, label %15, label %9
9: ; preds = %7
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @strtol(i8* nocapture %11, i32* null, i32 0)
switch i32 %12, label %13 [
i32 65536, label %15
i32 256, label %15
]
13: ; preds = %9
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %42
15: ; preds = %7, %9, %9
%16 = phi i32 [ %12, %9 ], [ %12, %9 ], [ 256, %7 ]
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %18, i32 %16)
%20 = load i8*, i8** %17
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = load i8*, i8** %17
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %24)
br label %42
26: ; preds = %15
%27 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %16)
br label %28
28: ; preds = %26, %36
%29 = phi i32 [ %37, %36 ], [ 0, %26 ]
%30 = tail call i32 @build_crc_table(i32 %29)
%31 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %30)
%32 = and i32 %29, 3
%33 = icmp eq i32 %32, 3
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = tail call i32 @fputc(i32 10, i32* %21)
br label %36
36: ; preds = %28, %34
%37 = add nuw nsw i32 %29, 1
%38 = icmp eq i32 %37, %16
br i1 %38, label %39, label %28
39: ; preds = %36
%40 = tail call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i64 11, i64 1, i32* %21)
%41 = tail call i32 @fclose(i32* %21)
br label %42
42: ; preds = %39, %23, %13, %4
%43 = phi i32 [ -1, %4 ], [ -1, %23 ], [ 0, %39 ], [ -1, %13 ]
ret i32 %43
}