#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned int *, int, int, int /*<<< orphan*/ *);
void writebits() {
  unsigned int bitNums[512];
  for (unsigned int i = 0; i < 512; i++)
    bitNums[i] = i * i - i;
  FILE *bNums = fopen("xdata.bin", "wb");
  fwrite(bitNums, sizeof(int), 512, bNums);
  fclose(bNums);
  FILE *checkSize = fopen("xdata.bin", "rb");
  int bytecount;
  char curr = 0;
  for (bytecount = 0; curr != EOF; bytecount++)
    fread(&curr, sizeof(char), 1, checkSize);
  fclose(checkSize);
}


x86 assembly (clang, -O0):
<writebits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x804(%rbp)
cmpl   $0x200,-0x804(%rbp)
jae    1199 <writebits+0x59>
mov    -0x804(%rbp),%ecx
imul   -0x804(%rbp),%ecx
sub    -0x804(%rbp),%ecx
mov    -0x804(%rbp),%eax
mov    %ecx,-0x800(%rbp,%rax,4)
mov    -0x804(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x804(%rbp)
jmp    1155 <writebits+0x15>
lea    0xe60(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x810(%rbp)
lea    -0x800(%rbp),%rdi
mov    -0x810(%rbp),%rcx
mov    $0x4,%esi
mov    $0x200,%edx
call   1060 <fwrite@plt>
mov    -0x810(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe1d(%rip),%rdi
lea    0xe23(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x818(%rbp)
movb   $0x0,-0x81d(%rbp)
movl   $0x0,-0x81c(%rbp)
movsbl -0x81d(%rbp),%eax
mov    0x2dd3(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     124e <writebits+0x10e>
mov    -0x818(%rbp),%rcx
lea    -0x81d(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x81c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x81c(%rbp)
jmp    1207 <writebits+0xc7>
mov    -0x818(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writebits>:
push   %r15
push   %r14
push   %rbx
sub    $0x810,%rsp
movdqa 0xeac(%rip),%xmm0
xor    %eax,%eax
movdqa 0xeb1(%rip),%xmm8
movdqa 0xeb8(%rip),%xmm9
movdqa 0xec0(%rip),%xmm3
movdqa 0xec8(%rip),%xmm4
nopl   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm5
paddd  %xmm8,%xmm5
movdqa %xmm0,%xmm6
pmuludq %xmm0,%xmm6
pshufd $0xe8,%xmm6,%xmm6
pshufd $0xf5,%xmm0,%xmm7
pmuludq %xmm7,%xmm7
pshufd $0xe8,%xmm7,%xmm7
punpckldq %xmm7,%xmm6
movdqa %xmm5,%xmm7
pmuludq %xmm5,%xmm7
pshufd $0xe8,%xmm7,%xmm7
pshufd $0xf5,%xmm5,%xmm1
pmuludq %xmm1,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm7
psubd  %xmm0,%xmm6
psubd  %xmm5,%xmm7
movdqa %xmm6,0x10(%rsp,%rax,4)
movdqa %xmm7,0x20(%rsp,%rax,4)
movdqa %xmm0,%xmm1
paddd  %xmm9,%xmm1
movdqa %xmm0,%xmm5
paddd  %xmm3,%xmm5
movdqa %xmm1,%xmm6
pmuludq %xmm1,%xmm6
pshufd $0xe8,%xmm6,%xmm6
pshufd $0xf5,%xmm1,%xmm7
pmuludq %xmm7,%xmm7
pshufd $0xe8,%xmm7,%xmm7
punpckldq %xmm7,%xmm6
movdqa %xmm5,%xmm7
pmuludq %xmm5,%xmm7
pshufd $0xe8,%xmm7,%xmm7
pshufd $0xf5,%xmm5,%xmm2
pmuludq %xmm2,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm7
psubd  %xmm1,%xmm6
psubd  %xmm5,%xmm7
movdqa %xmm6,0x30(%rsp,%rax,4)
movdqa %xmm7,0x40(%rsp,%rax,4)
add    $0x10,%rax
paddd  %xmm4,%xmm0
cmp    $0x200,%rax
jne    1180 <writebits+0x40>
lea    0xdf7(%rip),%r14
lea    0xdfa(%rip),%rsi
mov    %r14,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x4,%esi
mov    $0x200,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xdcc(%rip),%rsi
mov    %r14,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
movb   $0x0,0xf(%rsp)
mov    0x2d40(%rip),%r15
cmpb   $0x0,(%r15)
je     12df <writebits+0x19f>
lea    0xf(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
movzbl 0xf(%rsp),%eax
cmp    (%r15),%al
jne    12c0 <writebits+0x180>
mov    %rbx,%rdi
add    $0x810,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"xdata.bin\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [3 x i8] c"rb\00"
@EOF = global i8 0
define void @writebits() {
%1 = alloca [512 x i32]
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8
store i32 0, i32* %2
br label %7
7: ; preds = %19, %0
%8 = load i32, i32* %2
%9 = icmp ult i32 %8, 512
br i1 %9, label %10, label %22
10: ; preds = %7
%11 = load i32, i32* %2
%12 = load i32, i32* %2
%13 = mul i32 %11, %12
%14 = load i32, i32* %2
%15 = sub i32 %13, %14
%16 = load i32, i32* %2
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds [512 x i32], [512 x i32]* %1, i64 0, i64 %17
store i32 %15, i32* %18
br label %19
19: ; preds = %10
%20 = load i32, i32* %2
%21 = add i32 %20, 1
store i32 %21, i32* %2
br label %7
22: ; preds = %7
%23 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %3
%24 = getelementptr inbounds [512 x i32], [512 x i32]* %1, i64 0, i64 0
%25 = load i32*, i32** %3
%26 = call i32 @fwrite(i32* %24, i32 4, i32 512, i32* %25)
%27 = load i32*, i32** %3
%28 = call i32 @fclose(i32* %27)
%29 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %29, i32** %4
store i8 0, i8* %6
store i32 0, i32* %5
br label %30
30: ; preds = %39, %22
%31 = load i8, i8* %6
%32 = sext i8 %31 to i32
%33 = load i8, i8* @EOF
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %32, %34
br i1 %35, label %36, label %42
36: ; preds = %30
%37 = load i32*, i32** %4
%38 = call i32 @fread(i8* %6, i32 1, i32 1, i32* %37)
br label %39
39: ; preds = %36
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %30
42: ; preds = %30
%43 = load i32*, i32** %4
%44 = call i32 @fclose(i32* %43)
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"xdata.bin\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [3 x i8] c"rb\00"
@EOF = global i8 0
define void @writebits() {
%1 = alloca [512 x i32]
%2 = alloca i8
%3 = bitcast [512 x i32]* %1 to i8*
br label %4
4: ; preds = %4, %0
%5 = phi i64 [ 0, %0 ], [ %27, %4 ]
%6 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %28, %4 ]
%7 = add <4 x i32> %6, <i32 4, i32 4, i32 4, i32 4>
%8 = mul nuw nsw <4 x i32> %6, %6
%9 = mul nuw nsw <4 x i32> %7, %7
%10 = sub nsw <4 x i32> %8, %6
%11 = sub nsw <4 x i32> %9, %7
%12 = getelementptr inbounds [512 x i32], [512 x i32]* %1, i64 0, i64 %5
%13 = bitcast i32* %12 to <4 x i32>*
store <4 x i32> %10, <4 x i32>* %13
%14 = getelementptr inbounds i32, i32* %12, i64 4
%15 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> %11, <4 x i32>* %15
%16 = or i64 %5, 8
%17 = add <4 x i32> %6, <i32 8, i32 8, i32 8, i32 8>
%18 = add <4 x i32> %6, <i32 12, i32 12, i32 12, i32 12>
%19 = mul nuw nsw <4 x i32> %17, %17
%20 = mul nuw nsw <4 x i32> %18, %18
%21 = sub nsw <4 x i32> %19, %17
%22 = sub nsw <4 x i32> %20, %18
%23 = getelementptr inbounds [512 x i32], [512 x i32]* %1, i64 0, i64 %16
%24 = bitcast i32* %23 to <4 x i32>*
store <4 x i32> %21, <4 x i32>* %24
%25 = getelementptr inbounds i32, i32* %23, i64 4
%26 = bitcast i32* %25 to <4 x i32>*
store <4 x i32> %22, <4 x i32>* %26
%27 = add nuw nsw i64 %5, 16
%28 = add <4 x i32> %6, <i32 16, i32 16, i32 16, i32 16>
%29 = icmp eq i64 %27, 512
br i1 %29, label %30, label %4
30: ; preds = %4
%31 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%32 = getelementptr inbounds [512 x i32], [512 x i32]* %1, i64 0, i64 0
%33 = call i32 @fwrite(i32* %32, i32 4, i32 512, i32* %31)
%34 = tail call i32 @fclose(i32* %31)
%35 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i8 0, i8* %2
%36 = load i8, i8* @EOF
%37 = icmp eq i8 %36, 0
br i1 %37, label %43, label %38
38: ; preds = %30, %38
%39 = call i32 @fread(i8* %2, i32 1, i32 1, i32* %35)
%40 = load i8, i8* %2
%41 = load i8, i8* @EOF
%42 = icmp eq i8 %40, %41
br i1 %42, label %43, label %38
43: ; preds = %38, %30
%44 = tail call i32 @fclose(i32* %35)
ret void
}