void fig14_02() {
  double w = 37.5;
  double x = 22.5;
  double y = 1.7;
  double z = 10.2;
  printf("%s%.1f\n%s%.1f\n%s%.1f\n%s%.1f\n\n", "w = ", w, "x = ", x, "y = ", y,
         "z = ", z);
  printf("%s%.3f\n%s%.3f\n%s%.3f\n", "The average of w and x is ",
         average(2, w, x), "The average of w, x and y is ", average(3, w, x, y),
         "The average of w, x, y and z is ", average(4, w, x, y, z));
}


x86 assembly (clang, -O0):
<fig14_02>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  0xee8(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xed3(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xebe(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xea9(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm3
lea    0xea9(%rip),%rdi
lea    0xec0(%rip),%rsi
lea    0xebe(%rip),%rdx
lea    0xebc(%rip),%rcx
lea    0xeba(%rip),%r8
mov    $0x4,%al
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mov    $0x2,%edi
mov    $0x2,%al
call   1040 <average@plt>
mov    %eax,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
mov    $0x3,%edi
mov    $0x3,%al
call   1040 <average@plt>
mov    %eax,-0x24(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm3
mov    $0x4,%edi
mov    $0x4,%al
call   1040 <average@plt>
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%r8d
lea    0xe53(%rip),%rdi
lea    0xe62(%rip),%rsi
lea    0xe76(%rip),%rcx
lea    0xe8d(%rip),%r9
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig14_02>:
push   %rbp
push   %rbx
push   %rax
lea    0xef6(%rip),%rdi
lea    0xf0d(%rip),%rsi
lea    0xf0b(%rip),%rdx
lea    0xf09(%rip),%rcx
lea    0xf07(%rip),%r8
movsd  0xeb2(%rip),%xmm0
movsd  0xeb2(%rip),%xmm1
movsd  0xeb2(%rip),%xmm2
movsd  0xeb2(%rip),%xmm3
mov    $0x4,%al
call   1030 <printf@plt>
mov    $0x2,%edi
movsd  0xe86(%rip),%xmm0
movsd  0xe86(%rip),%xmm1
mov    $0x2,%al
call   1040 <average@plt>
mov    %eax,%ebx
mov    $0x3,%edi
movsd  0xe68(%rip),%xmm0
movsd  0xe68(%rip),%xmm1
movsd  0xe68(%rip),%xmm2
mov    $0x3,%al
call   1040 <average@plt>
mov    %eax,%ebp
mov    $0x4,%edi
movsd  0xe42(%rip),%xmm0
movsd  0xe42(%rip),%xmm1
movsd  0xe42(%rip),%xmm2
movsd  0xe42(%rip),%xmm3
mov    $0x4,%al
call   1040 <average@plt>
mov    %eax,(%rsp)
lea    0xe6b(%rip),%rdi
lea    0xe7a(%rip),%rsi
lea    0xe8e(%rip),%rcx
lea    0xea5(%rip),%r9
mov    %ebx,%edx
mov    %ebp,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"%s%.1f\0A%s%.1f\0A%s%.1f\0A%s%.1f\0A\0A\00"
@.str.1 = [5 x i8] c"w = \00"
@.str.2 = [5 x i8] c"x = \00"
@.str.3 = [5 x i8] c"y = \00"
@.str.4 = [5 x i8] c"z = \00"
@.str.5 = [22 x i8] c"%s%.3f\0A%s%.3f\0A%s%.3f\0A\00"
@.str.6 = [27 x i8] c"The average of w and x is \00"
@.str.7 = [30 x i8] c"The average of w, x and y is \00"
@.str.8 = [33 x i8] c"The average of w, x, y and z is \00"
define void @fig14_02() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
store double 3.750000e+01, double* %1
store double 2.250000e+01, double* %2
store double 1.700000e+00, double* %3
store double 1.020000e+01, double* %4
%5 = load double, double* %1
%6 = load double, double* %2
%7 = load double, double* %3
%8 = load double, double* %4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), double %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), double %8)
%10 = load double, double* %1
%11 = load double, double* %2
%12 = call i32 (i32, double, double, ...) bitcast (i32 (...)* @average to i32 (i32, double, double, ...)*)(i32 2, double %10, double %11)
%13 = load double, double* %1
%14 = load double, double* %2
%15 = load double, double* %3
%16 = call i32 (i32, double, double, double, ...) bitcast (i32 (...)* @average to i32 (i32, double, double, double, ...)*)(i32 3, double %13, double %14, double %15)
%17 = load double, double* %1
%18 = load double, double* %2
%19 = load double, double* %3
%20 = load double, double* %4
%21 = call i32 (i32, double, double, double, double, ...) bitcast (i32 (...)* @average to i32 (i32, double, double, double, double, ...)*)(i32 4, double %17, double %18, double %19, double %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %16, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %21)
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"%s%.1f\0A%s%.1f\0A%s%.1f\0A%s%.1f\0A\0A\00"
@.str.1 = [5 x i8] c"w = \00"
@.str.2 = [5 x i8] c"x = \00"
@.str.3 = [5 x i8] c"y = \00"
@.str.4 = [5 x i8] c"z = \00"
@.str.5 = [22 x i8] c"%s%.3f\0A%s%.3f\0A%s%.3f\0A\00"
@.str.6 = [27 x i8] c"The average of w and x is \00"
@.str.7 = [30 x i8] c"The average of w, x and y is \00"
@.str.8 = [33 x i8] c"The average of w, x, y and z is \00"
define void @fig14_02() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double 3.750000e+01, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double 2.250000e+01, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), double 1.700000e+00, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), double 1.020000e+01)
%2 = tail call i32 (i32, double, double, ...) bitcast (i32 (...)* @average to i32 (i32, double, double, ...)*)(i32 2, double 3.750000e+01, double 2.250000e+01)
%3 = tail call i32 (i32, double, double, double, ...) bitcast (i32 (...)* @average to i32 (i32, double, double, double, ...)*)(i32 3, double 3.750000e+01, double 2.250000e+01, double 1.700000e+00)
%4 = tail call i32 (i32, double, double, double, double, ...) bitcast (i32 (...)* @average to i32 (i32, double, double, double, double, ...)*)(i32 4, double 3.750000e+01, double 2.250000e+01, double 1.700000e+00, double 1.020000e+01)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %2, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %3, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %4)
ret void
}