#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*/ fwrite(double *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, ...);
void dump_vorticity_c(char *dname, char *fname, int nx, int ny, int nz,
                      double *array) {
  int i, j, k;
  FILE *fp;
  char errmsg[256];
  char buf[256];
  snprintf(buf, 256, "%s/%s.bov", dname, fname);
  fp = fopen(buf, "wb");
  if (fp == NULL) {
    snprintf(errmsg, 256, "WARNING: Unable to create BOV file (%s)", buf);
    perror(errmsg);
    return;
  }
  snprintf(buf, 256, "%s.dat", fname);
  fprintf(fp, "VARIABLE: vorticity\n");
  fprintf(fp, "DATA_FILE: %s\n", buf);
  fprintf(fp, "DATA_SIZE: %d %d %d\n", nx, ny, nz);
  fprintf(fp, "DATA_COMPONENTS: 1\n");
  fprintf(fp, "DATA_FORMAT: DOUBLE\n");
  fprintf(fp, "DATA_ENDIAN: LITTLE\n");
  fclose(fp);
  snprintf(buf, 256, "%s/%s.dat", dname, fname);
  fp = fopen(buf, "wb");
  if (fp == NULL) {
    snprintf(errmsg, 256, "WARNING: Unable to create DAT file (%s)", buf);
    perror(errmsg);
    return;
  }
  fwrite(array, sizeof(double), nx * ny * nz, fp);
  fclose(fp);
}


x86 assembly (clang, -O0):
<dump_vorticity_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9,-0x28(%rbp)
lea    -0x240(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    $0x100,%esi
lea    0xe64(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x240(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11f7 <dump_vorticity_c+0x97>
lea    -0x140(%rbp),%rdi
lea    -0x240(%rbp),%rcx
mov    $0x100,%esi
lea    0xe2e(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x140(%rbp),%rdi
call   1070 <perror@plt>
jmp    1337 <dump_vorticity_c+0x1d7>
lea    -0x240(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x100,%esi
lea    0xea1(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x40(%rbp),%rdi
lea    0xe15(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
lea    -0x240(%rbp),%rdx
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x240(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    $0x100,%esi
lea    0xdf6(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x240(%rbp),%rdi
lea    0xd3f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1311 <dump_vorticity_c+0x1b1>
lea    -0x140(%rbp),%rdi
lea    -0x240(%rbp),%rcx
mov    $0x100,%esi
lea    0xdbd(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x140(%rbp),%rdi
call   1070 <perror@plt>
jmp    1337 <dump_vorticity_c+0x1d7>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
imul   -0x18(%rbp),%edx
imul   -0x1c(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    $0x8,%esi
call   1080 <fwrite@plt>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_vorticity_c>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %r9,%r14
mov    %r8d,0x4(%rsp)
mov    %ecx,%ebx
mov    %edx,(%rsp)
mov    %rsi,%r12
mov    %rdi,%r13
lea    0xe75(%rip),%rdx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %r13,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xe5e(%rip),%rsi
mov    %rbp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     12e8 <dump_vorticity_c+0x188>
mov    %rax,%r15
mov    %r14,0x8(%rsp)
lea    0xee3(%rip),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x100,%esi
mov    %r12,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xe4b(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1080 <fwrite@plt>
lea    0xe47(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe42(%rip),%rsi
mov    %r15,%rdi
mov    (%rsp),%edx
mov    %ebx,%ecx
mov    0x4(%rsp),%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe3c(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1080 <fwrite@plt>
lea    0xe37(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1080 <fwrite@plt>
lea    0xe33(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1080 <fwrite@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
lea    0xe27(%rip),%rdx
mov    %r14,%rdi
mov    $0x100,%esi
mov    %r13,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xd69(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     12f1 <dump_vorticity_c+0x191>
mov    %rax,%rbp
imul   (%rsp),%ebx
imul   0x4(%rsp),%ebx
mov    0x8(%rsp),%rdi
mov    $0x8,%esi
mov    %ebx,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd1e(%rip),%rdx
jmp    12f8 <dump_vorticity_c+0x198>
lea    0xdbe(%rip),%rdx
lea    0x110(%rsp),%rbx
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x100,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1070 <perror@plt>
jmp    12d6 <dump_vorticity_c+0x176>

LLVM IR (-O0):
@.str = [10 x i8] c"%s/%s.bov\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [40 x i8] c"WARNING: Unable to create BOV file (%s)\00"
@.str.3 = [7 x i8] c"%s.dat\00"
@.str.4 = [21 x i8] c"VARIABLE: vorticity\0A\00"
@.str.5 = [15 x i8] c"DATA_FILE: %s\0A\00"
@.str.6 = [21 x i8] c"DATA_SIZE: %d %d %d\0A\00"
@.str.7 = [20 x i8] c"DATA_COMPONENTS: 1\0A\00"
@.str.8 = [21 x i8] c"DATA_FORMAT: DOUBLE\0A\00"
@.str.9 = [21 x i8] c"DATA_ENDIAN: LITTLE\0A\00"
@.str.10 = [10 x i8] c"%s/%s.dat\00"
@.str.11 = [40 x i8] c"WARNING: Unable to create DAT file (%s)\00"
define void @dump_vorticity_c(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, double* %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32*
%17 = alloca [256 x i8]
%18 = alloca [256 x i8]
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store double* %5, double** %12
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%20 = load i8*, i8** %7
%21 = load i8*, i8** %8
%22 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %19, i32 256, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %21)
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %16
%25 = load i32*, i32** %16
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %33
27: ; preds = %6
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%30 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %28, i32 256, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%32 = call i32 @perror(i8* %31)
br label %80
33: ; preds = %6
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%35 = load i8*, i8** %8
%36 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %34, i32 256, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %35)
%37 = load i32*, i32** %16
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%39 = load i32*, i32** %16
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %40)
%42 = load i32*, i32** %16
%43 = load i32, i32* %9
%44 = load i32, i32* %10
%45 = load i32, i32* %11
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %43, i32 %44, i32 %45)
%47 = load i32*, i32** %16
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%49 = load i32*, i32** %16
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%51 = load i32*, i32** %16
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%53 = load i32*, i32** %16
%54 = call i32 @fclose(i32* %53)
%55 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%56 = load i8*, i8** %7
%57 = load i8*, i8** %8
%58 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %55, i32 256, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %56, i8* %57)
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%60 = call i32* @fopen(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %60, i32** %16
%61 = load i32*, i32** %16
%62 = icmp eq i32* %61, null
br i1 %62, label %63, label %69
63: ; preds = %33
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%65 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%66 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %64, i32 256, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.11, i64 0, i64 0), i8* %65)
%67 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%68 = call i32 @perror(i8* %67)
br label %80
69: ; preds = %33
%70 = load double*, double** %12
%71 = load i32, i32* %9
%72 = load i32, i32* %10
%73 = mul nsw i32 %71, %72
%74 = load i32, i32* %11
%75 = mul nsw i32 %73, %74
%76 = load i32*, i32** %16
%77 = call i32 @fwrite(double* %70, i32 8, i32 %75, i32* %76)
%78 = load i32*, i32** %16
%79 = call i32 @fclose(i32* %78)
br label %80
80: ; preds = %69, %63, %27
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"%s/%s.bov\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [40 x i8] c"WARNING: Unable to create BOV file (%s)\00"
@.str.3 = [7 x i8] c"%s.dat\00"
@.str.4 = [21 x i8] c"VARIABLE: vorticity\0A\00"
@.str.5 = [15 x i8] c"DATA_FILE: %s\0A\00"
@.str.6 = [21 x i8] c"DATA_SIZE: %d %d %d\0A\00"
@.str.7 = [20 x i8] c"DATA_COMPONENTS: 1\0A\00"
@.str.8 = [21 x i8] c"DATA_FORMAT: DOUBLE\0A\00"
@.str.9 = [21 x i8] c"DATA_ENDIAN: LITTLE\0A\00"
@.str.10 = [10 x i8] c"%s/%s.dat\00"
@.str.11 = [40 x i8] c"WARNING: Unable to create DAT file (%s)\00"
define void @dump_vorticity_c(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, double* nocapture %5) {
%7 = alloca [256 x i8]
%8 = alloca [256 x i8]
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%11 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %10, i32 256, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%12 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %6
%15 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %9, i32 256, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%16 = call i32 @perror(i8* %9)
br label %37
17: ; preds = %6
%18 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %10, i32 256, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%19 = call i64 bitcast (i32 (double*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i64 20, i64 1, i32* %12)
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %10)
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %2, i32 %3, i32 %4)
%22 = call i64 bitcast (i32 (double*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i64 19, i64 1, i32* %12)
%23 = call i64 bitcast (i32 (double*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i64 20, i64 1, i32* %12)
%24 = call i64 bitcast (i32 (double*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i64 20, i64 1, i32* %12)
%25 = call i32 @fclose(i32* %12)
%26 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %10, i32 256, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %0, i8* %1)
%27 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %32
29: ; preds = %17
%30 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %9, i32 256, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.11, i64 0, i64 0), i8* %10)
%31 = call i32 @perror(i8* %9)
br label %37
32: ; preds = %17
%33 = mul nsw i32 %3, %2
%34 = mul nsw i32 %33, %4
%35 = call i32 @fwrite(double* %5, i32 8, i32 %34, i32* %27)
%36 = call i32 @fclose(i32* %27)
br label %37
37: ; preds = %32, %29, %14
ret void
}