#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 const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, float);
int /*<<< orphan*/ printf(char *, char const *);
void savePlotFile(const char *plot_file_name, float d_sampled_p0, int *out_step,
                  int *out_level, float *out_pressure, int wav_sample_count) {
  FILE *fw;
  fw = fopen(plot_file_name, "w");
  if (fw == NULL) {
    printf("Can't open output plot file: %s\n", plot_file_name);
    exit(-1);
  }
  for (int i = 0; i < wav_sample_count; i++) {
    fprintf(fw, "%d %d %e\n", out_step[i], out_level[i],
            out_pressure[i] - d_sampled_p0);
  }
  fclose(fw);
}


x86 assembly (clang, -O0):
<savePlotFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11aa <savePlotFile+0x5a>
mov    -0x8(%rbp),%rsi
lea    0xe67(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1203 <savePlotFile+0xb3>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rsi
movss  (%rax,%rsi,4),%xmm0
subss  -0xc(%rbp),%xmm0
lea    0xe33(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11b1 <savePlotFile+0x61>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<savePlotFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%ebp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
movss  %xmm0,0x4(%rsp)
mov    %rdi,%r13
lea    0xe89(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e6 <savePlotFile+0x96>
mov    %rax,%rbx
test   %ebp,%ebp
movss  0x4(%rsp),%xmm1
jle    11d0 <savePlotFile+0x80>
mov    %ebp,%ebp
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12,%r13,4),%edx
mov    (%r15,%r13,4),%ecx
movss  (%r14,%r13,4),%xmm0
subss  %xmm1,%xmm0
mov    %rbx,%rdi
lea    0xe67(%rip),%rsi
call   1050 <fprintf@plt>
movss  0x4(%rsp),%xmm1
add    $0x1,%r13
cmp    %r13,%rbp
jne    11a0 <savePlotFile+0x50>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
lea    0xe15(%rip),%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [33 x i8] c"Can't open output plot file: %s\0A\00"
@.str.2 = [10 x i8] c"%d %d %e\0A\00"
define void @savePlotFile(i8* %0, float %1, i32* nocapture %2, i32* nocapture %3, float* nocapture %4, i32 %5) {
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %13, label %9
9: ; preds = %6
%10 = icmp sgt i32 %5, 0
br i1 %10, label %11, label %16
11: ; preds = %9
%12 = zext i32 %5 to i64
br label %18
13: ; preds = %6
%14 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %18, %9
%17 = tail call i32 @fclose(i32* %7)
ret void
18: ; preds = %11, %18
%19 = phi i64 [ 0, %11 ], [ %28, %18 ]
%20 = getelementptr inbounds i32, i32* %2, i64 %19
%21 = load i32, i32* %20
%22 = getelementptr inbounds i32, i32* %3, i64 %19
%23 = load i32, i32* %22
%24 = getelementptr inbounds float, float* %4, i64 %19
%25 = load float, float* %24
%26 = fsub float %25, %1
%27 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 %23, float %26)
%28 = add nuw nsw i64 %19, 1
%29 = icmp eq i64 %28, %12
br i1 %29, label %16, label %18
}