#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*/ SEEK_SET;
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileActions(float, float, int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long);
scalar_t__ fread(float *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int fileReader(FILE *complexfile, long offset, long number, int isComplex,
               int action) {
  long i;
  float a, b;
  if (fseek(complexfile, offset * isComplex * sizeof(float), SEEK_SET) != 0) {
    perror("something when seeking the offset for the file");
    return 1;
  }
  for (i = 0; i < number; i++) {
    a = 0;
    b = 0;
    if (fread(&a, sizeof(float), 1, complexfile) == 0 ||
        isComplex == 2 && fread(&b, sizeof(float), 1, complexfile) == 0) {
      if (ferror(complexfile)) {
        perror("Something occurred while reading the file");
        return 1;
      }
      if (feof(complexfile)) {
        fprintf(stderr, "The end of the file reached after %ld read samples\n",
                i);
      }
      break;
    }
    fileActions(a, b, action, isComplex);
  }
  return 0;
}


x86 assembly (clang, -O0):
<fileReader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x24(%rbp),%rax
imul   %rax,%rsi
shl    $0x2,%rsi
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
cmp    $0x0,%rax
je     11cf <fileReader+0x5f>
lea    0xe42(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ca <fileReader+0x15a>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    12c3 <fileReader+0x153>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x34(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x0,%rax
je     1241 <fileReader+0xd1>
cmpl   $0x2,-0x24(%rbp)
jne    129d <fileReader+0x12d>
mov    -0x10(%rbp),%rcx
lea    -0x38(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x0,%rax
jne    129d <fileReader+0x12d>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     126c <fileReader+0xfc>
lea    0xdd4(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ca <fileReader+0x15a>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     1298 <fileReader+0x128>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xdc6(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12c3 <fileReader+0x153>
movss  -0x34(%rbp),%xmm0
movss  -0x38(%rbp),%xmm1
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1090 <fileActions@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11d7 <fileReader+0x67>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileReader>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %ecx,%ebx
mov    %rdx,%r12
mov    %rdi,%r15
movslq %ecx,%rax
imul   %rax,%rsi
shl    $0x2,%rsi
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
test   %rax,%rax
jne    1265 <fileReader+0xf5>
test   %r12,%r12
jle    122b <fileReader+0xbb>
xor    %ebp,%ebp
lea    0x4(%rsp),%r13
jmp    11d9 <fileReader+0x69>
nopw   0x0(%rax,%rax,1)
movss  0x4(%rsp),%xmm0
mov    %r14d,%edi
mov    %ebx,%esi
call   1090 <fileActions@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
je     122b <fileReader+0xbb>
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
mov    %r13,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     122f <fileReader+0xbf>
xorps  %xmm1,%xmm1
cmp    $0x2,%ebx
jne    11c0 <fileReader+0x50>
mov    %rsp,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     122f <fileReader+0xbf>
movss  (%rsp),%xmm1
jmp    11c0 <fileReader+0x50>
xor    %ebx,%ebx
jmp    127f <fileReader+0x10f>
mov    %r15,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    126e <fileReader+0xfe>
mov    %r15,%rdi
call   1060 <feof@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     127f <fileReader+0x10f>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
mov    %rbp,%rdx
call   1050 <fprintf@plt>
jmp    127f <fileReader+0x10f>
lea    0xd94(%rip),%rdi
jmp    1275 <fileReader+0x105>
lea    0xdba(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [47 x i8] c"something when seeking the offset for the file\00"
@.str.1 = [42 x i8] c"Something occurred while reading the file\00"
@stderr = global i32 0
@.str.2 = [52 x i8] c"The end of the file reached after %ld read samples\0A\00"
define i32 @fileReader(i32* %0, i64 %1, i64 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca float
%14 = alloca float
store i32* %0, i32** %7
store i64 %1, i64* %8
store i64 %2, i64* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%15 = load i32*, i32** %7
%16 = load i64, i64* %8
%17 = load i32, i32* %10
%18 = sext i32 %17 to i64
%19 = mul nsw i64 %16, %18
%20 = mul i64 %19, 4
%21 = load i32, i32* @SEEK_SET
%22 = call i64 @fseek(i32* %15, i64 %20, i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %5
%25 = call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %6
br label %67
26: ; preds = %5
store i64 0, i64* %12
br label %27
27: ; preds = %63, %26
%28 = load i64, i64* %12
%29 = load i64, i64* %9
%30 = icmp slt i64 %28, %29
br i1 %30, label %31, label %66
31: ; preds = %27
store float 0.000000e+00, float* %13
store float 0.000000e+00, float* %14
%32 = load i32*, i32** %7
%33 = call i64 @fread(float* %13, i32 4, i32 1, i32* %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %42, label %35
35: ; preds = %31
%36 = load i32, i32* %10
%37 = icmp eq i32 %36, 2
br i1 %37, label %38, label %57
38: ; preds = %35
%39 = load i32*, i32** %7
%40 = call i64 @fread(float* %14, i32 4, i32 1, i32* %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %57
42: ; preds = %38, %31
%43 = load i32*, i32** %7
%44 = call i64 @ferror(i32* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %6
br label %67
48: ; preds = %42
%49 = load i32*, i32** %7
%50 = call i64 @feof(i32* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = load i64, i64* %12
%55 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i64 %54)
br label %56
56: ; preds = %52, %48
br label %66
57: ; preds = %38, %35
%58 = load float, float* %13
%59 = load float, float* %14
%60 = load i32, i32* %11
%61 = load i32, i32* %10
%62 = call i32 @fileActions(float %58, float %59, i32 %60, i32 %61)
br label %63
63: ; preds = %57
%64 = load i64, i64* %12
%65 = add nsw i64 %64, 1
store i64 %65, i64* %12
br label %27
66: ; preds = %56, %27
store i32 0, i32* %6
br label %67
67: ; preds = %66, %46, %24
%68 = load i32, i32* %6
ret i32 %68
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [47 x i8] c"something when seeking the offset for the file\00"
@.str.1 = [42 x i8] c"Something occurred while reading the file\00"
@stderr = global i32 0
@.str.2 = [52 x i8] c"The end of the file reached after %ld read samples\0A\00"
define i32 @fileReader(i32* nocapture %0, i64 %1, i64 %2, i32 %3, i32 %4) {
%6 = alloca float
%7 = alloca float
%8 = bitcast float* %6 to i8*
%9 = bitcast float* %7 to i8*
%10 = sext i32 %3 to i64
%11 = shl i64 %1, 2
%12 = mul i64 %11, %10
%13 = load i32, i32* @SEEK_SET
%14 = tail call i64 @fseek(i32* %0, i64 %12, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %5
%17 = icmp sgt i64 %2, 0
br i1 %17, label %18, label %49
18: ; preds = %16
%19 = icmp eq i32 %3, 2
br label %22
20: ; preds = %5
%21 = tail call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %49
22: ; preds = %18, %43
%23 = phi i64 [ 0, %18 ], [ %47, %43 ]
store float 0.000000e+00, float* %6
store float 0.000000e+00, float* %7
%24 = call i64 @fread(float* %6, i32 4, i32 1, i32* %0)
%25 = icmp eq i64 %24, 0
br i1 %25, label %32, label %26
26: ; preds = %22
br i1 %19, label %27, label %43
27: ; preds = %26
%28 = call i64 @fread(float* %7, i32 4, i32 1, i32* %0)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = load float, float* %7
br label %43
32: ; preds = %27, %22
%33 = tail call i64 @ferror(i32* %0)
%34 = icmp eq i64 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = tail call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
br label %49
37: ; preds = %32
%38 = tail call i64 @feof(i32* %0)
%39 = icmp eq i64 %38, 0
br i1 %39, label %49, label %40
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = tail call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i64 %23)
br label %49
43: ; preds = %30, %26
%44 = phi float [ %31, %30 ], [ 0.000000e+00, %26 ]
%45 = load float, float* %6
%46 = tail call i32 @fileActions(float %45, float %44, i32 %4, i32 %3)
%47 = add nuw nsw i64 %23, 1
%48 = icmp eq i64 %47, %2
br i1 %48, label %49, label %22
49: ; preds = %43, %16, %40, %37, %35, %20
%50 = phi i32 [ 1, %20 ], [ 1, %35 ], [ 0, %37 ], [ 0, %40 ], [ 0, %16 ], [ 0, %43 ]
ret i32 %50
}