#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*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned long long);
void write_file(unsigned long long *arr, int size, char *path) {
  FILE *fp = fopen(path, "w+");
  char tmp[255];
  unsigned long i;
  for (i = 0; i < size; i++) {
    sprintf(tmp, "%llu\n", *(arr + i));
    fputs(tmp, fp);
  }
  if (fp) {
    fclose(fp);
  }
  return;
}


x86 assembly (clang, -O0):
<write_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe9f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x128(%rbp)
mov    -0x128(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmp    %rcx,%rax
jae    11d2 <write_file+0x92>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x128(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe5d(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <fputs@plt>
mov    -0x128(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x128(%rbp)
jmp    1175 <write_file+0x35>
cmpq   $0x0,-0x20(%rbp)
je     11e6 <write_file+0xa6>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xea3(%rip),%rsi
mov    %rdx,%rdi
call   1050 <fopen@plt>
mov    %rax,%r12
test   %ebx,%ebx
je     11a3 <write_file+0x63>
movslq %ebx,%r13
xor    %ebp,%ebp
lea    0xe8b(%rip),%r15
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbp,8),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <fputs@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1180 <write_file+0x40>
test   %r12,%r12
je     11c1 <write_file+0x81>
mov    %r12,%rdi
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
@.str.1 = [6 x i8] c"%llu\0A\00"
define void @write_file(i64* nocapture %0, i32 %1, i8* nocapture %2) {
%4 = alloca [255 x i8]
%5 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %1, 0
br i1 %7, label %18, label %8
8: ; preds = %3
%9 = sext i32 %1 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ %16, %10 ], [ 0, %8 ]
%12 = getelementptr inbounds i64, i64* %0, i64 %11
%13 = load i64, i64* %12
%14 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %13)
%15 = call i32 @fputs(i8* %6, i32* %5)
%16 = add nuw i64 %11, 1
%17 = icmp eq i64 %16, %9
br i1 %17, label %18, label %10
18: ; preds = %10, %3
%19 = icmp eq i32* %5, null
br i1 %19, label %22, label %20
20: ; preds = %18
%21 = tail call i32 @fclose(i32* %5)
br label %22
22: ; preds = %20, %18
ret void
}