#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 *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ stderr;
void write_file(int *vett, int size, char *filename) {
  FILE *fp;
  int i;
  if ((fp = fopen(filename, "w+")) == NULL) {
    fprintf(stderr, "Errore apertura file in scrittura.\n");
    exit(-2);
  }
  for (i = 0; i < size; i++) {
    fprintf(fp, "%d\n", vett[i]);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<write_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1193 <write_file+0x53>
mov    0x2e68(%rip),%rax
movslq (%rax),%rdi
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0xfffffffe,%edi
call   1060 <exit@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d1 <write_file+0x91>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119a <write_file+0x5a>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xe9c(%rip),%rsi
mov    %rdx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11ba <write_file+0x6a>
mov    %rax,%r12
test   %ebp,%ebp
jle    11aa <write_file+0x5a>
mov    %ebp,%ebp
lea    0xea6(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14,%rbx,4),%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <write_file+0x40>
mov    %r12,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
mov    0x2e1f(%rip),%rax
movslq (%rax),%rcx
lea    0xe38(%rip),%rdi
mov    $0x23,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    $0xfffffffe,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"w+\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c"Errore apertura file in scrittura.\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define void @write_file(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %7
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = sext i32 %13 to i64
%15 = inttoptr i64 %14 to i32*
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 -2)
unreachable
18: ; preds = %3
store i32 0, i32* %8
br label %19
19: ; preds = %31, %18
%20 = load i32, i32* %8
%21 = load i32, i32* %5
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %34
23: ; preds = %19
%24 = load i32*, i32** %7
%25 = load i32*, i32** %4
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load i32, i32* %28
%30 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %23
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
br label %19
34: ; preds = %19
%35 = load i32*, i32** %7
%36 = call i32 @fclose(i32* %35)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c"Errore apertura file in scrittura.\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define void @write_file(i32* nocapture %0, i32 %1, i8* nocapture %2) {
%4 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %23
8: ; preds = %6
%9 = zext i32 %1 to i64
br label %16
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32*
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i64 35, i64 1, i32* %13)
%15 = tail call i32 @exit(i32 -2)
unreachable
16: ; preds = %8, %16
%17 = phi i64 [ 0, %8 ], [ %21, %16 ]
%18 = getelementptr inbounds i32, i32* %0, i64 %17
%19 = load i32, i32* %18
%20 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = add nuw nsw i64 %17, 1
%22 = icmp eq i64 %21, %9
br i1 %22, label %23, label %16
23: ; preds = %16, %6
%24 = tail call i32 @fclose(i32* %4)
ret void
}