#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);
int /*<<< orphan*/ printError(char *);
int /*<<< orphan*/ printf(char *, int, char *);
void outputMatrix(char *outfile, int *matrix, int *filecounter) {
  FILE *out;
  int i;
  if ((out = fopen(outfile, "wb")) == NULL) {
    printError("error while opening output file");
  }
  for (i = 0; i < *filecounter; i++) {
    fprintf(out, "Element #%d located on memory address %d\n", i + 1,
            matrix[i]);
  }
  fclose(out);
  printf("BigExtract: successfully written %d entries to %s\n", *filecounter,
         outfile);
}


x86 assembly (clang, -O0):
<outputMatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    118e <outputMatrix+0x3e>
lea    0xe7a(%rip),%rdi
call   1070 <printError@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    11d3 <outputMatrix+0x83>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xe63(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1195 <outputMatrix+0x45>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rdx
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<outputMatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
je     1181 <outputMatrix+0x31>
cmpl   $0x0,(%r12)
jg     1194 <outputMatrix+0x44>
jmp    11be <outputMatrix+0x6e>
lea    0xe7b(%rip),%rdi
call   1070 <printError@plt>
cmpl   $0x0,(%r12)
jle    11be <outputMatrix+0x6e>
xor    %ebx,%ebx
lea    0xe86(%rip),%rbp
nopl   (%rax)
mov    (%r15,%rbx,4),%ecx
add    $0x1,%rbx
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1050 <fprintf@plt>
movslq (%r12),%rax
cmp    %rax,%rbx
jl     11a0 <outputMatrix+0x50>
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    (%r12),%esi
lea    0xe7c(%rip),%rdi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [32 x i8] c"error while opening output file\00"
@.str.2 = [42 x i8] c"Element #%d located on memory address %d\0A\00"
@.str.3 = [51 x i8] c"BigExtract: successfully written %d entries to %s\0A\00"
define void @outputMatrix(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 ([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 %14
12: ; preds = %3
%13 = call i32 @printError(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %3
store i32 0, i32* %8
br label %15
15: ; preds = %30, %14
%16 = load i32, i32* %8
%17 = load i32*, i32** %6
%18 = load i32, i32* %17
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %33
20: ; preds = %15
%21 = load i32*, i32** %7
%22 = load i32, i32* %8
%23 = add nsw i32 %22, 1
%24 = load i32*, i32** %5
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %28)
br label %30
30: ; preds = %20
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %15
33: ; preds = %15
%34 = load i32*, i32** %7
%35 = call i32 @fclose(i32* %34)
%36 = load i32*, i32** %6
%37 = load i32, i32* %36
%38 = load i8*, i8** %4
%39 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %37, i8* %38)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [32 x i8] c"error while opening output file\00"
@.str.2 = [42 x i8] c"Element #%d located on memory address %d\0A\00"
@.str.3 = [51 x i8] c"BigExtract: successfully written %d entries to %s\0A\00"
define void @outputMatrix(i8* %0, i32* nocapture %1, i32* nocapture %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 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 @printError(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %3
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %8, %11
%12 = phi i64 [ %13, %11 ], [ 0, %8 ]
%13 = add nuw nsw i64 %12, 1
%14 = getelementptr inbounds i32, i32* %1, i64 %12
%15 = load i32, i32* %14
%16 = trunc i64 %13 to i32
%17 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 %15)
%18 = load i32, i32* %2
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %13, %19
br i1 %20, label %11, label %21
21: ; preds = %11, %8
%22 = tail call i32 @fclose(i32* %4)
%23 = load i32, i32* %2
%24 = tail call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %23, i8* %0)
ret void
}