#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ stderr;
int write_halogen_cat(char *filename, float *x, float *y, float *z, float *vx,
                      float *vy, float *vz, float *M, float *R, long N) {
  FILE *f;
  long i;
  if ((f = fopen(filename, "w")) == NULL) {
    fprintf(stderr, "Couldnt open output file %s\n", filename);
    return -1;
  }
  for (i = 0; i < N; i++) {
    fprintf(f, "%f %f %f %f %f %f %e %f\n", x[i], y[i], z[i], vx[i], vy[i],
            vz[i], M[i], R[i]);
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<write_halogen_cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11a6 <write_halogen_cat+0x76>
mov    0x2e5b(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe6f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1277 <write_halogen_cat+0x147>
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    0x28(%rbp),%rax
jge    1267 <write_halogen_cat+0x137>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x20(%rbp),%rax
mov    -0x48(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
cvtss2sd %xmm1,%xmm1
mov    -0x28(%rbp),%rax
mov    -0x48(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm2
cvtss2sd %xmm2,%xmm2
mov    -0x30(%rbp),%rax
mov    -0x48(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm3
cvtss2sd %xmm3,%xmm3
mov    -0x38(%rbp),%rax
mov    -0x48(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm4
cvtss2sd %xmm4,%xmm4
mov    0x10(%rbp),%rax
mov    -0x48(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm5
cvtss2sd %xmm5,%xmm5
mov    0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm6
cvtss2sd %xmm6,%xmm6
mov    0x20(%rbp),%rax
mov    -0x48(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm7
cvtss2sd %xmm7,%xmm7
lea    0xdd0(%rip),%rsi
mov    $0x8,%al
call   1040 <fprintf@plt>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    11ae <write_halogen_cat+0x7e>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_halogen_cat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%rbp
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbx
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     123d <write_halogen_cat+0x10d>
mov    %rax,%rdi
mov    0x68(%rsp),%rax
test   %rax,%rax
jle    1234 <write_halogen_cat+0x104>
mov    %r14,%rcx
xor    %r14d,%r14d
mov    %r13,0x10(%rsp)
mov    %r12,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
movss  0x0(%r13,%r14,4),%xmm0
cvtss2sd %xmm0,%xmm0
movss  (%r12,%r14,4),%xmm1
cvtss2sd %xmm1,%xmm1
movss  0x0(%rbp,%r14,4),%xmm2
cvtss2sd %xmm2,%xmm2
movss  (%r15,%r14,4),%xmm3
cvtss2sd %xmm3,%xmm3
movss  (%rcx,%r14,4),%xmm4
cvtss2sd %xmm4,%xmm4
mov    0x50(%rsp),%rdx
movss  (%rdx,%r14,4),%xmm5
cvtss2sd %xmm5,%xmm5
mov    0x58(%rsp),%rdx
movss  (%rdx,%r14,4),%xmm6
cvtss2sd %xmm6,%xmm6
mov    0x60(%rsp),%rdx
movss  (%rdx,%r14,4),%xmm7
cvtss2sd %xmm7,%xmm7
mov    %rdi,%rbx
lea    0xe24(%rip),%rsi
mov    %rbp,%r12
mov    %r15,%rbp
mov    %rax,%r15
mov    $0x8,%al
mov    %rcx,%r13
call   1040 <fprintf@plt>
mov    %r13,%rcx
mov    %rbx,%rdi
mov    %r15,%rax
mov    %rbp,%r15
mov    %r12,%rbp
mov    0x8(%rsp),%r12
mov    0x10(%rsp),%r13
add    $0x1,%r14
cmp    %r14,%rax
jne    1190 <write_halogen_cat+0x60>
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    125d <write_halogen_cat+0x12d>
mov    0x2d9c(%rip),%rax
movslq (%rax),%rdi
lea    0xdb4(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Couldnt open output file %s\0A\00"
@.str.2 = [25 x i8] c"%f %f %f %f %f %f %e %f\0A\00"
define i32 @write_halogen_cat(i8* %0, float* %1, float* %2, float* %3, float* %4, float* %5, float* %6, float* %7, float* %8, i64 %9) {
%11 = alloca i32
%12 = alloca i8*
%13 = alloca float*
%14 = alloca float*
%15 = alloca float*
%16 = alloca float*
%17 = alloca float*
%18 = alloca float*
%19 = alloca float*
%20 = alloca float*
%21 = alloca i64
%22 = alloca i32*
%23 = alloca i64
store i8* %0, i8** %12
store float* %1, float** %13
store float* %2, float** %14
store float* %3, float** %15
store float* %4, float** %16
store float* %5, float** %17
store float* %6, float** %18
store float* %7, float** %19
store float* %8, float** %20
store i64 %9, i64* %21
%24 = load i8*, i8** %12
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %25, i32** %22
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %33
27: ; preds = %10
%28 = load i32, i32* @stderr
%29 = sext i32 %28 to i64
%30 = inttoptr i64 %29 to i32*
%31 = load i8*, i8** %12
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %31)
store i32 -1, i32* %11
br label %87
33: ; preds = %10
store i64 0, i64* %23
br label %34
34: ; preds = %81, %33
%35 = load i64, i64* %23
%36 = load i64, i64* %21
%37 = icmp slt i64 %35, %36
br i1 %37, label %38, label %84
38: ; preds = %34
%39 = load i32*, i32** %22
%40 = load float*, float** %13
%41 = load i64, i64* %23
%42 = getelementptr inbounds float, float* %40, i64 %41
%43 = load float, float* %42
%44 = fpext float %43 to double
%45 = load float*, float** %14
%46 = load i64, i64* %23
%47 = getelementptr inbounds float, float* %45, i64 %46
%48 = load float, float* %47
%49 = fpext float %48 to double
%50 = load float*, float** %15
%51 = load i64, i64* %23
%52 = getelementptr inbounds float, float* %50, i64 %51
%53 = load float, float* %52
%54 = fpext float %53 to double
%55 = load float*, float** %16
%56 = load i64, i64* %23
%57 = getelementptr inbounds float, float* %55, i64 %56
%58 = load float, float* %57
%59 = fpext float %58 to double
%60 = load float*, float** %17
%61 = load i64, i64* %23
%62 = getelementptr inbounds float, float* %60, i64 %61
%63 = load float, float* %62
%64 = fpext float %63 to double
%65 = load float*, float** %18
%66 = load i64, i64* %23
%67 = getelementptr inbounds float, float* %65, i64 %66
%68 = load float, float* %67
%69 = fpext float %68 to double
%70 = load float*, float** %19
%71 = load i64, i64* %23
%72 = getelementptr inbounds float, float* %70, i64 %71
%73 = load float, float* %72
%74 = fpext float %73 to double
%75 = load float*, float** %20
%76 = load i64, i64* %23
%77 = getelementptr inbounds float, float* %75, i64 %76
%78 = load float, float* %77
%79 = fpext float %78 to double
%80 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), double %44, double %49, double %54, double %59, double %64, double %69, double %74, double %79)
br label %81
81: ; preds = %38
%82 = load i64, i64* %23
%83 = add nsw i64 %82, 1
store i64 %83, i64* %23
br label %34
84: ; preds = %34
%85 = load i32*, i32** %22
%86 = call i32 @fclose(i32* %85)
store i32 0, i32* %11
br label %87
87: ; preds = %84, %27
%88 = load i32, i32* %11
ret i32 %88
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Couldnt open output file %s\0A\00"
@.str.2 = [25 x i8] c"%f %f %f %f %f %f %e %f\0A\00"
define i32 @write_halogen_cat(i8* %0, float* nocapture %1, float* nocapture %2, float* nocapture %3, float* nocapture %4, float* nocapture %5, float* nocapture %6, float* nocapture %7, float* nocapture %8, i64 %9) {
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = icmp sgt i64 %9, 0
br i1 %14, label %20, label %49
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i32*
%19 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %51
20: ; preds = %13, %20
%21 = phi i64 [ %47, %20 ], [ 0, %13 ]
%22 = getelementptr inbounds float, float* %1, i64 %21
%23 = load float, float* %22
%24 = fpext float %23 to double
%25 = getelementptr inbounds float, float* %2, i64 %21
%26 = load float, float* %25
%27 = fpext float %26 to double
%28 = getelementptr inbounds float, float* %3, i64 %21
%29 = load float, float* %28
%30 = fpext float %29 to double
%31 = getelementptr inbounds float, float* %4, i64 %21
%32 = load float, float* %31
%33 = fpext float %32 to double
%34 = getelementptr inbounds float, float* %5, i64 %21
%35 = load float, float* %34
%36 = fpext float %35 to double
%37 = getelementptr inbounds float, float* %6, i64 %21
%38 = load float, float* %37
%39 = fpext float %38 to double
%40 = getelementptr inbounds float, float* %7, i64 %21
%41 = load float, float* %40
%42 = fpext float %41 to double
%43 = getelementptr inbounds float, float* %8, i64 %21
%44 = load float, float* %43
%45 = fpext float %44 to double
%46 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), double %24, double %27, double %30, double %33, double %36, double %39, double %42, double %45)
%47 = add nuw nsw i64 %21, 1
%48 = icmp eq i64 %47, %9
br i1 %48, label %49, label %20
49: ; preds = %20, %13
%50 = tail call i32 @fclose(i32* %11)
br label %51
51: ; preds = %49, %15
%52 = phi i32 [ -1, %15 ], [ 0, %49 ]
ret i32 %52
}