#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 /*<<< orphan*/ free(int *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int main() {
  FILE *data_file;
  char *data_file_path = "data.txt";
  FILE *pos_file;
  char *pos_file_path = "positive.txt";
  FILE *neg_file;
  char *neg_file_path = "negative.txt";
  data_file = fopen(data_file_path, "r");
  if (data_file == NULL) {
    puts("Error opening data file for reading!");
    return -1;
  }
  pos_file = fopen(pos_file_path, "w");
  if (pos_file == NULL) {
    puts("Error opening positives file for writing!");
    return -1;
  }
  neg_file = fopen(neg_file_path, "w");
  if (neg_file == NULL) {
    puts("Error opening negatives file for writing!");
    return -1;
  }
  int elements_num;
  fscanf(data_file, "%d", &elements_num);
  int *nums;
  nums = (int *)malloc(elements_num * sizeof(int));
  int index = 0;
  int pos = 0;
  int neg = 0;
  while (fscanf(data_file, "%d", &nums[index]) > 0) {
    if (nums[index] < 0)
      neg++;
    if (nums[index] > 0)
      pos++;
    index++;
  }
  fprintf(neg_file, "%d\n", neg);
  fprintf(pos_file, "%d\n", pos);
  int i;
  for (i = 0; i < elements_num; i++) {
    if (nums[i] < 0) {
      fprintf(neg_file, "%d\n", nums[i]);
    }
    if (nums[i] > 0) {
      fprintf(pos_file, "%d\n", nums[i]);
    }
  }
  fclose(data_file);
  fclose(pos_file);
  fclose(neg_file);
  free(nums);
  FILE *sum_file;
  sum_file = fopen("positive.txt", "r");
  if (sum_file == NULL)
    printf("Error opening positive.txt");
  int pos_num;
  fscanf(sum_file, "%d", &pos_num);
  int sum = 0;
  int val;
  for (i = 0; i < pos_num; i++) {
    fscanf(sum_file, "%d", &val);
    printf("%d ", val);
    sum += val;
  }
  printf("Sum is: %d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xf03(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe5d(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e7 <main+0x67>
lea    0xe42(%rip),%rdi
call   1040 <puts@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    147a <main+0x2fa>
mov    -0x28(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121e <main+0x9e>
lea    0xe32(%rip),%rdi
call   1040 <puts@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    147a <main+0x2fa>
mov    -0x38(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1255 <main+0xd5>
lea    0xe25(%rip),%rdi
call   1040 <puts@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    147a <main+0x2fa>
mov    -0x10(%rbp),%rdi
lea    0xe33(%rip),%rsi
lea    -0x3c(%rbp),%rdx
call   1070 <fscanf@plt>
movslq -0x3c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rdx
movslq -0x4c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xde8(%rip),%rsi
call   1070 <fscanf@plt>
cmp    $0x0,%rax
jle    12fe <main+0x17e>
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jge    12d5 <main+0x155>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jle    12f0 <main+0x170>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1291 <main+0x111>
mov    -0x30(%rbp),%rdi
mov    -0x54(%rbp),%edx
lea    0xdb1(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x50(%rbp),%edx
lea    0xd9e(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    13a4 <main+0x224>
mov    -0x48(%rbp),%rax
movslq -0x58(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jge    1364 <main+0x1e4>
mov    -0x30(%rbp),%rdi
mov    -0x48(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd5e(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x48(%rbp),%rax
movslq -0x58(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jle    1391 <main+0x211>
mov    -0x20(%rbp),%rdi
mov    -0x48(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd31(%rip),%rsi
call   1080 <fprintf@plt>
jmp    1396 <main+0x216>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    132b <main+0x1ab>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
lea    0xcd5(%rip),%rdi
lea    0xc40(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    13f8 <main+0x278>
lea    0xca5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x60(%rbp),%rdi
lea    0xc90(%rip),%rsi
lea    -0x64(%rbp),%rdx
call   1070 <fscanf@plt>
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x64(%rbp),%eax
jge    1462 <main+0x2e2>
mov    -0x60(%rbp),%rdi
lea    0xc62(%rip),%rsi
lea    -0x6c(%rbp),%rdx
call   1070 <fscanf@plt>
mov    -0x6c(%rbp),%esi
lea    0xc6d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x6c(%rbp),%eax
add    -0x68(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    141a <main+0x29a>
mov    -0x68(%rbp),%esi
lea    0xc49(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe6b(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     126d <main+0xed>
mov    %rax,%r12
lea    0xef0(%rip),%rdi
lea    0xe82(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1276 <main+0xf6>
mov    %rax,%rbx
lea    0xe36(%rip),%rdi
lea    0xe63(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     127f <main+0xff>
mov    %rax,0x18(%rsp)
mov    %rbx,0x20(%rsp)
lea    0xe9a(%rip),%rbx
lea    0xc(%rsp),%rdx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <fscanf@plt>
mov    0xc(%rsp),%edi
shl    $0x2,%edi
call   1090 <malloc@plt>
mov    %rax,%r13
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1070 <fscanf@plt>
test   %rax,%rax
jle    1295 <main+0x115>
lea    0x4(%r13),%r15
xor    %ebx,%ebx
lea    0xe5b(%rip),%r14
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    -0x4(%r15),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %ecx,%ebx
xor    %ecx,%ecx
test   %eax,%eax
setg   %cl
add    %ecx,%ebp
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1070 <fscanf@plt>
add    $0x4,%r15
test   %rax,%rax
jg     1240 <main+0xc0>
jmp    1299 <main+0x119>
lea    0xda4(%rip),%rdi
jmp    1286 <main+0x106>
lea    0xdc2(%rip),%rdi
jmp    1286 <main+0x106>
lea    0xde3(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
jmp    13ed <main+0x26d>
xor    %ebp,%ebp
xor    %ebx,%ebx
lea    0xe1d(%rip),%r14
mov    0x18(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1080 <fprintf@plt>
mov    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1080 <fprintf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1321 <main+0x1a1>
xor    %ebp,%ebp
lea    0xde9(%rip),%r14
jmp    12ee <main+0x16e>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
cmp    %rax,%rbp
jge    1321 <main+0x1a1>
mov    0x0(%r13,%rbp,4),%edx
test   %edx,%edx
js     1300 <main+0x180>
test   %edx,%edx
jg     1314 <main+0x194>
jmp    12e0 <main+0x160>
nopl   (%rax)
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <fprintf@plt>
mov    0x0(%r13,%rbp,4),%edx
test   %edx,%edx
jle    12e0 <main+0x160>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <fprintf@plt>
jmp    12e0 <main+0x160>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r13,%rdi
call   1030 <free@plt>
lea    0xd5c(%rip),%rdi
lea    0xcc7(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    136a <main+0x1ea>
lea    0xd33(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd22(%rip),%rsi
lea    0x14(%rsp),%rdx
mov    %rbx,%rdi
call   1070 <fscanf@plt>
cmpl   $0x0,0x14(%rsp)
mov    $0x0,%ebp
jle    13db <main+0x25b>
lea    0xd02(%rip),%r15
lea    0x10(%rsp),%r12
lea    0xd14(%rip),%r13
xor    %ebp,%ebp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1070 <fscanf@plt>
mov    0x10(%rsp),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    0x10(%rsp),%ebp
add    $0x1,%r14d
cmp    0x14(%rsp),%r14d
jl     13b0 <main+0x230>
lea    0xcd3(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"data.txt\00"
@.str.1 = [13 x i8] c"positive.txt\00"
@.str.2 = [13 x i8] c"negative.txt\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [37 x i8] c"Error opening data file for reading!\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [42 x i8] c"Error opening positives file for writing!\00"
@.str.7 = [42 x i8] c"Error opening negatives file for writing!\00"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [4 x i8] c"%d\0A\00"
@.str.10 = [27 x i8] c"Error opening positive.txt\00"
@.str.11 = [4 x i8] c"%d \00"
@.str.12 = [12 x i8] c"Sum is: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8** %7
%18 = load i8*, i8** %3
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %19, i32** %2
%20 = load i32*, i32** %2
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = call i32 @puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %158
24: ; preds = %0
%25 = load i8*, i8** %5
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %26, i32** %4
%27 = load i32*, i32** %4
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %158
31: ; preds = %24
%32 = load i8*, i8** %7
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %33, i32** %6
%34 = load i32*, i32** %6
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 @puts(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %1
br label %158
38: ; preds = %31
%39 = load i32*, i32** %2
%40 = call i64 @fscanf(i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %8)
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = mul i64 %42, 4
%44 = trunc i64 %43 to i32
%45 = call i64 @malloc(i32 %44)
%46 = inttoptr i64 %45 to i32*
store i32* %46, i32** %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
br label %47
47: ; preds = %75, %38
%48 = load i32*, i32** %2
%49 = load i32*, i32** %9
%50 = load i32, i32* %10
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
%53 = call i64 @fscanf(i32* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %52)
%54 = icmp sgt i64 %53, 0
br i1 %54, label %55, label %78
55: ; preds = %47
%56 = load i32*, i32** %9
%57 = load i32, i32* %10
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %56, i64 %58
%60 = load i32, i32* %59
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %55
%63 = load i32, i32* %12
%64 = add nsw i32 %63, 1
store i32 %64, i32* %12
br label %65
65: ; preds = %62, %55
%66 = load i32*, i32** %9
%67 = load i32, i32* %10
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i32, i32* %66, i64 %68
%70 = load i32, i32* %69
%71 = icmp sgt i32 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %65
%73 = load i32, i32* %11
%74 = add nsw i32 %73, 1
store i32 %74, i32* %11
br label %75
75: ; preds = %72, %65
%76 = load i32, i32* %10
%77 = add nsw i32 %76, 1
store i32 %77, i32* %10
br label %47
78: ; preds = %47
%79 = load i32*, i32** %6
%80 = load i32, i32* %12
%81 = call i32 @fprintf(i32* %79, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %80)
%82 = load i32*, i32** %4
%83 = load i32, i32* %11
%84 = call i32 @fprintf(i32* %82, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %83)
store i32 0, i32* %13
br label %85
85: ; preds = %120, %78
%86 = load i32, i32* %13
%87 = load i32, i32* %8
%88 = icmp slt i32 %86, %87
br i1 %88, label %89, label %123
89: ; preds = %85
%90 = load i32*, i32** %9
%91 = load i32, i32* %13
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i32, i32* %90, i64 %92
%94 = load i32, i32* %93
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %104
96: ; preds = %89
%97 = load i32*, i32** %6
%98 = load i32*, i32** %9
%99 = load i32, i32* %13
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds i32, i32* %98, i64 %100
%102 = load i32, i32* %101
%103 = call i32 @fprintf(i32* %97, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %102)
br label %104
104: ; preds = %96, %89
%105 = load i32*, i32** %9
%106 = load i32, i32* %13
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds i32, i32* %105, i64 %107
%109 = load i32, i32* %108
%110 = icmp sgt i32 %109, 0
br i1 %110, label %111, label %119
111: ; preds = %104
%112 = load i32*, i32** %4
%113 = load i32*, i32** %9
%114 = load i32, i32* %13
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds i32, i32* %113, i64 %115
%117 = load i32, i32* %116
%118 = call i32 @fprintf(i32* %112, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %117)
br label %119
119: ; preds = %111, %104
br label %120
120: ; preds = %119
%121 = load i32, i32* %13
%122 = add nsw i32 %121, 1
store i32 %122, i32* %13
br label %85
123: ; preds = %85
%124 = load i32*, i32** %2
%125 = call i32 @fclose(i32* %124)
%126 = load i32*, i32** %4
%127 = call i32 @fclose(i32* %126)
%128 = load i32*, i32** %6
%129 = call i32 @fclose(i32* %128)
%130 = load i32*, i32** %9
%131 = call i32 @free(i32* %130)
%132 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %132, i32** %14
%133 = load i32*, i32** %14
%134 = icmp eq i32* %133, null
br i1 %134, label %135, label %137
135: ; preds = %123
%136 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
br label %137
137: ; preds = %135, %123
%138 = load i32*, i32** %14
%139 = call i64 @fscanf(i32* %138, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %15)
store i32 0, i32* %16
store i32 0, i32* %13
br label %140
140: ; preds = %152, %137
%141 = load i32, i32* %13
%142 = load i32, i32* %15
%143 = icmp slt i32 %141, %142
br i1 %143, label %144, label %155
144: ; preds = %140
%145 = load i32*, i32** %14
%146 = call i64 @fscanf(i32* %145, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %17)
%147 = load i32, i32* %17
%148 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i32 %147)
%149 = load i32, i32* %17
%150 = load i32, i32* %16
%151 = add nsw i32 %150, %149
store i32 %151, i32* %16
br label %152
152: ; preds = %144
%153 = load i32, i32* %13
%154 = add nsw i32 %153, 1
store i32 %154, i32* %13
br label %140
155: ; preds = %140
%156 = load i32, i32* %16
%157 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0), i32 %156)
store i32 0, i32* %1
br label %158
158: ; preds = %155, %36, %29, %22
%159 = load i32, i32* %1
ret i32 %159
}

LLVM IR (-O2):
@.str = [9 x i8] c"data.txt\00"
@.str.1 = [13 x i8] c"positive.txt\00"
@.str.2 = [13 x i8] c"negative.txt\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [37 x i8] c"Error opening data file for reading!\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [42 x i8] c"Error opening positives file for writing!\00"
@.str.7 = [42 x i8] c"Error opening negatives file for writing!\00"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [4 x i8] c"%d\0A\00"
@.str.10 = [27 x i8] c"Error opening positive.txt\00"
@.str.11 = [4 x i8] c"%d \00"
@.str.12 = [12 x i8] c"Sum is: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %96
8: ; preds = %0
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
br label %96
13: ; preds = %8
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0))
br label %96
18: ; preds = %13
%19 = bitcast i32* %1 to i8*
%20 = call i64 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %1)
%21 = load i32, i32* %1
%22 = shl i32 %21, 2
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i32*
%25 = call i64 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %24)
%26 = icmp sgt i64 %25, 0
br i1 %26, label %27, label %42
27: ; preds = %18, %27
%28 = phi i64 [ %38, %27 ], [ 0, %18 ]
%29 = phi i32* [ %39, %27 ], [ %24, %18 ]
%30 = phi i32 [ %34, %27 ], [ 0, %18 ]
%31 = phi i32 [ %37, %27 ], [ 0, %18 ]
%32 = load i32, i32* %29
%33 = lshr i32 %32, 31
%34 = add nuw nsw i32 %33, %30
%35 = icmp sgt i32 %32, 0
%36 = zext i1 %35 to i32
%37 = add nuw nsw i32 %31, %36
%38 = add nuw nsw i64 %28, 1
%39 = getelementptr inbounds i32, i32* %24, i64 %38
%40 = call i64 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %39)
%41 = icmp sgt i64 %40, 0
br i1 %41, label %27, label %42
42: ; preds = %27, %18
%43 = phi i32 [ 0, %18 ], [ %37, %27 ]
%44 = phi i32 [ 0, %18 ], [ %34, %27 ]
%45 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %44)
%46 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %43)
%47 = load i32, i32* %1
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %67
49: ; preds = %42, %62
%50 = phi i64 [ %63, %62 ], [ 0, %42 ]
%51 = getelementptr inbounds i32, i32* %24, i64 %50
%52 = load i32, i32* %51
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %49
%55 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %52)
%56 = load i32, i32* %51
br label %57
57: ; preds = %54, %49
%58 = phi i32 [ %56, %54 ], [ %52, %49 ]
%59 = icmp sgt i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %57
%61 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %58)
br label %62
62: ; preds = %57, %60
%63 = add nuw nsw i64 %50, 1
%64 = load i32, i32* %1
%65 = sext i32 %64 to i64
%66 = icmp slt i64 %63, %65
br i1 %66, label %49, label %67
67: ; preds = %62, %42
%68 = call i32 @fclose(i32* %4)
%69 = call i32 @fclose(i32* %9)
%70 = call i32 @fclose(i32* %14)
%71 = call i32 @free(i32* %24)
%72 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%73 = icmp eq i32* %72, null
br i1 %73, label %74, label %76
74: ; preds = %67
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
br label %76
76: ; preds = %74, %67
%77 = bitcast i32* %2 to i8*
%78 = call i64 @fscanf(i32* %72, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %2)
%79 = bitcast i32* %3 to i8*
%80 = load i32, i32* %2
%81 = icmp sgt i32 %80, 0
br i1 %81, label %82, label %93
82: ; preds = %76, %82
%83 = phi i32 [ %89, %82 ], [ 0, %76 ]
%84 = phi i32 [ %90, %82 ], [ 0, %76 ]
%85 = call i64 @fscanf(i32* %72, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %3)
%86 = load i32, i32* %3
%87 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i32 %86)
%88 = load i32, i32* %3
%89 = add nsw i32 %88, %83
%90 = add nuw nsw i32 %84, 1
%91 = load i32, i32* %2
%92 = icmp slt i32 %90, %91
br i1 %92, label %82, label %93
93: ; preds = %82, %76
%94 = phi i32 [ 0, %76 ], [ %89, %82 ]
%95 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0), i32 %94)
br label %96
96: ; preds = %93, %16, %11, %6
%97 = phi i32 [ -1, %6 ], [ -1, %11 ], [ -1, %16 ], [ 0, %93 ]
ret i32 %97
}