#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);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double, double const);
int /*<<< orphan*/ printf(char *, char const *);
void dwrite_ascfile_c_(const char *ascfile, double *t0, double *dt, int *n,
                       const double *data) {
  FILE *fd;
  int i;
  double tmp, tmp0;
  if ((fd = fopen(ascfile, "w")) == NULL) {
    printf(" file %s cannot be opened to write\n", ascfile);
    exit(1);
  }
  i = 0;
  tmp = *dt;
  tmp0 = *t0;
  for (i = 0; i < *n; i++) {
    fprintf(fd, "% .7f  \t  %f\n", tmp0 + i * tmp, data[i]);
  }
  if (fclose(fd) != 0) {
    printf("file %s cannot be closed\n", ascfile);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<dwrite_ascfile_c_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11a4 <dwrite_ascfile_c_+0x54>
mov    -0x8(%rbp),%rsi
lea    0xe6d(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jge    121d <dwrite_ascfile_c_+0xcd>
mov    -0x30(%rbp),%rdi
movsd  -0x48(%rbp),%xmm1
cvtsi2sdl -0x34(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xe1c(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11cc <dwrite_ascfile_c_+0x7c>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     124a <dwrite_ascfile_c_+0xfa>
mov    -0x8(%rbp),%rsi
lea    0xdf9(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dwrite_ascfile_c_>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%rbp
mov    %rsi,%r13
mov    %rdi,%r14
lea    0xe8c(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11fd <dwrite_ascfile_c_+0xad>
mov    %rax,%rbx
cmpl   $0x0,(%r12)
jle    11e1 <dwrite_ascfile_c_+0x91>
movsd  0x0(%rbp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x0(%r13),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %ebp,%ebp
lea    0xe7e(%rip),%r13
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  (%r15,%rbp,8),%xmm1
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <fprintf@plt>
add    $0x1,%rbp
movslq (%r12),%rax
cmp    %rax,%rbp
jl     11b0 <dwrite_ascfile_c_+0x60>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
jne    1206 <dwrite_ascfile_c_+0xb6>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdfe(%rip),%rdi
jmp    120d <dwrite_ascfile_c_+0xbd>
lea    0xe27(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [36 x i8] c" file %s cannot be opened to write\0A\00"
@.str.2 = [14 x i8] c"% .7f \09 %f\0A\00"
@.str.3 = [26 x i8] c"file %s cannot be closed\0A\00"
define void @dwrite_ascfile_c_(i8* %0, double* %1, double* %2, i32* %3, double* %4) {
%6 = alloca i8*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32*
%10 = alloca double*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca double
%14 = alloca double
store i8* %0, i8** %6
store double* %1, double** %7
store double* %2, double** %8
store i32* %3, i32** %9
store double* %4, double** %10
%15 = load i8*, i8** %6
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %11
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %5
%19 = load i8*, i8** %6
%20 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %5
store i32 0, i32* %12
%23 = load double*, double** %8
%24 = load double, double* %23
store double %24, double* %13
%25 = load double*, double** %7
%26 = load double, double* %25
store double %26, double* %14
store i32 0, i32* %12
br label %27
27: ; preds = %45, %22
%28 = load i32, i32* %12
%29 = load i32*, i32** %9
%30 = load i32, i32* %29
%31 = icmp slt i32 %28, %30
br i1 %31, label %32, label %48
32: ; preds = %27
%33 = load i32*, i32** %11
%34 = load double, double* %14
%35 = load i32, i32* %12
%36 = sitofp i32 %35 to double
%37 = load double, double* %13
%38 = call double @llvm.fmuladd.f64(double %36, double %37, double %34)
%39 = load double*, double** %10
%40 = load i32, i32* %12
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double, double* %42
%44 = call i32 @fprintf(i32* %33, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %38, double %43)
br label %45
45: ; preds = %32
%46 = load i32, i32* %12
%47 = add nsw i32 %46, 1
store i32 %47, i32* %12
br label %27
48: ; preds = %27
%49 = load i32*, i32** %11
%50 = call i64 @fclose(i32* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = load i8*, i8** %6
%54 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %53)
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %48
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [36 x i8] c" file %s cannot be opened to write\0A\00"
@.str.2 = [14 x i8] c"% .7f \09 %f\0A\00"
@.str.3 = [26 x i8] c"file %s cannot be closed\0A\00"
define void @dwrite_ascfile_c_(i8* %0, double* nocapture %1, double* nocapture %2, i32* nocapture %3, double* nocapture %4) {
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %5
%12 = load double, double* %2
%13 = load double, double* %1
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %11, %16
%17 = phi i64 [ %24, %16 ], [ 0, %11 ]
%18 = trunc i64 %17 to i32
%19 = sitofp i32 %18 to double
%20 = tail call double @llvm.fmuladd.f64(double %19, double %12, double %13)
%21 = getelementptr inbounds double, double* %4, i64 %17
%22 = load double, double* %21
%23 = tail call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %20, double %22)
%24 = add nuw nsw i64 %17, 1
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %24, %26
br i1 %27, label %16, label %28
28: ; preds = %16, %11
%29 = tail call i64 @fclose(i32* %6)
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %28
ret void
}