#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 const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int txtarray_write2(const char *filename, const char *header, int m,
                    double *data1, int n1, double *data2, int n2) {
  FILE *fp;
  int i, j;
  double *x;
  double *y;
  fp = fopen(filename, "w");
  if (fp == NULL) {
    return -1;
  }
  fprintf(fp, "# %d %d %d\n", m, n1, n2);
  if (header != NULL)
    fprintf(fp, "# %s\n", header);
  else
    fprintf(fp, "# header\n");
  for (i = 0; i < m; i++) {
    x = &data1[n1 * i];
    for (j = 0; j < n1; j++) {
      fprintf(fp, " %0.12e", x[j]);
    }
    y = &data2[n2 * i];
    for (j = 0; j < n2; j++) {
      fprintf(fp, " %0.12e", y[j]);
    }
    fprintf(fp, "\n");
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<txtarray_write2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    117d <txtarray_write2+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c6 <txtarray_write2+0x196>
mov    -0x40(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    0x10(%rbp),%r8d
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
cmpq   $0x0,-0x18(%rbp)
je     11bf <txtarray_write2+0x8f>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11d1 <txtarray_write2+0xa1>
mov    -0x40(%rbp),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12b6 <txtarray_write2+0x186>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
imul   -0x44(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    123d <txtarray_write2+0x10d>
mov    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rax
movslq -0x48(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xdf6(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1204 <txtarray_write2+0xd4>
mov    -0x38(%rbp),%rax
mov    0x10(%rbp),%ecx
imul   -0x44(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    0x10(%rbp),%eax
jge    1296 <txtarray_write2+0x166>
mov    -0x40(%rbp),%rdi
mov    -0x58(%rbp),%rax
movslq -0x48(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xd9d(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    125d <txtarray_write2+0x12d>
mov    -0x40(%rbp),%rdi
lea    0xd6b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11d8 <txtarray_write2+0xa8>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<txtarray_write2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,%r15
mov    %r8d,%ebp
mov    %rcx,%r12
mov    %edx,%r13d
mov    %rsi,%r14
lea    0xe8c(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c8 <txtarray_write2+0x78>
mov    %rax,%rbx
mov    0x70(%rsp),%r8d
lea    0xe75(%rip),%rsi
mov    %rax,%rdi
mov    %r13d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %r14,%r14
mov    %ebp,0x4(%rsp)
mov    %r12,0x8(%rsp)
je     11d2 <txtarray_write2+0x82>
lea    0xe5d(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %r13d,%r13d
jg     11f4 <txtarray_write2+0xa4>
jmp    12d1 <txtarray_write2+0x181>
mov    $0xffffffff,%eax
jmp    12db <txtarray_write2+0x18b>
lea    0xe3b(%rip),%rdi
mov    $0x9,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
test   %r13d,%r13d
jle    12d1 <txtarray_write2+0x181>
mov    0x4(%rsp),%eax
movslq %eax,%rdx
mov    0x70(%rsp),%ecx
movslq %ecx,%rsi
mov    %r13d,%edi
mov    %rdi,0x10(%rsp)
mov    %eax,%r12d
mov    %ecx,%r14d
shl    $0x3,%rdx
mov    %rdx,0x20(%rsp)
shl    $0x3,%rsi
mov    %rsi,0x18(%rsp)
xor    %ecx,%ecx
lea    0xdf3(%rip),%r13
jmp    125c <txtarray_write2+0x10c>
nopl   (%rax)
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    0x28(%rsp),%rcx
add    $0x1,%rcx
mov    0x20(%rsp),%rax
add    %rax,0x8(%rsp)
add    0x18(%rsp),%r15
cmp    0x10(%rsp),%rcx
je     12d1 <txtarray_write2+0x181>
mov    %rcx,0x28(%rsp)
mov    %r15,0x30(%rsp)
cmpl   $0x0,0x4(%rsp)
mov    0x8(%rsp),%rbp
jle    129d <txtarray_write2+0x14d>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
movsd  0x0(%rbp,%r15,8),%xmm0
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%r15
cmp    %r15,%r12
jne    1280 <txtarray_write2+0x130>
cmpl   $0x0,0x70(%rsp)
mov    0x30(%rsp),%r15
jle    1230 <txtarray_write2+0xe0>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsd  (%r15,%rbp,8),%xmm0
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    12b0 <txtarray_write2+0x160>
jmp    1230 <txtarray_write2+0xe0>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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