#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*/ modifyArray(int *, int);
int /*<<< orphan*/ modifyElement(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
void fig06_13() {
  int a[5] = {0, 1, 2, 3, 4};
  size_t i;
  puts("Effects of passing entire array by reference:\n\nThe "
       "value of the original array are:");
  for (i = 0; i < 5; ++i) {
    printf("%3d", a[i]);
  }
  puts("");
  modifyArray(a, 5);
  puts("The value of the modified array are:");
  for (i = 0; i < 5; ++i) {
    printf("%3d", a[i]);
  }
  printf("\n\nEffects of passing array element "
         "by value:\n\nThe value of a[3] is %d\n",
         a[3]);
  modifyElement(a[3]);
  printf("The value of a[ 3 ] is %d\n", a[3]);
}


x86 assembly (clang, -O0):
<fig06_13>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xeb1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeae(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeac(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    0xea6(%rip),%rdi
call   1040 <puts@plt>
movq   $0x0,-0x28(%rbp)
cmpq   $0x5,-0x28(%rbp)
jae    11ab <fig06_13+0x6b>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
lea    0xed3(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    117b <fig06_13+0x3b>
lea    0xf40(%rip),%rdi
call   1040 <puts@plt>
lea    -0x20(%rbp),%rdi
mov    $0x5,%esi
call   1060 <modifyArray@plt>
lea    0xea0(%rip),%rdi
call   1040 <puts@plt>
movq   $0x0,-0x28(%rbp)
cmpq   $0x5,-0x28(%rbp)
jae    1209 <fig06_13+0xc9>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%esi
lea    0xe75(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11d9 <fig06_13+0x99>
mov    -0x14(%rbp),%esi
lea    0xe7e(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1030 <modifyElement@plt>
mov    -0x14(%rbp),%esi
lea    0xeae(%rip),%rdi
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig06_13>:
push   %rbx
sub    $0x20,%rsp
mov    0xeb5(%rip),%eax
mov    %eax,0x10(%rsp)
movaps 0xe9a(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xea3(%rip),%rdi
call   1050 <puts@plt>
lea    0xeeb(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1060 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rsp,%rdi
mov    $0x5,%esi
call   1070 <modifyArray@plt>
lea    0xe93(%rip),%rdi
call   1050 <puts@plt>
mov    (%rsp),%esi
mov    %rbx,%rdi
call   1060 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1060 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1060 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1060 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
call   1060 <printf@plt>
mov    0xc(%rsp),%esi
lea    0xe6d(%rip),%rdi
call   1060 <printf@plt>
mov    0xc(%rsp),%edi
call   1030 <modifyElement@plt>
mov    0xc(%rsp),%esi
lea    0xe9b(%rip),%rdi
call   1060 <printf@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.fig06_13.a = [5 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4]
@.str = [84 x i8] c"Effects of passing entire array by reference:\0A\0AThe value of the original array are:\00"
@.str.1 = [4 x i8] c"%3d\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [37 x i8] c"The value of the modified array are:\00"
@.str.4 = [71 x i8] c"\0A\0AEffects of passing array element by value:\0A\0AThe value of a[3] is %d\0A\00"
@.str.5 = [27 x i8] c"The value of a[ 3 ] is %d\0A\00"
define void @fig06_13() {
%1 = alloca [5 x i32]
%2 = alloca i64
%3 = bitcast [5 x i32]* %1 to i8*
%4 = call i32 @puts(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %2
br label %5
5: ; preds = %13, %0
%6 = load i64, i64* %2
%7 = icmp ult i64 %6, 5
br i1 %7, label %8, label %16
8: ; preds = %5
%9 = load i64, i64* %2
%10 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %9
%11 = load i32, i32* %10
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %8
%14 = load i64, i64* %2
%15 = add i64 %14, 1
store i64 %15, i64* %2
br label %5
16: ; preds = %5
%17 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%18 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
%19 = call i32 @modifyArray(i32* %18, i32 5)
%20 = call i32 @puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
store i64 0, i64* %2
br label %21
21: ; preds = %29, %16
%22 = load i64, i64* %2
%23 = icmp ult i64 %22, 5
br i1 %23, label %24, label %32
24: ; preds = %21
%25 = load i64, i64* %2
%26 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %24
%30 = load i64, i64* %2
%31 = add i64 %30, 1
store i64 %31, i64* %2
br label %21
32: ; preds = %21
%33 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 3
%34 = load i32, i32* %33
%35 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.4, i64 0, i64 0), i32 %34)
%36 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 3
%37 = load i32, i32* %36
%38 = call i32 @modifyElement(i32 %37)
%39 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 3
%40 = load i32, i32* %39
%41 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %40)
ret void
}

LLVM IR (-O2):
@__const.fig06_13.a = [5 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4]
@.str = [84 x i8] c"Effects of passing entire array by reference:\0A\0AThe value of the original array are:\00"
@.str.1 = [4 x i8] c"%3d\00"
@.str.3 = [37 x i8] c"The value of the modified array are:\00"
@.str.4 = [71 x i8] c"\0A\0AEffects of passing array element by value:\0A\0AThe value of a[3] is %d\0A\00"
@.str.5 = [27 x i8] c"The value of a[ 3 ] is %d\0A\00"
define void @fig06_13() {
%1 = alloca [5 x i32]
%2 = bitcast [5 x i32]* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([84 x i8], [84 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
%5 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 0)
%6 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 1)
%8 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 2
%9 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 2)
%10 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 3
%11 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%12 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 4
%13 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4)
%14 = tail call i32 @putchar(i32 10)
%15 = call i32 @modifyArray(i32* %4, i32 5)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32, i32* %4
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %6
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %8
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %10
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %12
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %10
%28 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %10
%30 = call i32 @modifyElement(i32 %29)
%31 = load i32, i32* %10
%32 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %31)
ret void
}