#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, int *);
int main() {
  int grade, sum = 0, num_grades = 0, failed = 0;
  while (scanf("%d", &grade) == 1) {
    while (grade < 5 || grade > 10) {
      printf("Enter grade from 5 to 10: ");
      if (scanf("%d", &grade) != 1)
        break;
    }
    if (grade >= 6 && grade <= 10) {
      sum += grade;
      num_grades++;
    } else
      failed++;
  }
  if (num_grades == 0)
    printf("No passed exams");
  else
    printf("Average is %4.2f\n", (float)sum / num_grades);
  if (failed != 0)
    printf("Failed on %d exams\n", failed);
  else
    printf("No failed exams\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xeb5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    11f5 <main+0xd5>
jmp    1162 <main+0x42>
mov    $0x1,%al
cmpl   $0x5,-0x8(%rbp)
mov    %al,-0x15(%rbp)
jl     117b <main+0x5b>
cmpl   $0xa,-0x8(%rbp)
setg   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    118b <main+0x6b>
jmp    11bc <main+0x9c>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe60(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
je     11b7 <main+0x97>
jmp    11bc <main+0x9c>
jmp    1162 <main+0x42>
cmpl   $0x6,-0x8(%rbp)
jl     11e7 <main+0xc7>
cmpl   $0xa,-0x8(%rbp)
jg     11e7 <main+0xc7>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11f0 <main+0xd0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1144 <main+0x24>
cmpl   $0x0,-0x10(%rbp)
jne    1212 <main+0xf2>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1232 <main+0x112>
cvtsi2ssl -0xc(%rbp),%xmm0
cvtsi2ssl -0x10(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe03(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x14(%rbp)
je     1252 <main+0x132>
mov    -0x14(%rbp),%esi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1260 <main+0x140>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
xor    %r14d,%r14d
cmp    $0x1,%eax
jne    1210 <main+0xe0>
lea    0xea4(%rip),%r15
lea    0xe9a(%rip),%rbp
lea    0x4(%rsp),%rbx
xor    %r14d,%r14d
xor    %r12d,%r12d
xor    %r13d,%r13d
jmp    11b0 <main+0x80>
mov    0x4(%rsp),%eax
lea    -0x6(%rax),%ecx
cmp    $0x5,%ecx
adc    $0x0,%r12d
cmp    $0x5,%ecx
sbb    $0xffffffff,%r14d
cmp    $0x5,%ecx
mov    $0x0,%ecx
cmovae %ecx,%eax
add    %eax,%r13d
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    11d8 <main+0xa8>
nopl   0x0(%rax)
mov    0x4(%rsp),%eax
lea    -0xb(%rax),%ecx
cmp    $0xfffffff9,%ecx
ja     117a <main+0x4a>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
je     11b0 <main+0x80>
jmp    1176 <main+0x46>
test   %r12d,%r12d
je     1210 <main+0xe0>
cvtsi2ss %r13d,%xmm0
cvtsi2ss %r12d,%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe38(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
test   %r14d,%r14d
jne    1223 <main+0xf3>
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
jmp    1234 <main+0x104>
lea    0xe07(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14d,%r14d
je     1202 <main+0xd2>
lea    0xe16(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [27 x i8] c"Enter grade from 5 to 10: \00"
@.str.2 = [16 x i8] c"No passed exams\00"
@.str.3 = [18 x i8] c"Average is %4.2f\0A\00"
@.str.4 = [20 x i8] c"Failed on %d exams\0A\00"
@.str.5 = [17 x i8] c"No failed exams\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %39, %0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %40
9: ; preds = %6
br label %10
10: ; preds = %23, %9
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 5
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = load i32, i32* %2
%15 = icmp sgt i32 %14, 10
br label %16
16: ; preds = %13, %10
%17 = phi i1 [ true, %10 ], [ %15, %13 ]
br i1 %17, label %18, label %24
18: ; preds = %16
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %18
br label %24
23: ; preds = %18
br label %10
24: ; preds = %22, %16
%25 = load i32, i32* %2
%26 = icmp sge i32 %25, 6
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = load i32, i32* %2
%29 = icmp sle i32 %28, 10
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = load i32, i32* %2
%32 = load i32, i32* %3
%33 = add nsw i32 %32, %31
store i32 %33, i32* %3
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %39
36: ; preds = %27, %24
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %39
39: ; preds = %36, %30
br label %6
40: ; preds = %6
%41 = load i32, i32* %4
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %53
45: ; preds = %40
%46 = load i32, i32* %3
%47 = sitofp i32 %46 to float
%48 = load i32, i32* %4
%49 = sitofp i32 %48 to float
%50 = fdiv float %47, %49
%51 = fpext float %50 to double
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), double %51)
br label %53
53: ; preds = %45, %43
%54 = load i32, i32* %5
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load i32, i32* %5
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %57)
br label %61
59: ; preds = %53
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %61
61: ; preds = %59, %56
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [27 x i8] c"Enter grade from 5 to 10: \00"
@.str.2 = [16 x i8] c"No passed exams\00"
@.str.3 = [18 x i8] c"Average is %4.2f\0A\00"
@.str.4 = [20 x i8] c"Failed on %d exams\0A\00"
@str = [16 x i8] c"No failed exams\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %34
5: ; preds = %0, %19
%6 = phi i32 [ %29, %19 ], [ 0, %0 ]
%7 = phi i32 [ %26, %19 ], [ 0, %0 ]
%8 = phi i32 [ %24, %19 ], [ 0, %0 ]
br label %9
9: ; preds = %5, %13
%10 = load i32, i32* %1
%11 = add i32 %10, -11
%12 = icmp ult i32 %11, -6
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%16 = icmp eq i32 %15, 1
br i1 %16, label %9, label %17
17: ; preds = %13
%18 = load i32, i32* %1
br label %19
19: ; preds = %9, %17
%20 = phi i32 [ %18, %17 ], [ %10, %9 ]
%21 = add i32 %20, -6
%22 = icmp ult i32 %21, 5
%23 = select i1 %22, i32 %20, i32 0
%24 = add nsw i32 %23, %8
%25 = zext i1 %22 to i32
%26 = add nuw nsw i32 %7, %25
%27 = xor i1 %22, true
%28 = zext i1 %27 to i32
%29 = add nuw nsw i32 %6, %28
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%31 = icmp eq i32 %30, 1
br i1 %31, label %5, label %32
32: ; preds = %19
%33 = icmp eq i32 %26, 0
br i1 %33, label %34, label %37
34: ; preds = %0, %32
%35 = phi i32 [ %29, %32 ], [ 0, %0 ]
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %43
37: ; preds = %32
%38 = sitofp i32 %24 to float
%39 = sitofp i32 %26 to float
%40 = fdiv float %38, %39
%41 = fpext float %40 to double
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), double %41)
br label %43
43: ; preds = %37, %34
%44 = phi i32 [ %29, %37 ], [ %35, %34 ]
%45 = icmp eq i32 %44, 0
br i1 %45, label %48, label %46
46: ; preds = %43
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %44)
br label %50
48: ; preds = %43
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %50
50: ; preds = %48, %46
ret i32 0
}