#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 maximum(int const **, int, int);
int minimum(int const **, int, int);
int /*<<< orphan*/ printArray(int const **, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int student;
  const int studentGrades[3][4] = {
      {77, 68, 86, 73}, {96, 87, 89, 78}, {70, 90, 86, 81}};
  printf("The array is:\n");
  printArray(studentGrades, 3, 4);
  printf("\n\nLowest grade: %d\nHighest grade: %d\n",
         minimum(studentGrades, 3, 4), maximum(studentGrades, 3, 4));
  for (student = 0; student < 3; student++) {
    printf("The average grade for student %d is %.2f\n", student,
           average(studentGrades[student], 4));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe86(%rip),%rsi
mov    $0x30,%edx
call   1060 <memcpy@plt>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x3,%esi
mov    $0x4,%edx
call   1080 <printArray@plt>
lea    -0x40(%rbp),%rdi
mov    $0x3,%esi
mov    $0x4,%edx
call   1040 <minimum@plt>
mov    %eax,-0x44(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x3,%esi
mov    $0x4,%edx
call   1030 <maximum@plt>
mov    -0x44(%rbp),%esi
mov    %eax,%edx
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1230 <main+0xd0>
mov    -0x8(%rbp),%eax
mov    %eax,-0x48(%rbp)
movslq -0x8(%rbp),%rax
lea    -0x40(%rbp),%rdi
shl    $0x4,%rax
add    %rax,%rdi
mov    $0x4,%esi
call   1070 <average@plt>
mov    -0x48(%rbp),%esi
lea    0xe4a(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11e8 <main+0x88>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
movaps 0xeaf(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe93(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe77(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x20(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0xee2(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x4,%edx
call   1080 <printArray@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x4,%edx
call   1050 <minimum@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x4,%edx
call   1030 <maximum@plt>
lea    0xe4b(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1070 <average@plt>
lea    0xe52(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    %r15,%rdi
mov    $0x4,%esi
call   1070 <average@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%al
call   1060 <printf@plt>
mov    %r14,%rdi
mov    $0x4,%esi
call   1070 <average@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.studentGrades = [3 x [4 x i32]] [[4 x i32] [i32 77, i32 68, i32 86, i32 73], [4 x i32] [i32 96, i32 87, i32 89, i32 78], [4 x i32] [i32 70, i32 90, i32 86, i32 81]]
@.str = [15 x i8] c"The array is:\0A\00"
@.str.1 = [38 x i8] c"\0A\0ALowest grade: %d\0AHighest grade: %d\0A\00"
@.str.2 = [42 x i8] c"The average grade for student %d is %.2f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [3 x [4 x i32]]
store i32 0, i32* %1
%4 = bitcast [3 x [4 x i32]]* %3 to i8*
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %3, i64 0, i64 0
%7 = bitcast [4 x i32]* %6 to i32**
%8 = call i32 @printArray(i32** %7, i32 3, i32 4)
%9 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %3, i64 0, i64 0
%10 = bitcast [4 x i32]* %9 to i32**
%11 = call i32 @minimum(i32** %10, i32 3, i32 4)
%12 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %3, i64 0, i64 0
%13 = bitcast [4 x i32]* %12 to i32**
%14 = call i32 @maximum(i32** %13, i32 3, i32 4)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %14)
store i32 0, i32* %2
br label %16
16: ; preds = %27, %0
%17 = load i32, i32* %2
%18 = icmp slt i32 %17, 3
br i1 %18, label %19, label %30
19: ; preds = %16
%20 = load i32, i32* %2
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %3, i64 0, i64 %22
%24 = getelementptr inbounds [4 x i32], [4 x i32]* %23, i64 0, i64 0
%25 = call double @average(i32* %24, i32 4)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %20, double %25)
br label %27
27: ; preds = %19
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %16
30: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
@__const.main.studentGrades = [3 x [4 x i32]] [[4 x i32] [i32 77, i32 68, i32 86, i32 73], [4 x i32] [i32 96, i32 87, i32 89, i32 78], [4 x i32] [i32 70, i32 90, i32 86, i32 81]]
@.str.1 = [38 x i8] c"\0A\0ALowest grade: %d\0AHighest grade: %d\0A\00"
@.str.2 = [42 x i8] c"The average grade for student %d is %.2f\0A\00"
@str = [14 x i8] c"The array is:\00"
define i32 @main() {
%1 = alloca [3 x [4 x i32]]
%2 = bitcast [3 x [4 x i32]]* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%4 = bitcast [3 x [4 x i32]]* %1 to i32**
%5 = call i32 @printArray(i32** %4, i32 3, i32 4)
%6 = call i32 @minimum(i32** %4, i32 3, i32 4)
%7 = call i32 @maximum(i32** %4, i32 3, i32 4)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %7)
%9 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i64 0, i64 0, i64 0
%10 = call double @average(i32* %9, i32 4)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 0, double %10)
%12 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i64 0, i64 1, i64 0
%13 = call double @average(i32* %12, i32 4)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 1, double %13)
%15 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i64 0, i64 2, i64 0
%16 = call double @average(i32* %15, i32 4)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 2, double %16)
ret i32 0
}