#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 *, ...);
scalar_t__ strcmp(char *, char *);
int main() {
  char StudentName[100];
  float ExamValue, Sum, Avg;
  int students, exams;
  while (1) {
    Sum = 0.0;
    printf("Enter Student Name (use 0 to exit): \n");
    scanf("%s", StudentName);
    if (strcmp("0", StudentName) != 0) {
      for (exams = 0; exams < 3; exams++) {
        printf("Enter exam grade: \n");
        scanf("%f", &ExamValue);
        Sum += ExamValue;
      }
      Avg = Sum / 3.0;
      printf("Average for %s is %f\n", StudentName, Avg);
    } else {
      printf("Exiting program\n");
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x78(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    -0x70(%rbp),%rsi
lea    0xebc(%rip),%rdi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     121c <main+0xec>
movl   $0x0,-0x84(%rbp)
cmpl   $0x3,-0x84(%rbp)
jge    11de <main+0xae>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe97(%rip),%rdi
lea    -0x74(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movss  -0x74(%rbp),%xmm0
addss  -0x78(%rbp),%xmm0
movss  %xmm0,-0x78(%rbp)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    118e <main+0x5e>
movss  -0x78(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe11(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x7c(%rbp)
lea    -0x70(%rbp),%rsi
movss  -0x7c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe3a(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    122f <main+0xff>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1234 <main+0x104>
jmp    1142 <main+0x12>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
lea    0xea7(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xe94(%rip),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     126b <main+0x12b>
lea    0xecc(%rip),%r14
lea    0xe77(%rip),%r15
lea    0xc(%rsp),%r13
lea    0x10(%rsp),%rbx
lea    0xe61(%rip),%r12
lea    0xe5d(%rip),%rbp
xchg   %ax,%ax
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
movss  0xc(%rsp),%xmm0
addss  0xe31(%rip),%xmm0
movss  %xmm0,0x8(%rsp)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
movss  0x8(%rsp),%xmm0
addss  0xc(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
movss  0x8(%rsp),%xmm0
addss  0xc(%rsp),%xmm0
divss  0xdd7(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xddc(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xde1(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11b0 <main+0x70>
lea    0xdd9(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Enter Student Name (use 0 to exit): \0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [20 x i8] c"Enter exam grade: \0A\00"
@.str.4 = [3 x i8] c"%f\00"
@.str.5 = [22 x i8] c"Average for %s is %f\0A\00"
@.str.6 = [17 x i8] c"Exiting program\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
br label %8
8: ; preds = %0, %39
store float 0.000000e+00, float* %4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%13 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %37
15: ; preds = %8
store i32 0, i32* %7
br label %16
16: ; preds = %25, %15
%17 = load i32, i32* %7
%18 = icmp slt i32 %17, 3
br i1 %18, label %19, label %28
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), float* %3)
%22 = load float, float* %3
%23 = load float, float* %4
%24 = fadd float %23, %22
store float %24, float* %4
br label %25
25: ; preds = %19
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %16
28: ; preds = %16
%29 = load float, float* %4
%30 = fpext float %29 to double
%31 = fdiv double %30, 3.000000e+00
%32 = fptrunc double %31 to float
store float %32, float* %5
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%34 = load float, float* %5
%35 = fpext float %34 to double
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %33, double %35)
br label %39
37: ; preds = %8
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
br label %40
39: ; preds = %28
br label %8
40: ; preds = %37
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"0\00"
@.str.4 = [3 x i8] c"%f\00"
@.str.5 = [22 x i8] c"Average for %s is %f\0A\00"
@str = [37 x i8] c"Enter Student Name (use 0 to exit): \00"
@str.7 = [16 x i8] c"Exiting program\00"
@str.8 = [19 x i8] c"Enter exam grade: \00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca float
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = bitcast float* %2 to i8*
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %29, label %9
9: ; preds = %0, %9
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.8, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), float* %2)
%12 = load float, float* %2
%13 = fadd float %12, 0.000000e+00
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.8, i64 0, i64 0))
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), float* %2)
%16 = load float, float* %2
%17 = fadd float %13, %16
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.8, i64 0, i64 0))
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), float* %2)
%20 = load float, float* %2
%21 = fadd float %17, %20
%22 = fdiv float %21, 3.000000e+00
%23 = fpext float %22 to double
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %3, double %23)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%26 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%27 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %9
29: ; preds = %9, %0
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
ret i32 0
}