#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 /*<<< orphan*/ printf(char *);
void writeIter(int *result, int startNumber, int endNumber, char *filename) {
  FILE *fp;
  fp = fopen(filename, "w+");
  if (fp == NULL)
    printf("File opening was not successful.");
  fprintf(fp, "  Number of steps\n\n");
  int iNumber;
  for (iNumber = startNumber; iNumber <= endNumber; iNumber++)
    fprintf(fp, "  %d\n", result[iNumber - startNumber]);
  fclose(fp);
}


x86 assembly (clang, -O0):
<writeIter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1181 <writeIter+0x41>
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe98(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11d5 <writeIter+0x95>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1199 <writeIter+0x59>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeIter>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xe99(%rip),%rsi
mov    %rcx,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1183 <writeIter+0x33>
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
lea    0xe9a(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
cmp    %r15d,%ebp
jg     11da <writeIter+0x8a>
sub    %ebp,%r15d
add    $0x1,%r15d
lea    0xe89(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbp,4),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%rbp
cmp    %ebp,%r15d
jne    11c0 <writeIter+0x70>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"w+\00"
@.str.1 = [33 x i8] c"File opening was not successful.\00"
@.str.2 = [20 x i8] c" Number of steps\0A\0A\00"
@.str.3 = [6 x i8] c" %d\0A\00"
define void @writeIter(i32* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%11 = load i8*, i8** %8
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %9
%13 = load i32*, i32** %9
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %4
%18 = load i32*, i32** %9
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* %6
store i32 %20, i32* %10
br label %21
21: ; preds = %35, %17
%22 = load i32, i32* %10
%23 = load i32, i32* %7
%24 = icmp sle i32 %22, %23
br i1 %24, label %25, label %38
25: ; preds = %21
%26 = load i32*, i32** %9
%27 = load i32*, i32** %5
%28 = load i32, i32* %10
%29 = load i32, i32* %6
%30 = sub nsw i32 %28, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %27, i64 %31
%33 = load i32, i32* %32
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %25
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
br label %21
38: ; preds = %21
%39 = load i32*, i32** %9
%40 = call i32 @fclose(i32* %39)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
@.str.1 = [33 x i8] c"File opening was not successful.\00"
@.str.2 = [20 x i8] c" Number of steps\0A\0A\00"
@.str.3 = [6 x i8] c" %d\0A\00"
define void @writeIter(i32* nocapture %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %4
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 19, i64 1, i32* %5)
%11 = icmp sgt i32 %1, %2
br i1 %11, label %24, label %12
12: ; preds = %9
%13 = sext i32 %1 to i64
%14 = add i32 %2, 1
br label %15
15: ; preds = %12, %15
%16 = phi i64 [ %13, %12 ], [ %21, %15 ]
%17 = sub nsw i64 %16, %13
%18 = getelementptr inbounds i32, i32* %0, i64 %17
%19 = load i32, i32* %18
%20 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = add nsw i64 %16, 1
%22 = trunc i64 %21 to i32
%23 = icmp eq i32 %14, %22
br i1 %23, label %24, label %15
24: ; preds = %15, %9
%25 = tail call i32 @fclose(i32* %5)
ret void
}