#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);
    } else {
      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 mark is: %.2f", (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     1284 <main+0x124>
cmpl   $0x28,-0x44(%rbp)
jl     1247 <main+0xe7>
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>
jmp    126d <main+0x10d>
lea    -0x40(%rbp),%rsi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xde7(%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    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4c(%rbp),%esi
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x48(%rbp),%eax
cltd
idivl  -0x4c(%rbp)
cvtsi2sd %eax,%xmm0
lea    0xde1(%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,%rbp
lea    0xe71(%rip),%rdi
lea    0xe73(%rip),%rbx
mov    %rbx,%rsi
call   1080 <fopen@plt>
mov    %rax,0x18(%rsp)
lea    0xe61(%rip),%rdi
mov    %rbx,%rsi
call   1080 <fopen@plt>
mov    %rax,0x10(%rsp)
mov    %rbp,0x8(%rsp)
test   %rbp,%rbp
je     12ff <main+0x18f>
lea    0xe48(%rip),%rsi
lea    0x20(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    0x8(%rsp),%rdi
call   1060 <fscanf@plt>
mov    0x2df5(%rip),%rcx
xor    %ebp,%ebp
mov    $0x0,%ebx
cmp    (%rcx),%rax
jne    1265 <main+0xf5>
lea    0xe4d(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe50(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%eax
cltd
idiv   %ebx
cvtsi2sd %eax,%xmm0
lea    0xe57(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    0x8(%rsp),%rdi
call   1040 <fclose@plt>
mov    0x18(%rsp),%rdi
call   1040 <fclose@plt>
mov    0x10(%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    0xdaf(%rip),%r13
lea    0x4(%rsp),%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    12ce <main+0x15e>
nopl   0x0(%rax)
lea    0xdb5(%rip),%r12
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
add    0x4(%rsp),%ebp
add    $0x1,%ebx
mov    0x8(%rsp),%rdi
mov    %r13,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1060 <fscanf@plt>
mov    0x2d23(%rip),%rcx
cmp    (%rcx),%rax
je     11ff <main+0x8f>
cmpl   $0x28,0x4(%rsp)
jl     1280 <main+0x110>
mov    %r15,%r12
mov    %r13,%r15
lea    0xd43(%rip),%r13
mov    %r13,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rsp),%rdi
mov    %r13,%rsi
mov    %r15,%r13
mov    %r12,%r15
jmp    129c <main+0x12c>
lea    0xd9a(%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 = [26 x i8] c"The average mark is: %.2f\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 = %39, %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 %45
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 %39
33: ; preds = %24
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %34)
%36 = load i32*, i32** %4
%37 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%38 = call i32 @fprintf(i32* %36, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %33, %27
%40 = load i32, i32* %7
%41 = load i32, i32* %6
%42 = add nsw i32 %40, %41
store i32 %42, i32* %7
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %18
45: ; preds = %18
%46 = load i32, i32* %7
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %8
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i32 %48)
%50 = load i32, i32* %7
%51 = load i32, i32* %8
%52 = sdiv i32 %50, %51
%53 = sitofp i32 %52 to double
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), double %53)
%55 = load i32*, i32** %2
%56 = call i32 @fclose(i32* %55)
%57 = load i32*, i32** %3
%58 = call i32 @fclose(i32* %57)
%59 = load i32*, i32** %4
%60 = call i32 @fclose(i32* %59)
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 = [26 x i8] c"The average mark is: %.2f\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 %34, 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, %27
%17 = phi i32 [ %30, %27 ], [ 0, %9 ]
%18 = phi i32 [ %29, %27 ], [ 0, %9 ]
%19 = load i32, i32* %2
%20 = icmp sgt i32 %19, 39
br i1 %20, label %21, label %24
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)
br label %27
24: ; preds = %16
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %3)
%26 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %3)
br label %27
27: ; preds = %24, %21
%28 = load i32, i32* %2
%29 = add nsw i32 %28, %18
%30 = add nuw nsw i32 %17, 1
%31 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %3, i32* %2)
%32 = load i64, i64* @EOF
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %16
34: ; preds = %27, %9
%35 = phi i32 [ 0, %9 ], [ %29, %27 ]
%36 = phi i32 [ 0, %9 ], [ %30, %27 ]
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i32 %35)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0), i32 %36)
%39 = sdiv i32 %35, %36
%40 = sitofp i32 %39 to double
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), double %40)
%42 = call i32 @fclose(i32* %5)
%43 = call i32 @fclose(i32* %6)
%44 = call i32 @fclose(i32* %7)
ret i32 0
}