#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fwrite(double *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ lg(char *, ...);
void ddump_bin(char *fname, double *vec, int M, int N, int N1) {
  int m;
  FILE *fp;
  lg("Writing to %s\n", fname);
  fp = fopen(fname, "wb");
  for (m = 0; m < M; m++) {
    if (N != fwrite(vec, sizeof(double), N, fp)) {
      lg("Error\n");
      exit(1);
    }
    vec += N1;
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<ddump_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <lg@plt>
mov    -0x8(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1206 <ddump_bin+0xb6>
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x8,%esi
call   1070 <fwrite@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
je     11e3 <ddump_bin+0x93>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <lg@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1197 <ddump_bin+0x47>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ddump_bin>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r12d
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xe93(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <lg@plt>
lea    0xe91(%rip),%rsi
mov    %r15,%rdi
call   1050 <fopen@plt>
mov    %rax,%r15
test   %ebp,%ebp
jle    11c0 <ddump_bin+0x70>
movslq %r12d,%r12
shl    $0x3,%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x8,%esi
mov    %r14d,%edx
mov    %r15,%rcx
call   1070 <fwrite@plt>
cmp    %r14d,%eax
jne    11d0 <ddump_bin+0x80>
add    %r12,%rbx
add    $0xffffffff,%ebp
jne    11a0 <ddump_bin+0x50>
mov    %r15,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
lea    0xe3b(%rip),%rdi
xor    %eax,%eax
call   1040 <lg@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"Writing to %s\0A\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [7 x i8] c"Error\0A\00"
define void @ddump_bin(i8* %0, double* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
store i8* %0, i8** %6
store double* %1, double** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%13 = load i8*, i8** %6
%14 = call i32 (i8*, ...) @lg(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %6
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %12
store i32 0, i32* %11
br label %17
17: ; preds = %36, %5
%18 = load i32, i32* %11
%19 = load i32, i32* %8
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %39
21: ; preds = %17
%22 = load i32, i32* %9
%23 = load double*, double** %7
%24 = load i32, i32* %9
%25 = load i32*, i32** %12
%26 = call i32 @fwrite(double* %23, i32 8, i32 %24, i32* %25)
%27 = icmp ne i32 %22, %26
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = call i32 (i8*, ...) @lg(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %21
%32 = load i32, i32* %10
%33 = load double*, double** %7
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds double, double* %33, i64 %34
store double* %35, double** %7
br label %36
36: ; preds = %31
%37 = load i32, i32* %11
%38 = add nsw i32 %37, 1
store i32 %38, i32* %11
br label %17
39: ; preds = %17
%40 = load i32*, i32** %12
%41 = call i32 @fclose(i32* %40)
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"Writing to %s\0A\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [7 x i8] c"Error\0A\00"
define void @ddump_bin(i8* %0, double* nocapture %1, i32 %2, i32 %3, i32 %4) {
%6 = tail call i32 (i8*, ...) @lg(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %23
9: ; preds = %5
%10 = sext i32 %4 to i64
br label %11
11: ; preds = %9, %19
%12 = phi double* [ %1, %9 ], [ %20, %19 ]
%13 = phi i32 [ 0, %9 ], [ %21, %19 ]
%14 = tail call i32 @fwrite(double* %12, i32 8, i32 %3, i32* %7)
%15 = icmp eq i32 %14, %3
br i1 %15, label %19, label %16
16: ; preds = %11
%17 = tail call i32 (i8*, ...) @lg(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %11
%20 = getelementptr inbounds double, double* %12, i64 %10
%21 = add nuw nsw i32 %13, 1
%22 = icmp eq i32 %21, %2
br i1 %22, label %23, label %11
23: ; preds = %19, %5
%24 = tail call i32 @fclose(i32* %7)
ret void
}