#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, long *);
int /*<<< orphan*/ system(char *);
long RunProcessFile(void) {
  char c;
  int i;
  long Value, SumValue;
  FILE *RunFile;
  SumValue = 0;
  for (i = 0; i < 3; i++) {
    system("./runtnt.sh cnd PN");
    RunFile = fopen("TRPN.txt", "r");
    while ((c = fgetc(RunFile)) != EOF)
      if (c == '#') {
        fscanf(RunFile, "%*i %*i %li", &Value);
        SumValue += Value;
      }
    fclose(RunFile);
  }
  SumValue /= 3;
  return SumValue;
}


x86 assembly (clang, -O0):
<RunProcessFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11fe <RunProcessFile+0xae>
lea    0xe88(%rip),%rdi
call   1040 <system@plt>
lea    0xe8f(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x1(%rbp)
movsbl %al,%eax
mov    0x2e3e(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11e7 <RunProcessFile+0x97>
movsbl -0x1(%rbp),%eax
cmp    $0x23,%eax
jne    11e2 <RunProcessFile+0x92>
mov    -0x20(%rbp),%rdi
lea    0xe51(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1194 <RunProcessFile+0x44>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1167 <RunProcessFile+0x17>
mov    -0x18(%rbp),%rax
mov    $0x3,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RunProcessFile>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe9c(%rip),%rdi
call   1040 <system@plt>
lea    0xea3(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <fgetc@plt>
mov    0x2e5a(%rip),%r13
cmp    0x0(%r13),%al
jne    1243 <RunProcessFile+0xf3>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe56(%rip),%rdi
call   1040 <system@plt>
lea    0xe5d(%rip),%rdi
lea    0xe5f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <fgetc@plt>
cmp    0x0(%r13),%al
jne    128b <RunProcessFile+0x13b>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe1a(%rip),%rdi
call   1040 <system@plt>
lea    0xe21(%rip),%rdi
lea    0xe23(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <fgetc@plt>
cmp    0x0(%r13),%al
jne    12cb <RunProcessFile+0x17b>
mov    %rbx,%rdi
call   1030 <fclose@plt>
movabs $0x5555555555555556,%rcx
55 55 55
mov    %r14,%rax
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
add    %rdx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xor    %r14d,%r14d
lea    0xdd1(%rip),%r15
lea    0x8(%rsp),%r12
jmp    1272 <RunProcessFile+0x122>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    0x0(%r13),%al
je     119b <RunProcessFile+0x4b>
cmp    $0x23,%al
jne    1260 <RunProcessFile+0x110>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
add    0x8(%rsp),%r14
jmp    1260 <RunProcessFile+0x110>
lea    0xd8c(%rip),%r15
lea    0x8(%rsp),%r12
jmp    12b2 <RunProcessFile+0x162>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    0x0(%r13),%al
je     11d7 <RunProcessFile+0x87>
cmp    $0x23,%al
jne    12a0 <RunProcessFile+0x150>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
add    0x8(%rsp),%r14
jmp    12a0 <RunProcessFile+0x150>
lea    0xd4c(%rip),%r15
lea    0x8(%rsp),%r12
jmp    12f2 <RunProcessFile+0x1a2>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    0x0(%r13),%al
je     1213 <RunProcessFile+0xc3>
cmp    $0x23,%al
jne    12e0 <RunProcessFile+0x190>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
add    0x8(%rsp),%r14
jmp    12e0 <RunProcessFile+0x190>

LLVM IR (-O0):
@.str = [19 x i8] c"./runtnt.sh cnd PN\00"
@.str.1 = [9 x i8] c"TRPN.txt\00"
@.str.2 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.3 = [12 x i8] c"%*i %*i %li\00"
define i64 @RunProcessFile() {
%1 = alloca i8
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32*
store i64 0, i64* %4
store i32 0, i32* %2
br label %6
6: ; preds = %33, %0
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %36
9: ; preds = %6
%10 = call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%11 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %11, i32** %5
br label %12
12: ; preds = %29, %9
%13 = load i32*, i32** %5
%14 = call signext i8 @fgetc(i32* %13)
store i8 %14, i8* %1
%15 = sext i8 %14 to i32
%16 = load i8, i8* @EOF
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %15, %17
br i1 %18, label %19, label %30
19: ; preds = %12
%20 = load i8, i8* %1
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 35
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i32*, i32** %5
%25 = call i32 @fscanf(i32* %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i64* %3)
%26 = load i64, i64* %3
%27 = load i64, i64* %4
%28 = add nsw i64 %27, %26
store i64 %28, i64* %4
br label %29
29: ; preds = %23, %19
br label %12
30: ; preds = %12
%31 = load i32*, i32** %5
%32 = call i32 @fclose(i32* %31)
br label %33
33: ; preds = %30
%34 = load i32, i32* %2
%35 = add nsw i32 %34, 1
store i32 %35, i32* %2
br label %6
36: ; preds = %6
%37 = load i64, i64* %4
%38 = sdiv i64 %37, 3
store i64 %38, i64* %4
%39 = load i64, i64* %4
ret i64 %39
}

LLVM IR (-O2):
@.str = [19 x i8] c"./runtnt.sh cnd PN\00"
@.str.1 = [9 x i8] c"TRPN.txt\00"
@.str.2 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.3 = [12 x i8] c"%*i %*i %li\00"
define i64 @RunProcessFile() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%4 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%5 = call signext i8 @fgetc(i32* %4)
%6 = load i8, i8* @EOF
%7 = icmp eq i8 %5, %6
br i1 %7, label %21, label %8
8: ; preds = %0, %16
%9 = phi i8 [ %18, %16 ], [ %5, %0 ]
%10 = phi i64 [ %17, %16 ], [ 0, %0 ]
%11 = icmp eq i8 %9, 35
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i64* %1)
%14 = load i64, i64* %1
%15 = add nsw i64 %14, %10
br label %16
16: ; preds = %12, %8
%17 = phi i64 [ %15, %12 ], [ %10, %8 ]
%18 = call signext i8 @fgetc(i32* %4)
%19 = load i8, i8* @EOF
%20 = icmp eq i8 %18, %19
br i1 %20, label %21, label %8
21: ; preds = %16, %0
%22 = phi i64 [ 0, %0 ], [ %17, %16 ]
%23 = call i32 @fclose(i32* %4)
%24 = call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%25 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = call signext i8 @fgetc(i32* %25)
%27 = load i8, i8* @EOF
%28 = icmp eq i8 %26, %27
br i1 %28, label %42, label %29
29: ; preds = %21, %37
%30 = phi i8 [ %39, %37 ], [ %26, %21 ]
%31 = phi i64 [ %38, %37 ], [ %22, %21 ]
%32 = icmp eq i8 %30, 35
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i64* %1)
%35 = load i64, i64* %1
%36 = add nsw i64 %35, %31
br label %37
37: ; preds = %33, %29
%38 = phi i64 [ %36, %33 ], [ %31, %29 ]
%39 = call signext i8 @fgetc(i32* %25)
%40 = load i8, i8* @EOF
%41 = icmp eq i8 %39, %40
br i1 %41, label %42, label %29
42: ; preds = %37, %21
%43 = phi i64 [ %22, %21 ], [ %38, %37 ]
%44 = call i32 @fclose(i32* %25)
%45 = call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%46 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%47 = call signext i8 @fgetc(i32* %46)
%48 = load i8, i8* @EOF
%49 = icmp eq i8 %47, %48
br i1 %49, label %63, label %50
50: ; preds = %42, %58
%51 = phi i8 [ %60, %58 ], [ %47, %42 ]
%52 = phi i64 [ %59, %58 ], [ %43, %42 ]
%53 = icmp eq i8 %51, 35
br i1 %53, label %54, label %58
54: ; preds = %50
%55 = call i32 @fscanf(i32* %46, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i64* %1)
%56 = load i64, i64* %1
%57 = add nsw i64 %56, %52
br label %58
58: ; preds = %54, %50
%59 = phi i64 [ %57, %54 ], [ %52, %50 ]
%60 = call signext i8 @fgetc(i32* %46)
%61 = load i8, i8* @EOF
%62 = icmp eq i8 %60, %61
br i1 %62, label %63, label %50
63: ; preds = %58, %42
%64 = phi i64 [ %43, %42 ], [ %59, %58 ]
%65 = call i32 @fclose(i32* %46)
%66 = sdiv i64 %64, 3
ret i64 %66
}