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

/* Variables and functions */
int write(int, char *, unsigned long);
int pvoc_writeWindow(int fd, int byterev, float *window, unsigned long length) {
  if (byterev) {
    unsigned long i;
    long lval, *lp = (long *)window;
    for (i = 0; i < length; i++) {
      lval = *lp++;
      lval = ((((lval)&0xff) << 24) | (((lval)&0xff00) << 8) |
              (((lval)&0xff0000) >> 8) | (((lval) >> 24) & 0xff));
      if (write(fd, (char *)&lval, sizeof(long)) != sizeof(long))
        return 0;
    }
  } else {
    if (write(fd, (char *)window, length * sizeof(float)) !=
        (int)(length * sizeof(float)))
      return 0;
  }
  return length * sizeof(float);
}


x86 assembly (clang, -O0):
<pvoc_writeWindow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11f0 <pvoc_writeWindow+0xe0>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11eb <pvoc_writeWindow+0xdb>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x38(%rbp)
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
and    $0xff,%rax
shl    $0x18,%rax
mov    -0x30(%rbp),%rcx
and    $0xff00,%rcx
shl    $0x8,%rcx
or     %rcx,%rax
mov    -0x30(%rbp),%rcx
and    $0xff0000,%rcx
sar    $0x8,%rcx
or     %rcx,%rax
mov    -0x30(%rbp),%rcx
sar    $0x18,%rcx
and    $0xff,%rcx
or     %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
cltq
cmp    $0x8,%rax
je     11d5 <pvoc_writeWindow+0xc5>
movl   $0x0,-0x4(%rbp)
jmp    1230 <pvoc_writeWindow+0x120>
jmp    11da <pvoc_writeWindow+0xca>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1140 <pvoc_writeWindow+0x30>
jmp    1225 <pvoc_writeWindow+0x115>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
shl    $0x2,%rdx
call   1030 <write@plt>
mov    -0x20(%rbp),%rcx
shl    $0x2,%rcx
cmp    %ecx,%eax
je     1220 <pvoc_writeWindow+0x110>
movl   $0x0,-0x4(%rbp)
jmp    1230 <pvoc_writeWindow+0x120>
jmp    1225 <pvoc_writeWindow+0x115>
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pvoc_writeWindow>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r12
mov    %rdx,%r14
mov    %edi,%ebp
test   %esi,%esi
je     116a <pvoc_writeWindow+0x5a>
test   %r12,%r12
je     1188 <pvoc_writeWindow+0x78>
xor    %ebx,%ebx
lea    0x8(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r14,%rbx,8),%eax
bswap  %eax
mov    %rax,0x8(%rsp)
mov    $0x8,%edx
mov    %ebp,%edi
mov    %r15,%rsi
call   1030 <write@plt>
cmp    $0x8,%eax
jne    1191 <pvoc_writeWindow+0x81>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <pvoc_writeWindow+0x30>
jmp    1188 <pvoc_writeWindow+0x78>
lea    0x0(,%r12,4),%r15
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <write@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %r15d,%ecx
jne    1193 <pvoc_writeWindow+0x83>
shl    $0x2,%r12d
mov    %r12d,%eax
jmp    1193 <pvoc_writeWindow+0x83>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pvoc_writeWindow(i32 %0, i32 %1, float* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca float*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64*
store i32 %0, i32* %6
store i32 %1, i32* %7
store float* %2, float** %8
store i64 %3, i64* %9
%13 = load i32, i32* %7
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %52
15: ; preds = %4
%16 = load float*, float** %8
%17 = bitcast float* %16 to i64*
store i64* %17, i64** %12
store i64 0, i64* %10
br label %18
18: ; preds = %48, %15
%19 = load i64, i64* %10
%20 = load i64, i64* %9
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %51
22: ; preds = %18
%23 = load i64*, i64** %12
%24 = getelementptr inbounds i64, i64* %23, i32 1
store i64* %24, i64** %12
%25 = load i64, i64* %23
store i64 %25, i64* %11
%26 = load i64, i64* %11
%27 = and i64 %26, 255
%28 = shl i64 %27, 24
%29 = load i64, i64* %11
%30 = and i64 %29, 65280
%31 = shl i64 %30, 8
%32 = or i64 %28, %31
%33 = load i64, i64* %11
%34 = and i64 %33, 16711680
%35 = ashr i64 %34, 8
%36 = or i64 %32, %35
%37 = load i64, i64* %11
%38 = ashr i64 %37, 24
%39 = and i64 %38, 255
%40 = or i64 %36, %39
store i64 %40, i64* %11
%41 = load i32, i32* %6
%42 = bitcast i64* %11 to i8*
%43 = call i32 @write(i32 %41, i8* %42, i64 8)
%44 = sext i32 %43 to i64
%45 = icmp ne i64 %44, 8
br i1 %45, label %46, label %47
46: ; preds = %22
store i32 0, i32* %5
br label %69
47: ; preds = %22
br label %48
48: ; preds = %47
%49 = load i64, i64* %10
%50 = add i64 %49, 1
store i64 %50, i64* %10
br label %18
51: ; preds = %18
br label %65
52: ; preds = %4
%53 = load i32, i32* %6
%54 = load float*, float** %8
%55 = bitcast float* %54 to i8*
%56 = load i64, i64* %9
%57 = mul i64 %56, 4
%58 = call i32 @write(i32 %53, i8* %55, i64 %57)
%59 = load i64, i64* %9
%60 = mul i64 %59, 4
%61 = trunc i64 %60 to i32
%62 = icmp ne i32 %58, %61
br i1 %62, label %63, label %64
63: ; preds = %52
store i32 0, i32* %5
br label %69
64: ; preds = %52
br label %65
65: ; preds = %64, %51
%66 = load i64, i64* %9
%67 = mul i64 %66, 4
%68 = trunc i64 %67 to i32
store i32 %68, i32* %5
br label %69
69: ; preds = %65, %63, %46
%70 = load i32, i32* %5
ret i32 %70
}

LLVM IR (-O2):
define i32 @pvoc_writeWindow(i32 %0, i32 %1, float* nocapture %2, i64 %3) {
%5 = alloca i64
%6 = icmp eq i32 %1, 0
br i1 %6, label %27, label %7
7: ; preds = %4
%8 = bitcast i64* %5 to i8*
%9 = icmp eq i64 %3, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = bitcast float* %2 to i64*
br label %13
12: ; preds = %22, %7
br label %33
13: ; preds = %10, %22
%14 = phi i64* [ %23, %22 ], [ %11, %10 ]
%15 = phi i64 [ %24, %22 ], [ 0, %10 ]
%16 = load i64, i64* %14
%17 = trunc i64 %16 to i32
%18 = tail call i32 @llvm.bswap.i32(i32 %17)
%19 = zext i32 %18 to i64
store i64 %19, i64* %5
%20 = call i32 @write(i32 %0, i8* %8, i64 8)
%21 = icmp eq i32 %20, 8
br i1 %21, label %22, label %26
22: ; preds = %13
%23 = getelementptr inbounds i64, i64* %14, i64 1
%24 = add nuw i64 %15, 1
%25 = icmp eq i64 %24, %3
br i1 %25, label %12, label %13
26: ; preds = %13
br label %36
27: ; preds = %4
%28 = bitcast float* %2 to i8*
%29 = shl i64 %3, 2
%30 = tail call i32 @write(i32 %0, i8* %28, i64 %29)
%31 = trunc i64 %29 to i32
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %12, %27
%34 = trunc i64 %3 to i32
%35 = shl i32 %34, 2
br label %36
36: ; preds = %26, %27, %33
%37 = phi i32 [ 0, %26 ], [ %35, %33 ], [ 0, %27 ]
ret i32 %37
}