#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 int32_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int read(int, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ swap4(char *, int);
int read_float4(int fd, float *rstore, int size, int swap) {
  int n;
  int32_t rl1, rl2;
  n = read(fd, &rl1, 4);
  if (n == 0)
    return -1;
  if (swap)
    swap4((char *)&rl1, 1);
  n = read(fd, rstore, rl1);
  if (swap)
    swap4((char *)rstore, size);
  n = read(fd, &rl2, 4);
  if (swap)
    swap4((char *)&rl2, 1);
  if (rl1 != rl2) {
    fprintf(stderr, "Error read float block\n");
    return -2;
  }
  if (4 * size != rl2)
    fprintf(stderr, "read_float4: Expected %d, got %d elements\n", 4 * size,
            rl2);
  return 0;
}


x86 assembly (clang, -O0):
<read_float4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1171 <read_float4+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    1246 <read_float4+0x116>
cmpl   $0x0,-0x18(%rbp)
je     1189 <read_float4+0x59>
lea    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1050 <swap4@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    $0x0,%al
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11b3 <read_float4+0x83>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <swap4@plt>
mov    -0x8(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11e1 <read_float4+0xb1>
lea    -0x24(%rbp),%rdi
mov    $0x1,%esi
call   1050 <swap4@plt>
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     1210 <read_float4+0xe0>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1246 <read_float4+0x116>
mov    -0x14(%rbp),%eax
shl    $0x2,%eax
cmp    -0x24(%rbp),%eax
je     123f <read_float4+0x10f>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
shl    $0x2,%edx
mov    -0x24(%rbp),%ecx
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_float4>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,%ebp
mov    %rsp,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <read@plt>
test   %eax,%eax
je     11a4 <read_float4+0x74>
test   %ebx,%ebx
je     11ab <read_float4+0x7b>
mov    %rsp,%rdi
mov    $0x1,%esi
call   1050 <swap4@plt>
mov    (%rsp),%edx
mov    %ebp,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <read@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   1050 <swap4@plt>
lea    0x4(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <read@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1050 <swap4@plt>
jmp    11cd <read_float4+0x9d>
mov    $0xffffffff,%ebx
jmp    121b <read_float4+0xeb>
mov    (%rsp),%edx
mov    %ebp,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <read@plt>
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <read@plt>
mov    (%rsp),%ecx
cmp    0x4(%rsp),%ecx
jne    11ff <read_float4+0xcf>
shl    $0x2,%r14d
xor    %ebx,%ebx
cmp    %ecx,%r14d
je     121b <read_float4+0xeb>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
xor    %ebx,%ebx
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    121b <read_float4+0xeb>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xfffffffe,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Error read float block\0A\00"
@.str.1 = [43 x i8] c"read_float4: Expected %d, got %d elements\0A\00"
define i32 @read_float4(i32 %0, float* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca float*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %6
store float* %1, float** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = load i32, i32* %6
%14 = call i32 (i32, ...) @read(i32 %13, i32* %11, i32 4)
store i32 %14, i32* %10
%15 = load i32, i32* %10
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 -1, i32* %5
br label %63
18: ; preds = %4
%19 = load i32, i32* %9
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = bitcast i32* %11 to i8*
%23 = call i32 @swap4(i8* %22, i32 1)
br label %24
24: ; preds = %21, %18
%25 = load i32, i32* %6
%26 = load float*, float** %7
%27 = load i32, i32* %11
%28 = call i32 (i32, ...) @read(i32 %25, float* %26, i32 %27)
store i32 %28, i32* %10
%29 = load i32, i32* %9
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %24
%32 = load float*, float** %7
%33 = bitcast float* %32 to i8*
%34 = load i32, i32* %8
%35 = call i32 @swap4(i8* %33, i32 %34)
br label %36
36: ; preds = %31, %24
%37 = load i32, i32* %6
%38 = call i32 (i32, ...) @read(i32 %37, i32* %12, i32 4)
store i32 %38, i32* %10
%39 = load i32, i32* %9
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = bitcast i32* %12 to i8*
%43 = call i32 @swap4(i8* %42, i32 1)
br label %44
44: ; preds = %41, %36
%45 = load i32, i32* %11
%46 = load i32, i32* %12
%47 = icmp ne i32 %45, %46
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 -2, i32* %5
br label %63
51: ; preds = %44
%52 = load i32, i32* %8
%53 = mul nsw i32 4, %52
%54 = load i32, i32* %12
%55 = icmp ne i32 %53, %54
br i1 %55, label %56, label %62
56: ; preds = %51
%57 = load i32, i32* @stderr
%58 = load i32, i32* %8
%59 = mul nsw i32 4, %58
%60 = load i32, i32* %12
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %59, i32 %60)
br label %62
62: ; preds = %56, %51
store i32 0, i32* %5
br label %63
63: ; preds = %62, %48, %17
%64 = load i32, i32* %5
ret i32 %64
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"Error read float block\0A\00"
@.str.1 = [43 x i8] c"read_float4: Expected %d, got %d elements\0A\00"
define i32 @read_float4(i32 %0, float* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %5 to i8*
%8 = bitcast i32* %6 to i8*
%9 = call i32 (i32, ...) @read(i32 %0, i32* %5, i32 4)
%10 = icmp eq i32 %9, 0
br i1 %10, label %38, label %11
11: ; preds = %4
%12 = icmp eq i32 %3, 0
br i1 %12, label %13, label %17
13: ; preds = %11
%14 = load i32, i32* %5
%15 = call i32 (i32, ...) @read(i32 %0, float* %1, i32 %14)
%16 = call i32 (i32, ...) @read(i32 %0, i32* %6, i32 4)
br label %25
17: ; preds = %11
%18 = call i32 @swap4(i8* %7, i32 1)
%19 = load i32, i32* %5
%20 = call i32 (i32, ...) @read(i32 %0, float* %1, i32 %19)
%21 = bitcast float* %1 to i8*
%22 = call i32 @swap4(i8* %21, i32 %2)
%23 = call i32 (i32, ...) @read(i32 %0, i32* %6, i32 4)
%24 = call i32 @swap4(i8* %8, i32 1)
br label %25
25: ; preds = %13, %17
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = icmp eq i32 %26, %27
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %38
32: ; preds = %25
%33 = shl nsw i32 %2, 2
%34 = icmp eq i32 %33, %26
br i1 %34, label %38, label %35
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %26)
br label %38
38: ; preds = %32, %35, %4, %29
%39 = phi i32 [ -2, %29 ], [ -1, %4 ], [ 0, %35 ], [ 0, %32 ]
ret i32 %39
}