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


x86 assembly (clang, -O0):
<dump_velocity_component_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%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_velocity_component_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    1334 <dump_velocity_component_c+0x1d4>
lea    -0x240(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    $0x100,%esi
lea    0xe23(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
lea    -0x240(%rbp),%rdx
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
lea    0xe08(%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    $0x100,%esi
lea    0xd85(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x240(%rbp),%rdi
lea    0xd42(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    130e <dump_velocity_component_c+0x1ae>
lea    -0x140(%rbp),%rdi
lea    -0x240(%rbp),%rcx
mov    $0x100,%esi
lea    0xdb3(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x140(%rbp),%rdi
call   1070 <perror@plt>
jmp    1334 <dump_velocity_component_c+0x1d4>
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    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_velocity_component_c>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %r9,%r13
mov    %r8d,(%rsp)
mov    %ecx,%ebx
mov    %edx,0x4(%rsp)
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe75(%rip),%rdx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %r12,%rcx
mov    %r15,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xe5e(%rip),%rsi
mov    %rbp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     12e0 <dump_velocity_component_c+0x180>
mov    %rax,%r14
mov    %r13,0x8(%rsp)
lea    0xe69(%rip),%rdx
lea    0x10(%rsp),%r13
mov    %r13,%rdi
mov    $0x100,%esi
mov    %r12,%rcx
mov    %r15,%r8
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xe52(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe4c(%rip),%rsi
mov    %r14,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe47(%rip),%rsi
mov    %r14,%rdi
mov    0x4(%rsp),%r15d
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe3d(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
lea    0xe38(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
lea    0xe34(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
lea    0xdb7(%rip),%rdx
mov    %r13,%rdi
mov    $0x100,%esi
mov    %r12,%rcx
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0xd70(%rip),%rsi
mov    %r13,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     12e9 <dump_velocity_component_c+0x189>
mov    %rax,%rbp
imul   %r15d,%ebx
imul   (%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    0xd26(%rip),%rdx
jmp    12f0 <dump_velocity_component_c+0x190>
lea    0xdb9(%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    12ce <dump_velocity_component_c+0x16e>

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 = [10 x i8] c"%s_%s.dat\00"
@.str.4 = [14 x i8] c"VARIABLE: %s\0A\00"
@.str.5 = [15 x i8] c"DATA_FILE: %s\0A\00"
@.str.6 = [15 x i8] c"DATA_SIZE: %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 = [7 x i8] c"%s.dat\00"
@.str.11 = [40 x i8] c"WARNING: Unable to create DAT file (%s)\00"
define void @dump_velocity_component_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]
%19 = alloca double*
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
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%21 = load i8*, i8** %7
%22 = load i8*, i8** %8
%23 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %20, i32 256, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %22)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %16
%26 = load i32*, i32** %16
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %34
28: ; preds = %6
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%31 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %29, i32 256, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%33 = call i32 @perror(i8* %32)
br label %80
34: ; preds = %6
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%36 = load i8*, i8** %7
%37 = load i8*, i8** %8
%38 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %35, i32 256, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %36, i8* %37)
%39 = load i32*, i32** %16
%40 = load i8*, i8** %8
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %40)
%42 = load i32*, i32** %16
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %43)
%45 = load i32*, i32** %16
%46 = load i32, i32* %9
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %46)
%48 = load i32*, i32** %16
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%50 = load i32*, i32** %16
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%52 = load i32*, i32** %16
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%54 = load i32*, i32** %16
%55 = call i32 @fclose(i32* %54)
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%57 = load i8*, i8** %7
%58 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %56, i32 256, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), 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 = %34
%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 = %34
%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, %28
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 = [10 x i8] c"%s_%s.dat\00"
@.str.4 = [14 x i8] c"VARIABLE: %s\0A\00"
@.str.5 = [15 x i8] c"DATA_FILE: %s\0A\00"
@.str.6 = [15 x i8] c"DATA_SIZE: %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 = [7 x i8] c"%s.dat\00"
@.str.11 = [40 x i8] c"WARNING: Unable to create DAT file (%s)\00"
define void @dump_velocity_component_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 ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %1)
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%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 ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %2)
%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 ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i8* %0)
%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
}