#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 */
double average(int const *, int);
int /*<<< orphan*/ printf(char *, int, double);
void menuAverages(const int grades[][4], int pupils, int tests) {
  for (int student = 0; student < pupils; student++) {
    printf("The average grade for student %d is %.2f\n", student,
           average(grades[student], tests));
  }
}


x86 assembly (clang, -O0):
<menuAverages>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117f <menuAverages+0x5f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x4,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%esi
call   1040 <average@plt>
mov    -0x18(%rbp),%esi
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1139 <menuAverages+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<menuAverages>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
jle    1162 <menuAverages+0x42>
mov    %edx,%r14d
mov    %rdi,%rbx
mov    %esi,%r12d
xor    %ebp,%ebp
lea    0xec2(%rip),%r15
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <average@plt>
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
add    $0x1,%rbp
add    $0x10,%rbx
cmp    %rbp,%r12
jne    1140 <menuAverages+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"The average grade for student %d is %.2f\0A\00"
define void @menuAverages([4 x i32]* %0, i32 %1, i32 %2) {
%4 = alloca [4 x i32]*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store [4 x i32]* %0, [4 x i32]** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %22, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %5
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %25
12: ; preds = %8
%13 = load i32, i32* %7
%14 = load [4 x i32]*, [4 x i32]** %4
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %14, i64 %16
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %17, i64 0, i64 0
%19 = load i32, i32* %6
%20 = call double @average(i32* %18, i32 %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %13, double %20)
br label %22
22: ; preds = %12
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
br label %8
25: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [42 x i8] c"The average grade for student %d is %.2f\0A\00"
define void @menuAverages([4 x i32]* %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %8
7: ; preds = %8, %3
ret void
8: ; preds = %5, %8
%9 = phi i64 [ 0, %5 ], [ %14, %8 ]
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %0, i64 %9, i64 0
%11 = tail call double @average(i32* %10, i32 %2)
%12 = trunc i64 %9 to i32
%13 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %12, double %11)
%14 = add nuw nsw i64 %9, 1
%15 = icmp eq i64 %14, %6
br i1 %15, label %7, label %8
}