#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 /*<<< orphan*/ scanf(char *, ...);
int main() {
  int absences;
  float prog_a_grade;
  float prog_b_grade;
  float exam_grade;
  printf("Give absences number: ");
  scanf("%d", &absences);
  printf("Give first progress grade: ");
  scanf("%f", &prog_a_grade);
  printf("Give second progress grade: ");
  scanf("%f", &prog_b_grade);
  printf("Give final exam grade: ");
  scanf("%f", &exam_grade);
  float absences_grade = 0;
  switch (absences) {
  case 0:
    absences_grade = 10;
    break;
  case 1:
    absences_grade = 5;
    break;
  }
  float lab_grade =
      0.2 * absences_grade + 0.4 * prog_a_grade + 0.4 * prog_b_grade;
  if (lab_grade < 4.5) {
    printf("Lab failed!\n");
    return 0;
  }
  if (exam_grade < 4.5) {
    printf("Final exam failed!\n");
    return 0;
  }
  float final_grade = 0.4 * lab_grade + 0.6 * exam_grade;
  printf("cse502 passed! grade: %f\n", final_grade);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xef2(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x25(%rbp)
call   1030 <printf@plt>
mov    -0x25(%rbp),%al
lea    0xef5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x25(%rbp),%al
lea    0xee5(%rip),%rdi
call   1030 <printf@plt>
mov    -0x25(%rbp),%al
lea    0xef2(%rip),%rdi
mov    %rdi,-0x30(%rbp)
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x25(%rbp),%al
lea    0xede(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x25(%rbp),%al
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x25(%rbp),%al
lea    0xedc(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x25(%rbp),%al
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
test   %eax,%eax
je     11e2 <main+0xc2>
jmp    11d1 <main+0xb1>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
je     11f4 <main+0xd4>
jmp    1201 <main+0xe1>
movss  0xe1a(%rip),%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    1201 <main+0xe1>
movss  0xe04(%rip),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm2
movsd  0xdf5(%rip),%xmm0
mulsd  %xmm2,%xmm0
movsd  0xdf1(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdd0(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xda6(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1286 <main+0x166>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1309 <main+0x1e9>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd71(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    12bb <main+0x19b>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1309 <main+0x1e9>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x14(%rbp),%xmm1
cvtss2sd %xmm1,%xmm2
movsd  0xd4b(%rip),%xmm1
mulsd  %xmm2,%xmm1
movsd  0xd2f(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdb5(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xef0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xef9(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xee9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xef7(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xee4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xee4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x1,%eax
je     11c5 <main+0x95>
xorpd  %xmm0,%xmm0
test   %eax,%eax
je     11d1 <main+0xa1>
jmp    11d9 <main+0xa9>
movsd  0xe33(%rip),%xmm0
test   %eax,%eax
jne    11d9 <main+0xa9>
movsd  0xe2f(%rip),%xmm0
movss  0x8(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xe25(%rip),%xmm2
mulsd  0xe25(%rip),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movss  0x4(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
movss  0xe0c(%rip),%xmm2
ucomiss %xmm0,%xmm2
jbe    122f <main+0xff>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
jmp    1279 <main+0x149>
movss  (%rsp),%xmm1
ucomiss %xmm1,%xmm2
jbe    1247 <main+0x117>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
jmp    1279 <main+0x149>
cvtss2sd %xmm0,%xmm0
cvtss2sd %xmm1,%xmm1
mulsd  0xdc9(%rip),%xmm1
mulsd  0xdb1(%rip),%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe28(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Give absences number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [28 x i8] c"Give first progress grade: \00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [29 x i8] c"Give second progress grade: \00"
@.str.5 = [24 x i8] c"Give final exam grade: \00"
@.str.6 = [13 x i8] c"Lab failed!\0A\00"
@.str.7 = [20 x i8] c"Final exam failed!\0A\00"
@.str.8 = [26 x i8] c"cse502 passed! grade: %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %3)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %4)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %5)
store float 0.000000e+00, float* %6
%17 = load i32, i32* %2
switch i32 %17, label %20 [
i32 0, label %18
i32 1, label %19
]
18: ; preds = %0
store float 1.000000e+01, float* %6
br label %20
19: ; preds = %0
store float 5.000000e+00, float* %6
br label %20
20: ; preds = %0, %19, %18
%21 = load float, float* %6
%22 = fpext float %21 to double
%23 = load float, float* %3
%24 = fpext float %23 to double
%25 = fmul double 4.000000e-01, %24
%26 = call double @llvm.fmuladd.f64(double 2.000000e-01, double %22, double %25)
%27 = load float, float* %4
%28 = fpext float %27 to double
%29 = call double @llvm.fmuladd.f64(double 4.000000e-01, double %28, double %26)
%30 = fptrunc double %29 to float
store float %30, float* %7
%31 = load float, float* %7
%32 = fpext float %31 to double
%33 = fcmp olt double %32, 4.500000e+00
br i1 %33, label %34, label %36
34: ; preds = %20
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %1
br label %53
36: ; preds = %20
%37 = load float, float* %5
%38 = fpext float %37 to double
%39 = fcmp olt double %38, 4.500000e+00
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %1
br label %53
42: ; preds = %36
%43 = load float, float* %7
%44 = fpext float %43 to double
%45 = load float, float* %5
%46 = fpext float %45 to double
%47 = fmul double 6.000000e-01, %46
%48 = call double @llvm.fmuladd.f64(double 4.000000e-01, double %44, double %47)
%49 = fptrunc double %48 to float
store float %49, float* %8
%50 = load float, float* %8
%51 = fpext float %50 to double
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), double %51)
br label %53
53: ; preds = %42, %40, %34
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@.str = [23 x i8] c"Give absences number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [28 x i8] c"Give first progress grade: \00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [29 x i8] c"Give second progress grade: \00"
@.str.5 = [24 x i8] c"Give final exam grade: \00"
@.str.8 = [26 x i8] c"cse502 passed! grade: %f\0A\00"
@str = [19 x i8] c"Final exam failed!\00"
@str.9 = [12 x i8] c"Lab failed!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = bitcast i32* %1 to i8*
%6 = bitcast float* %2 to i8*
%7 = bitcast float* %3 to i8*
%8 = bitcast float* %4 to i8*
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %2)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %3)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %4)
%17 = load i32, i32* %1
%18 = icmp eq i32 %17, 1
%19 = select i1 %18, double 5.000000e+00, double 0.000000e+00
%20 = icmp eq i32 %17, 0
%21 = select i1 %20, double 1.000000e+01, double %19
%22 = load float, float* %2
%23 = fpext float %22 to double
%24 = fmul double %23, 4.000000e-01
%25 = call double @llvm.fmuladd.f64(double %21, double 2.000000e-01, double %24)
%26 = load float, float* %3
%27 = fpext float %26 to double
%28 = call double @llvm.fmuladd.f64(double %27, double 4.000000e-01, double %25)
%29 = fptrunc double %28 to float
%30 = fpext float %29 to double
%31 = fcmp olt float %29, 4.500000e+00
br i1 %31, label %32, label %34
32: ; preds = %0
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.9, i64 0, i64 0))
br label %46
34: ; preds = %0
%35 = load float, float* %4
%36 = fcmp olt float %35, 4.500000e+00
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %46
39: ; preds = %34
%40 = fpext float %35 to double
%41 = fmul double %40, 6.000000e-01
%42 = call double @llvm.fmuladd.f64(double %30, double 4.000000e-01, double %41)
%43 = fptrunc double %42 to float
%44 = fpext float %43 to double
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), double %44)
br label %46
46: ; preds = %39, %37, %32
ret i32 0
}