#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 */
scalar_t__ EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *fp;
  FILE *fpass;
  FILE *ffail;
  char student[20];
  int mark;
  int total = 0;
  int num = 0;
  fp = fopen("marks.txt", "r");
  fpass = fopen("pass.txt", "w");
  ffail = fopen("fail.txt", "w");
  if (fp == NULL) {
    printf("Cannot open file.\n");
    exit(1);
  }
  while (fscanf(fp,
                "%s"
                "%d",
                student, &mark) != EOF) {
    if (mark >= 40) {
      printf("%s passed the exam ! \n", student);
      fprintf(fpass, "%s passed the exam ! \n", student);
    }
    if (mark < 40) {
      printf("%s failed the exam ! \n", student);
      fprintf(ffail, "%s failed the exam ! \n", student);
    }
    total = total + mark;
    num++;
  }
  printf("The total is: %d \n", total);
  printf("The number of students is: %d \n", num);
  printf("The average is: %f", (double)(total / num));
  fclose(fp);
  fclose(fpass);
  fclose(ffail);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
lea    0xe7c(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe71(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe65(%rip),%rdi
lea    0xe5c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e5 <main+0x85>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11ea <main+0x8a>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xe3a(%rip),%rsi
lea    -0x44(%rbp),%rcx
call   1050 <fscanf@plt>
mov    0x2ddf(%rip),%rcx
cmp    (%rcx),%rax
je     1289 <main+0x129>
cmpl   $0x28,-0x44(%rbp)
jl     1242 <main+0xe2>
lea    -0x40(%rbp),%rsi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xdfb(%rip),%rsi
call   1060 <fprintf@plt>
cmpl   $0x28,-0x44(%rbp)
jge    1272 <main+0x112>
lea    -0x40(%rbp),%rsi
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xde2(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x48(%rbp),%eax
add    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11ea <main+0x8a>
mov    -0x48(%rbp),%esi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4c(%rbp),%esi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%eax
cltd
idivl  -0x4c(%rbp)
cvtsi2sd %eax,%xmm0
lea    0xddc(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe7b(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
lea    0xe71(%rip),%rdi
lea    0xe73(%rip),%rbx
mov    %rbx,%rsi
call   1080 <fopen@plt>
mov    %rax,0x10(%rsp)
lea    0xe61(%rip),%rdi
mov    %rbx,%rsi
call   1080 <fopen@plt>
mov    %rax,0x18(%rsp)
test   %r12,%r12
je     1306 <main+0x196>
lea    0xe4d(%rip),%rsi
lea    0x20(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %r12,%rdi
call   1060 <fscanf@plt>
mov    0x2dfc(%rip),%rcx
xor    %ebp,%ebp
mov    $0x0,%ebx
cmp    (%rcx),%rax
jne    125c <main+0xec>
lea    0xe54(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe57(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%eax
cltd
idiv   %ebx
cvtsi2sd %eax,%xmm0
lea    0xe5e(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    0x10(%rsp),%rdi
call   1040 <fclose@plt>
mov    0x18(%rsp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x20(%rsp),%r14
lea    0xdb8(%rip),%r13
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    12c0 <main+0x150>
xchg   %ax,%ax
lea    0xdc5(%rip),%r15
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rsp),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    0xc(%rsp),%eax
add    %eax,%ebp
add    $0x1,%ebx
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
lea    0xc(%rsp),%rcx
call   1060 <fscanf@plt>
mov    0x2d31(%rip),%rcx
cmp    (%rcx),%rax
je     11f8 <main+0x88>
cmpl   $0x28,0xc(%rsp)
jl     1270 <main+0x100>
mov    %r12,%r15
mov    %r13,%r12
lea    0xd51(%rip),%r13
mov    %r13,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%rdi
mov    %r13,%rsi
mov    %r12,%r13
mov    %r15,%r12
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    0xc(%rsp),%eax
cmp    $0x27,%eax
jle    1270 <main+0x100>
jmp    1298 <main+0x128>
lea    0xd8c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"marks.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"pass.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [9 x i8] c"fail.txt\00"
@.str.5 = [19 x i8] c"Cannot open file.\0A\00"
@.str.6 = [5 x i8] c"%s%d\00"
@EOF = global i64 0
@.str.7 = [23 x i8] c"%s passed the exam ! \0A\00"
@.str.8 = [23 x i8] c"%s failed the exam ! \0A\00"
@.str.9 = [19 x i8] c"The total is: %d \0A\00"
@.str.10 = [32 x i8] c"The number of students is: %d \0A\00"
@.str.11 = [19 x i8] c"The average is: %f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [20 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %7
store i32 0, i32* %8
%9 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %2
%10 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %10, i32** %3
%11 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %11, i32** %4
%12 = load i32*, i32** %2
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
br label %18
18: ; preds = %42, %17
%19 = load i32*, i32** %2
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%21 = call i64 @fscanf(i32* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %20, i32* %6)
%22 = load i64, i64* @EOF
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %48
24: ; preds = %18
%25 = load i32, i32* %6
%26 = icmp sge i32 %25, 40
br i1 %26, label %27, label %33
27: ; preds = %24
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %28)
%30 = load i32*, i32** %3
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%32 = call i32 @fprintf(i32* %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %27, %24
%34 = load i32, i32* %6
%35 = icmp slt i32 %34, 40
br i1 %35, label %36, label %42
36: ; preds = %33
%37 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %37)
%39 = load i32*, i32** %4
%40 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%41 = call i32 @fprintf(i32* %39, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %36, %33
%43 = load i32, i32* %7
%44 = load i32, i32* %6
%45 = add nsw i32 %43, %44
store i32 %45, i32* %7
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %18
48: ; preds = %18
%49 = load i32, i32* %7
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %8
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i32 %51)
%53 = load i32, i32* %7
%54 = load i32, i32* %8
%55 = sdiv i32 %53, %54
%56 = sitofp i32 %55 to double
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), double %56)
%58 = load i32*, i32** %2
%59 = call i32 @fclose(i32* %58)
%60 = load i32*, i32** %3
%61 = call i32 @fclose(i32* %60)
%62 = load i32*, i32** %4
%63 = call i32 @fclose(i32* %62)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"marks.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"pass.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [9 x i8] c"fail.txt\00"
@.str.6 = [5 x i8] c"%s%d\00"
@EOF = global i64 0
@.str.7 = [23 x i8] c"%s passed the exam ! \0A\00"
@.str.8 = [23 x i8] c"%s failed the exam ! \0A\00"
@.str.9 = [19 x i8] c"The total is: %d \0A\00"
@.str.10 = [32 x i8] c"The number of students is: %d \0A\00"
@.str.11 = [19 x i8] c"The average is: %f\00"
@str = [18 x i8] c"Cannot open file.\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%8 = icmp eq i32* %5, null
br i1 %8, label %13, label %9
9: ; preds = %0
%10 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %3, i32* %2)
%11 = load i64, i64* @EOF
%12 = icmp eq i64 %10, %11
br i1 %12, label %37, label %16
13: ; preds = %0
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %9, %30
%17 = phi i32 [ %33, %30 ], [ 0, %9 ]
%18 = phi i32 [ %32, %30 ], [ 0, %9 ]
%19 = load i32, i32* %2
%20 = icmp sgt i32 %19, 39
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %3)
%23 = call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %3)
%24 = load i32, i32* %2
%25 = icmp slt i32 %24, 40
br i1 %25, label %26, label %30
26: ; preds = %16, %21
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %3)
%28 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %3)
%29 = load i32, i32* %2
br label %30
30: ; preds = %26, %21
%31 = phi i32 [ %29, %26 ], [ %24, %21 ]
%32 = add nsw i32 %31, %18
%33 = add nuw nsw i32 %17, 1
%34 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %3, i32* %2)
%35 = load i64, i64* @EOF
%36 = icmp eq i64 %34, %35
br i1 %36, label %37, label %16
37: ; preds = %30, %9
%38 = phi i32 [ 0, %9 ], [ %32, %30 ]
%39 = phi i32 [ 0, %9 ], [ %33, %30 ]
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i32 %38)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i32 %39)
%42 = sdiv i32 %38, %39
%43 = sitofp i32 %42 to double
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), double %43)
%45 = call i32 @fclose(i32* %5)
%46 = call i32 @fclose(i32* %6)
%47 = call i32 @fclose(i32* %7)
ret i32 0
}