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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SWAPF(float *);
int /*<<< orphan*/ SWAPL(int *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(unsigned int);
int open(char *, int /*<<< orphan*/, int);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int f2read(char *file, float **data1_ref, float **data2_ref, int *length_ref) {
  int fd;
  int length;
  int size;
  int offset;
  char *data1, *data2;
  if ((fd = open(file, O_RDONLY, 0644)) < 0) {
    fprintf(stderr, "f2read: %s: can't open\n", file);
    return -1;
  }
  if (read(fd, (char *)&length, 4) != 4) {
    fprintf(stderr, "f2read: %s: can't read length (empty file?)\n", file);
    return (-1);
  }
  SWAPL(&length);
  size = length * sizeof(float);
  if (!(data1 = malloc((unsigned)size))) {
    fprintf(stderr, "f2read: %s: can't alloc data1\n", file);
    close(fd);
    return -1;
  }
  if (read(fd, data1, size) != size) {
    fprintf(stderr, "f2read: %s: can't read data1\n", file);
    close(fd);
    free(data1);
    return -1;
  }
  if (!(data2 = malloc((unsigned)size))) {
    fprintf(stderr, "f2read: %s: can't alloc data2\n", file);
    close(fd);
    free(data1);
    return -1;
  }
  if (read(fd, data2, size) != size) {
    fprintf(stderr, "f2read: %s: can't read data2\n", file);
    close(fd);
    free(data1);
    free(data2);
    return -1;
  }
  close(fd);
  *data1_ref = (float *)data1;
  *data2_ref = (float *)data2;
  for (offset = 0; offset < length; offset++) {
    SWAPF(*data1_ref + offset);
    SWAPF(*data2_ref + offset);
  }
  *length_ref = length;
  return length;
}


x86 assembly (clang, -O0):
<f2read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
mov    $0x1a4,%edx
call   1080 <open@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    11e0 <f2read+0x60>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe31(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e3 <f2read+0x263>
mov    -0x2c(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
je     121f <f2read+0x9f>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe0a(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e3 <f2read+0x263>
lea    -0x30(%rbp),%rdi
call   1090 <SWAPL@plt>
movslq -0x30(%rbp),%rax
shl    $0x2,%rax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1276 <f2read+0xf6>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xde8(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x2c(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e3 <f2read+0x263>
mov    -0x2c(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1050 <read@plt>
cmp    -0x34(%rbp),%eax
je     12c4 <f2read+0x144>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdc2(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x2c(%rbp),%edi
call   1040 <close@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e3 <f2read+0x263>
mov    -0x34(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    1310 <f2read+0x190>
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd94(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x2c(%rbp),%edi
call   1040 <close@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e3 <f2read+0x263>
mov    -0x2c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1050 <read@plt>
cmp    -0x34(%rbp),%eax
je     1367 <f2read+0x1e7>
mov    0x2ca9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd65(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x2c(%rbp),%edi
call   1040 <close@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13e3 <f2read+0x263>
mov    -0x2c(%rbp),%edi
call   1040 <close@plt>
mov    -0x40(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x48(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    13d4 <f2read+0x254>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
movslq -0x38(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   10a0 <SWAPF@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
movslq -0x38(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   10a0 <SWAPF@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    138c <f2read+0x20c>
mov    -0x30(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f2read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
mov    $0x1a4,%edx
call   1080 <open@plt>
test   %eax,%eax
js     129e <f2read+0x11e>
mov    %eax,%ebp
lea    0x4(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
jne    12b0 <f2read+0x130>
mov    %rbx,0x10(%rsp)
lea    0x4(%rsp),%rdi
call   1090 <SWAPL@plt>
mov    0x4(%rsp),%r14d
shl    $0x2,%r14d
mov    %r14d,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     12dc <f2read+0x15c>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %rax,%rsi
mov    %r14d,%edx
call   1050 <read@plt>
cmp    %r14d,%eax
jne    12fd <f2read+0x17d>
mov    %r14d,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     130f <f2read+0x18f>
mov    %ebp,%edi
mov    %rax,0x8(%rsp)
mov    %rax,%rsi
mov    %r14d,%edx
call   1050 <read@plt>
cmp    %r14d,%eax
jne    1338 <f2read+0x1b8>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %rbx,(%r12)
mov    0x8(%rsp),%rax
mov    %rax,(%r15)
mov    0x4(%rsp),%eax
test   %eax,%eax
mov    0x10(%rsp),%r14
jle    1299 <f2read+0x119>
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12),%rdi
add    %rbx,%rdi
call   10a0 <SWAPF@plt>
mov    (%r15),%rdi
add    %rbx,%rdi
call   10a0 <SWAPF@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%rbp
jl     1270 <f2read+0xf0>
mov    %eax,(%r14)
jmp    12cd <f2read+0x14d>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
lea    0xd52(%rip),%rsi
jmp    12c0 <f2read+0x140>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
lea    0xd58(%rip),%rsi
mov    %r13,%rdx
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
lea    0xd59(%rip),%rsi
mov    %r13,%rdx
call   1060 <fprintf@plt>
mov    %ebp,%edi
call   1040 <close@plt>
jmp    12c8 <f2read+0x148>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
lea    0xd57(%rip),%rsi
jmp    131f <f2read+0x19f>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
lea    0xd63(%rip),%rsi
mov    %r13,%rdx
call   1060 <fprintf@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    12c8 <f2read+0x148>
mov    0x2c99(%rip),%rax
mov    (%rax),%edi
lea    0xd59(%rip),%rsi
mov    %r13,%rdx
call   1060 <fprintf@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
jmp    1331 <f2read+0x1b1>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"f2read: %s: can't open\0A\00"
@.str.1 = [45 x i8] c"f2read: %s: can't read length (empty file?)\0A\00"
@.str.2 = [31 x i8] c"f2read: %s: can't alloc data1\0A\00"
@.str.3 = [30 x i8] c"f2read: %s: can't read data1\0A\00"
@.str.4 = [31 x i8] c"f2read: %s: can't alloc data2\0A\00"
@.str.5 = [30 x i8] c"f2read: %s: can't read data2\0A\00"
define i32 @f2read(i8* %0, float** %1, float** %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca float**
%8 = alloca float**
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
store i8* %0, i8** %6
store float** %1, float*** %7
store float** %2, float*** %8
store i32* %3, i32** %9
%16 = load i8*, i8** %6
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %16, i32 %17, i32 420)
store i32 %18, i32* %10
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %4
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %6
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %22)
store i32 -1, i32* %5
br label %125
24: ; preds = %4
%25 = load i32, i32* %10
%26 = bitcast i32* %11 to i8*
%27 = call i32 @read(i32 %25, i8* %26, i32 4)
%28 = icmp ne i32 %27, 4
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %6
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %31)
store i32 -1, i32* %5
br label %125
33: ; preds = %24
%34 = call i32 @SWAPL(i32* %11)
%35 = load i32, i32* %11
%36 = sext i32 %35 to i64
%37 = mul i64 %36, 4
%38 = trunc i64 %37 to i32
store i32 %38, i32* %12
%39 = load i32, i32* %12
%40 = call i8* @malloc(i32 %39)
store i8* %40, i8** %14
%41 = icmp ne i8* %40, null
br i1 %41, label %48, label %42
42: ; preds = %33
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %6
%45 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %44)
%46 = load i32, i32* %10
%47 = call i32 @close(i32 %46)
store i32 -1, i32* %5
br label %125
48: ; preds = %33
%49 = load i32, i32* %10
%50 = load i8*, i8** %14
%51 = load i32, i32* %12
%52 = call i32 @read(i32 %49, i8* %50, i32 %51)
%53 = load i32, i32* %12
%54 = icmp ne i32 %52, %53
br i1 %54, label %55, label %63
55: ; preds = %48
%56 = load i32, i32* @stderr
%57 = load i8*, i8** %6
%58 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %57)
%59 = load i32, i32* %10
%60 = call i32 @close(i32 %59)
%61 = load i8*, i8** %14
%62 = call i32 @free(i8* %61)
store i32 -1, i32* %5
br label %125
63: ; preds = %48
%64 = load i32, i32* %12
%65 = call i8* @malloc(i32 %64)
store i8* %65, i8** %15
%66 = icmp ne i8* %65, null
br i1 %66, label %75, label %67
67: ; preds = %63
%68 = load i32, i32* @stderr
%69 = load i8*, i8** %6
%70 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %69)
%71 = load i32, i32* %10
%72 = call i32 @close(i32 %71)
%73 = load i8*, i8** %14
%74 = call i32 @free(i8* %73)
store i32 -1, i32* %5
br label %125
75: ; preds = %63
%76 = load i32, i32* %10
%77 = load i8*, i8** %15
%78 = load i32, i32* %12
%79 = call i32 @read(i32 %76, i8* %77, i32 %78)
%80 = load i32, i32* %12
%81 = icmp ne i32 %79, %80
br i1 %81, label %82, label %92
82: ; preds = %75
%83 = load i32, i32* @stderr
%84 = load i8*, i8** %6
%85 = call i32 @fprintf(i32 %83, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %84)
%86 = load i32, i32* %10
%87 = call i32 @close(i32 %86)
%88 = load i8*, i8** %14
%89 = call i32 @free(i8* %88)
%90 = load i8*, i8** %15
%91 = call i32 @free(i8* %90)
store i32 -1, i32* %5
br label %125
92: ; preds = %75
%93 = load i32, i32* %10
%94 = call i32 @close(i32 %93)
%95 = load i8*, i8** %14
%96 = bitcast i8* %95 to float*
%97 = load float**, float*** %7
store float* %96, float** %97
%98 = load i8*, i8** %15
%99 = bitcast i8* %98 to float*
%100 = load float**, float*** %8
store float* %99, float** %100
store i32 0, i32* %13
br label %101
101: ; preds = %118, %92
%102 = load i32, i32* %13
%103 = load i32, i32* %11
%104 = icmp slt i32 %102, %103
br i1 %104, label %105, label %121
105: ; preds = %101
%106 = load float**, float*** %7
%107 = load float*, float** %106
%108 = load i32, i32* %13
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds float, float* %107, i64 %109
%111 = call i32 @SWAPF(float* %110)
%112 = load float**, float*** %8
%113 = load float*, float** %112
%114 = load i32, i32* %13
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds float, float* %113, i64 %115
%117 = call i32 @SWAPF(float* %116)
br label %118
118: ; preds = %105
%119 = load i32, i32* %13
%120 = add nsw i32 %119, 1
store i32 %120, i32* %13
br label %101
121: ; preds = %101
%122 = load i32, i32* %11
%123 = load i32*, i32** %9
store i32 %122, i32* %123
%124 = load i32, i32* %11
store i32 %124, i32* %5
br label %125
125: ; preds = %121, %82, %67, %55, %42, %29, %20
%126 = load i32, i32* %5
ret i32 %126
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"f2read: %s: can't open\0A\00"
@.str.1 = [45 x i8] c"f2read: %s: can't read length (empty file?)\0A\00"
@.str.2 = [31 x i8] c"f2read: %s: can't alloc data1\0A\00"
@.str.3 = [30 x i8] c"f2read: %s: can't read data1\0A\00"
@.str.4 = [31 x i8] c"f2read: %s: can't alloc data2\0A\00"
@.str.5 = [30 x i8] c"f2read: %s: can't read data2\0A\00"
define i32 @f2read(i8* %0, float** nocapture %1, float** nocapture %2, i32* nocapture writeonly %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %0, i32 %7, i32 420)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %74
13: ; preds = %4
%14 = call i32 @read(i32 %8, i8* %6, i32 4)
%15 = icmp eq i32 %14, 4
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %74
19: ; preds = %13
%20 = call i32 @SWAPL(i32* %5)
%21 = load i32, i32* %5
%22 = shl i32 %21, 2
%23 = call i8* @malloc(i32 %22)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %29
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%28 = call i32 @close(i32 %8)
br label %74
29: ; preds = %19
%30 = call i32 @read(i32 %8, i8* %23, i32 %22)
%31 = icmp eq i32 %30, %22
br i1 %31, label %37, label %32
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%35 = call i32 @close(i32 %8)
%36 = call i32 @free(i8* %23)
br label %74
37: ; preds = %29
%38 = call i8* @malloc(i32 %22)
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%43 = call i32 @close(i32 %8)
%44 = call i32 @free(i8* %23)
br label %74
45: ; preds = %37
%46 = call i32 @read(i32 %8, i8* %38, i32 %22)
%47 = icmp eq i32 %46, %22
br i1 %47, label %54, label %48
48: ; preds = %45
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %0)
%51 = call i32 @close(i32 %8)
%52 = call i32 @free(i8* %23)
%53 = call i32 @free(i8* %38)
br label %74
54: ; preds = %45
%55 = call i32 @close(i32 %8)
%56 = bitcast float** %1 to i8**
store i8* %23, i8** %56
%57 = bitcast float** %2 to i8**
store i8* %38, i8** %57
%58 = load i32, i32* %5
%59 = icmp sgt i32 %58, 0
br i1 %59, label %60, label %72
60: ; preds = %54, %60
%61 = phi i64 [ %68, %60 ], [ 0, %54 ]
%62 = load float*, float** %1
%63 = getelementptr inbounds float, float* %62, i64 %61
%64 = call i32 @SWAPF(float* %63)
%65 = load float*, float** %2
%66 = getelementptr inbounds float, float* %65, i64 %61
%67 = call i32 @SWAPF(float* %66)
%68 = add nuw nsw i64 %61, 1
%69 = load i32, i32* %5
%70 = sext i32 %69 to i64
%71 = icmp slt i64 %68, %70
br i1 %71, label %60, label %72
72: ; preds = %60, %54
%73 = phi i32 [ %58, %54 ], [ %69, %60 ]
store i32 %73, i32* %3
br label %74
74: ; preds = %72, %48, %40, %32, %25, %16, %10
%75 = phi i32 [ -1, %10 ], [ -1, %16 ], [ -1, %32 ], [ -1, %48 ], [ %73, %72 ], [ -1, %40 ], [ -1, %25 ]
ret i32 %75
}