#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 O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SWAPF(float *);
int /*<<< orphan*/ SWAPL(int *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, int, char *);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int f2write(char *file, float *data1, float *data2, int length) {
  int fd;
  int size;
  int offset;
  if ((fd = open(file, O_CREAT | O_WRONLY | O_TRUNC, 0644)) < 0) {
    fprintf(stderr, "f2write: %s: can't create\n", file);
    return -1;
  }
  SWAPL(&length);
  if (write(fd, (char *)&length, 4) != 4) {
    fprintf(stderr, "f2write: %s: can't write length\n", file);
    close(fd);
    return -1;
  }
  SWAPL(&length);
  for (offset = 0; offset < length; offset++) {
    SWAPF(data1 + offset);
    SWAPF(data2 + offset);
  }
  size = length * sizeof(float);
  if (write(fd, (char *)data1, size) != size) {
    fprintf(stderr, "f2write: %s: can't write data1\n", file);
    close(fd);
    return -1;
  }
  if (write(fd, (char *)data2, size) != size) {
    fprintf(stderr, "f2write: %s: can't write data2\n", file);
    close(fd);
    return -1;
  }
  for (offset = 0; offset < length; offset++) {
    SWAPF(data1 + offset);
    SWAPF(data2 + offset);
  }
  printf("Wrote %d * 2 floats in %s.\n", length, file);
  close(fd);
  return length;
}


x86 assembly (clang, -O0):
<f2write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
mov    0x2e25(%rip),%rax
or     (%rax),%esi
mov    0x2e4c(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1070 <open@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    11e1 <f2write+0x71>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe30(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1382 <f2write+0x212>
lea    -0x24(%rbp),%rdi
call   1080 <SWAPL@plt>
mov    -0x28(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x4,%eax
je     1231 <f2write+0xc1>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe03(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1382 <f2write+0x212>
lea    -0x24(%rbp),%rdi
call   1080 <SWAPL@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1283 <f2write+0x113>
mov    -0x18(%rbp),%rdi
movslq -0x30(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1090 <SWAPF@plt>
mov    -0x20(%rbp),%rdi
movslq -0x30(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1090 <SWAPF@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1241 <f2write+0xd1>
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <write@plt>
cmp    -0x2c(%rbp),%eax
je     12d3 <f2write+0x163>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd82(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1382 <f2write+0x212>
mov    -0x28(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <write@plt>
cmp    -0x2c(%rbp),%eax
je     1318 <f2write+0x1a8>
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd5d(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1382 <f2write+0x212>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1361 <f2write+0x1f1>
mov    -0x18(%rbp),%rdi
movslq -0x30(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1090 <SWAPF@plt>
mov    -0x20(%rbp),%rdi
movslq -0x30(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1090 <SWAPF@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    131f <f2write+0x1af>
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xd0d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f2write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
mov    0x2e6a(%rip),%rax
mov    0x2e2b(%rip),%rdx
mov    (%rdx),%esi
or     (%rax),%esi
mov    %ecx,0x8(%rsp)
mov    0x2e4c(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1070 <open@plt>
test   %eax,%eax
js     12c2 <f2write+0x152>
mov    %eax,%ebp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <SWAPL@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0x4,%eax
jne    12dc <f2write+0x16c>
lea    0x8(%rsp),%rdi
call   1080 <SWAPL@plt>
mov    0x8(%rsp),%ebx
test   %ebx,%ebx
jle    123f <f2write+0xcf>
mov    %ebp,0xc(%rsp)
mov    %r15,0x10(%rsp)
xor    %r15d,%r15d
mov    %r13,%rbp
mov    %r14,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
call   1090 <SWAPF@plt>
mov    %r12,%rdi
call   1090 <SWAPF@plt>
add    $0x1,%r15
movslq 0x8(%rsp),%rbx
add    $0x4,%r12
add    $0x4,%rbp
cmp    %rbx,%r15
jl     1210 <f2write+0xa0>
mov    0x10(%rsp),%r15
mov    0xc(%rsp),%ebp
shl    $0x2,%ebx
mov    %ebp,%edi
mov    %r13,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
cmp    %ebx,%eax
jne    12ee <f2write+0x17e>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
cmp    %ebx,%eax
jne    1300 <f2write+0x190>
mov    0x8(%rsp),%esi
test   %esi,%esi
jle    12a6 <f2write+0x136>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
call   1090 <SWAPF@plt>
mov    %r14,%rdi
call   1090 <SWAPF@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rsi
add    $0x4,%r14
add    $0x4,%r13
cmp    %rsi,%rbx
jl     1280 <f2write+0x110>
lea    0xdcf(%rip),%rdi
mov    %r15,%rdx
call   1040 <printf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    0x8(%rsp),%eax
jmp    1324 <f2write+0x1b4>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
lea    0xd2e(%rip),%rsi
mov    %r15,%rdx
call   1060 <fprintf@plt>
jmp    131f <f2write+0x1af>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
lea    0xd2f(%rip),%rsi
jmp    1310 <f2write+0x1a0>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
lea    0xd3e(%rip),%rsi
jmp    1310 <f2write+0x1a0>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
lea    0xd4c(%rip),%rsi
mov    %r15,%rdx
call   1060 <fprintf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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