#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned int, unsigned int);
void readbits() {
  FILE *bNums = fopen("xdata.bin", "rb");
  unsigned int bitNums[512];
  fread(bitNums, sizeof(int), 512, bNums);
  fclose(bNums);
  for (unsigned int i = 0; i < 512; i++) {
    if (bitNums[i] != i * i - i) {
      printf("Error! bitNums[%d] = %d\n", i, bitNums[i]);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<readbits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
lea    0xeae(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
lea    -0x810(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x4,%esi
mov    $0x200,%edx
call   1030 <fread@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x814(%rbp)
cmpl   $0x200,-0x814(%rbp)
jae    1204 <readbits+0xc4>
mov    -0x814(%rbp),%eax
mov    -0x810(%rbp,%rax,4),%eax
mov    -0x814(%rbp),%ecx
imul   -0x814(%rbp),%ecx
sub    -0x814(%rbp),%ecx
cmp    %ecx,%eax
je     11eb <readbits+0xab>
mov    -0x814(%rbp),%esi
mov    -0x814(%rbp),%eax
mov    -0x810(%rbp,%rax,4),%edx
lea    0xe2c(%rip),%rdi
call   1050 <printf@plt>
jmp    1204 <readbits+0xc4>
jmp    11f0 <readbits+0xb0>
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
jmp    118f <readbits+0x4f>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readbits>:
push   %rbx
sub    $0x800,%rsp
lea    0xeb1(%rip),%rdi
lea    0xeb4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x4,%esi
mov    $0x200,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %esi,%esi
nopl   (%rax)
mov    (%rsp,%rsi,4),%edx
mov    %esi,%eax
imul   %esi,%eax
sub    %esi,%eax
cmp    %eax,%edx
jne    11ea <readbits+0xaa>
lea    0x1(%rsi),%eax
mov    0x4(%rsp,%rsi,4),%edx
mov    %eax,%ecx
imul   %eax,%ecx
sub    %eax,%ecx
cmp    %ecx,%edx
jne    11da <readbits+0x9a>
lea    0x2(%rsi),%eax
mov    0x8(%rsp,%rsi,4),%edx
mov    %eax,%ecx
imul   %eax,%ecx
sub    %eax,%ecx
cmp    %ecx,%edx
jne    11e0 <readbits+0xa0>
lea    0x3(%rsi),%eax
mov    0xc(%rsp,%rsi,4),%edx
mov    %eax,%ecx
imul   %eax,%ecx
sub    %eax,%ecx
cmp    %ecx,%edx
jne    11e6 <readbits+0xa6>
add    $0x4,%rsi
cmp    $0x200,%rsi
jne    1180 <readbits+0x40>
add    $0x800,%rsp
pop    %rbx
ret
add    $0x1,%rsi
jmp    11ea <readbits+0xaa>
add    $0x2,%rsi
jmp    11ea <readbits+0xaa>
add    $0x3,%rsi
lea    0xe1c(%rip),%rdi
add    $0x800,%rsp
pop    %rbx
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"xdata.bin\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [25 x i8] c"Error! bitNums[%d] = %d\0A\00"
define void @readbits() {
%1 = alloca i32*
%2 = alloca [512 x i32]
%3 = alloca i32
%4 = 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* %4, i32** %1
%5 = getelementptr inbounds [512 x i32], [512 x i32]* %2, i64 0, i64 0
%6 = load i32*, i32** %1
%7 = call i32 @fread(i32* %5, i32 4, i32 512, i32* %6)
%8 = load i32*, i32** %1
%9 = call i32 @fclose(i32* %8)
store i32 0, i32* %3
br label %10
10: ; preds = %32, %0
%11 = load i32, i32* %3
%12 = icmp ult i32 %11, 512
br i1 %12, label %13, label %35
13: ; preds = %10
%14 = load i32, i32* %3
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [512 x i32], [512 x i32]* %2, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = load i32, i32* %3
%19 = load i32, i32* %3
%20 = mul i32 %18, %19
%21 = load i32, i32* %3
%22 = sub i32 %20, %21
%23 = icmp ne i32 %17, %22
br i1 %23, label %24, label %31
24: ; preds = %13
%25 = load i32, i32* %3
%26 = load i32, i32* %3
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds [512 x i32], [512 x i32]* %2, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %25, i32 %29)
br label %35
31: ; preds = %13
br label %32
32: ; preds = %31
%33 = load i32, i32* %3
%34 = add i32 %33, 1
store i32 %34, i32* %3
br label %10
35: ; preds = %24, %10
ret void
}

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