#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);
int /*<<< orphan*/ printf(char *, char *);
void save_ivector(char *output_filename, int *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);
  for (i = 1; i <= n; i++)
    fprintf(output_file, "%d\n", data[i]);
  fclose(output_file);
}


x86 assembly (clang, -O0):
<save_ivector>:
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    1182 <save_ivector+0x42>
mov    -0x8(%rbp),%rsi
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11be <save_ivector+0x7e>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe81(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1189 <save_ivector+0x49>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_ivector>:
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>
mov    %rax,%r13
test   %rax,%rax
je     116d <save_ivector+0x2d>
test   %r15d,%r15d
jg     1181 <save_ivector+0x41>
jmp    11b8 <save_ivector+0x78>
lea    0xe8e(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
test   %r15d,%r15d
jle    11b8 <save_ivector+0x78>
add    $0x1,%r15d
mov    $0x1,%ebx
lea    0xe9b(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbx,4),%edx
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11a0 <save_ivector+0x60>
mov    %r13,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <fclose@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 = [4 x i8] c"%d\0A\00"
define void @save_ivector(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %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 %16
16: ; preds = %13, %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 i32*, i32** %5
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = call i32 @fprintf(i32* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %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)
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 = [4 x i8] c"%d\0A\00"
define void @save_ivector(i8* %0, i32* 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 %6, label %8
6: ; preds = %3
%7 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %8
8: ; preds = %6, %3
%9 = icmp slt i32 %2, 1
br i1 %9, label %20, label %10
10: ; preds = %8
%11 = add nuw i32 %2, 1
%12 = zext i32 %11 to i64
br label %13
13: ; preds = %10, %13
%14 = phi i64 [ 1, %10 ], [ %18, %13 ]
%15 = getelementptr inbounds i32, i32* %1, i64 %14
%16 = load i32, i32* %15
%17 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = add nuw nsw i64 %14, 1
%19 = icmp eq i64 %18, %12
br i1 %19, label %20, label %13
20: ; preds = %13, %8
%21 = tail call i32 @fclose(i32* %4)
ret void
}