#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);
void save_ivec(char name[], int nvec, int *vec) {
  FILE *fnam = fopen(name, "w");
  for (int i = 0; i < nvec; ++i) {
    fprintf(fnam, "%d\n", vec[i]);
  }
  fclose(fnam);
}


x86 assembly (clang, -O0):
<save_ivec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1193 <save_ivec+0x63>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe82(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115e <save_ivec+0x2e>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_ivec>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebp
lea    0xebc(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r12
test   %ebp,%ebp
jle    1178 <save_ivec+0x48>
mov    %ebp,%ebp
xor    %ebx,%ebx
lea    0xea7(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbx,4),%edx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <save_ivec+0x30>
mov    %r12,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define void @save_ivec(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** %7
store i32 0, i32* %8
br label %11
11: ; preds = %23, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load i32*, i32** %7
%17 = load i32*, i32** %6
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %15
%24 = load i32, i32* %8
%25 = add nsw i32 %24, 1
store i32 %25, i32* %8
br label %11
26: ; preds = %11
%27 = load i32*, i32** %7
%28 = call i32 @fclose(i32* %27)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define void @save_ivec(i8* nocapture %0, i32 %1, i32* nocapture %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = zext i32 %1 to i64
br label %10
8: ; preds = %10, %3
%9 = tail call i32 @fclose(i32* %4)
ret void
10: ; preds = %6, %10
%11 = phi i64 [ 0, %6 ], [ %15, %10 ]
%12 = getelementptr inbounds i32, i32* %2, i64 %11
%13 = load i32, i32* %12
%14 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, %7
br i1 %16, label %8, label %10
}