#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 *, int);
int maximum(int **, int, int);
int minimum(int **, int, int);
int /*<<< orphan*/ printSubArray(int **, int, int);
int /*<<< orphan*/ printf(char *, size_t, double);
int /*<<< orphan*/ puts(char *);
void fig06_22() {
  size_t student;
  int studentGrades[3][4] = {
      {77, 68, 86, 73}, {96, 87, 89, 78}, {70, 90, 86, 81}};
  puts("The array is:");
  printSubArray(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 %u is %.2f\n", student,
           average(studentGrades[student], 4));
  }
}


x86 assembly (clang, -O0):
<fig06_22>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x40(%rbp),%rdi
lea    0xe7d(%rip),%rsi
mov    $0x30,%edx
call   1070 <memcpy@plt>
lea    0xe9c(%rip),%rdi
call   1040 <puts@plt>
lea    -0x40(%rbp),%rdi
mov    $0x3,%esi
mov    $0x4,%edx
call   1090 <printSubArray@plt>
lea    -0x40(%rbp),%rdi
mov    $0x3,%esi
mov    $0x4,%edx
call   1050 <minimum@plt>
cltq
mov    %rax,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x3,%esi
mov    $0x4,%edx
call   1030 <maximum@plt>
mov    -0x48(%rbp),%rsi
cvtsi2sd %eax,%xmm0
lea    0xe57(%rip),%rdi
call   1060 <printf@plt>
movq   $0x0,-0x8(%rbp)
cmpq   $0x3,-0x8(%rbp)
jae    1241 <fig06_22+0xd1>
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rax
lea    -0x40(%rbp),%rdi
shl    $0x4,%rax
add    %rax,%rdi
mov    $0x4,%esi
call   1080 <average@plt>
mov    -0x50(%rbp),%rsi
lea    0xe39(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11f4 <fig06_22+0x84>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig06_22>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
movaps 0xeae(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe92(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe76(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x20(%rsp),%r14
lea    0x10(%rsp),%r15
lea    0xe91(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x3,%esi
mov    $0x4,%edx
call   1080 <printSubArray@plt>
mov    %r12,%rdi
mov    $0x3,%esi
mov    $0x4,%edx
call   1050 <minimum@plt>
movslq %eax,%rbx
mov    %r12,%rdi
mov    $0x3,%esi
mov    $0x4,%edx
call   1030 <maximum@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
lea    0xe50(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %r12,%rdi
mov    $0x4,%esi
call   1070 <average@plt>
lea    0xe5a(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <printf@plt>
mov    %r15,%rdi
mov    $0x4,%esi
call   1070 <average@plt>
mov    $0x1,%esi
mov    %rbx,%rdi
call   1060 <printf@plt>
mov    %r14,%rdi
mov    $0x4,%esi
call   1070 <average@plt>
mov    $0x2,%esi
mov    %rbx,%rdi
call   1060 <printf@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.fig06_22.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 = [14 x i8] c"The array is:\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 %u is %.2f\0A\00"
define void @fig06_22() {
%1 = alloca i64
%2 = alloca [3 x [4 x i32]]
%3 = bitcast [3 x [4 x i32]]* %2 to i8*
%4 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %2, i64 0, i64 0
%6 = bitcast [4 x i32]* %5 to i32**
%7 = call i32 @printSubArray(i32** %6, i32 3, i32 4)
%8 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %2, i64 0, i64 0
%9 = bitcast [4 x i32]* %8 to i32**
%10 = call i32 @minimum(i32** %9, i32 3, i32 4)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %2, i64 0, i64 0
%13 = bitcast [4 x i32]* %12 to i32**
%14 = call i32 @maximum(i32** %13, i32 3, i32 4)
%15 = sitofp i32 %14 to double
%16 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i64 %11, double %15)
store i64 0, i64* %1
br label %17
17: ; preds = %27, %0
%18 = load i64, i64* %1
%19 = icmp ult i64 %18, 3
br i1 %19, label %20, label %30
20: ; preds = %17
%21 = load i64, i64* %1
%22 = load i64, i64* %1
%23 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %2, 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 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i64 %21, double %25)
br label %27
27: ; preds = %20
%28 = load i64, i64* %1
%29 = add i64 %28, 1
store i64 %29, i64* %1
br label %17
30: ; preds = %17
ret void
}

LLVM IR (-O2):
@__const.fig06_22.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 = [14 x i8] c"The array is:\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 %u is %.2f\0A\00"
define void @fig06_22() {
%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 @printSubArray(i32** %4, i32 3, i32 4)
%6 = call i32 @minimum(i32** %4, i32 3, i32 4)
%7 = sext i32 %6 to i64
%8 = call i32 @maximum(i32** %4, i32 3, i32 4)
%9 = sitofp i32 %8 to double
%10 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i64 %7, double %9)
%11 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i64 0, i64 0, i64 0
%12 = call double @average(i32* %11, i32 4)
%13 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i64 0, double %12)
%14 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i64 0, i64 1, i64 0
%15 = call double @average(i32* %14, i32 4)
%16 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i64 1, double %15)
%17 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i64 0, i64 2, i64 0
%18 = call double @average(i32* %17, i32 4)
%19 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i64 2, double %18)
ret void
}