#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 *, long);
int /*<<< orphan*/ printf(char *, char *);
void save_lvector(char *output_filename, long *data, int n) {
  int i;
  FILE *output_file;
  output_file = fopen(output_filename, "w");
  if (!output_file) {
    printf("I could not open the file %s for writing\n", output_filename);
  } else {
    for (i = 1; i <= n; i++)
      fprintf(output_file, "%ld\n", data[i]);
    fclose(output_file);
  }
}


x86 assembly (clang, -O0):
<save_lvector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1187 <save_lvector+0x47>
mov    -0x8(%rbp),%rsi
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
jmp    11cd <save_lvector+0x8d>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11c4 <save_lvector+0x84>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe7b(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118e <save_lvector+0x4e>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_lvector>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xea7(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a9 <save_lvector+0x69>
mov    %rax,%r13
test   %r15d,%r15d
jle    1198 <save_lvector+0x58>
add    $0x1,%r15d
mov    $0x1,%ebx
lea    0xeb1(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdx
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1180 <save_lvector+0x40>
mov    %r13,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
lea    0xe52(%rip),%rdi
mov    %r12,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [42 x i8] c"I could not open the file %s for writing\0A\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
define void @save_lvector(i8* %0, i64* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i8* %0, i8** %4
store i64* %1, i64** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %8
%11 = load i32*, i32** %8
%12 = icmp ne i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %35
16: ; preds = %3
store i32 1, i32* %7
br label %17
17: ; preds = %29, %16
%18 = load i32, i32* %7
%19 = load i32, i32* %6
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %32
21: ; preds = %17
%22 = load i32*, i32** %8
%23 = load i64*, i64** %5
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i64, i64* %23, i64 %25
%27 = load i64, i64* %26
%28 = call i32 @fprintf(i32* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %27)
br label %29
29: ; preds = %21
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %17
32: ; preds = %17
%33 = load i32*, i32** %8
%34 = call i32 @fclose(i32* %33)
br label %35
35: ; preds = %32, %13
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [42 x i8] c"I could not open the file %s for writing\0A\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
define void @save_lvector(i8* %0, i64* nocapture %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = icmp slt i32 %2, 1
br i1 %7, label %20, label %8
8: ; preds = %6
%9 = add nuw i32 %2, 1
%10 = zext i32 %9 to i64
br label %13
11: ; preds = %3
%12 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %22
13: ; preds = %8, %13
%14 = phi i64 [ 1, %8 ], [ %18, %13 ]
%15 = getelementptr inbounds i64, i64* %1, i64 %14
%16 = load i64, i64* %15
%17 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %16)
%18 = add nuw nsw i64 %14, 1
%19 = icmp eq i64 %18, %10
br i1 %19, label %20, label %13
20: ; preds = %13, %6
%21 = tail call i32 @fclose(i32* %4)
br label %22
22: ; preds = %20, %11
ret void
}