#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*/ printf(char *, size_t, int);
int /*<<< orphan*/ puts(char *);
void fig07_20() {
  int b[] = {10, 20, 30, 40};
  int *bPtr = b;
  size_t i;
  size_t offset;
  puts("Array b printed with:\nArray sudirript notation");
  for (i = 0; i < 4; ++i) {
    printf("b[ %u ] = %d\n", i, b[i]);
  }
  puts("\nPointer/offset notation where\n"
       "the pointer is the array name");
  for (offset = 0; offset < 4; ++offset) {
    printf("*( b + %u ) = %d\n", offset, *(b + offset));
  }
  puts("\nPointer sudirript notation");
  for (i = 0; i < 4; ++i) {
    printf("bPtr[ %u ] = %d\n", i, bPtr[i]);
  }
  puts("\nPointer/offset notation");
  for (offset = 0; offset < 4; ++offset) {
    printf("*( bPtr + %u ) = %d\n", offset, *(bPtr + offset));
  }
}


x86 assembly (clang, -O0):
<fig07_20>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xece(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xec3(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x20(%rbp)
cmpq   $0x4,-0x20(%rbp)
jae    118e <fig07_20+0x6e>
mov    -0x20(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp,%rax,4),%edx
lea    0xec7(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115a <fig07_20+0x3a>
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x28(%rbp)
cmpq   $0x4,-0x28(%rbp)
jae    11d6 <fig07_20+0xb6>
mov    -0x28(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp,%rax,4),%edx
lea    0xeca(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11a2 <fig07_20+0x82>
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x20(%rbp)
cmpq   $0x4,-0x20(%rbp)
jae    1221 <fig07_20+0x101>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xead(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11ea <fig07_20+0xca>
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x28(%rbp)
cmpq   $0x4,-0x28(%rbp)
jae    126c <fig07_20+0x14c>
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1235 <fig07_20+0x115>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig07_20>:
push   %rbx
lea    0xed8(%rip),%rdi
call   1030 <puts@plt>
lea    0xefb(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <printf@plt>
mov    $0x1,%esi
mov    %rbx,%rdi
mov    $0x14,%edx
call   1040 <printf@plt>
mov    $0x2,%esi
mov    %rbx,%rdi
mov    $0x1e,%edx
call   1040 <printf@plt>
mov    $0x3,%esi
mov    %rbx,%rdi
mov    $0x28,%edx
call   1040 <printf@plt>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
lea    0xeee(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <printf@plt>
mov    $0x1,%esi
mov    %rbx,%rdi
mov    $0x14,%edx
call   1040 <printf@plt>
mov    $0x2,%esi
mov    %rbx,%rdi
mov    $0x1e,%edx
call   1040 <printf@plt>
mov    $0x3,%esi
mov    %rbx,%rdi
mov    $0x28,%edx
call   1040 <printf@plt>
lea    0xeb4(%rip),%rdi
call   1030 <puts@plt>
lea    0xec4(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <printf@plt>
mov    $0x1,%esi
mov    %rbx,%rdi
mov    $0x14,%edx
call   1040 <printf@plt>
mov    $0x2,%esi
mov    %rbx,%rdi
mov    $0x1e,%edx
call   1040 <printf@plt>
mov    $0x3,%esi
mov    %rbx,%rdi
mov    $0x28,%edx
call   1040 <printf@plt>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
lea    0xe96(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <printf@plt>
mov    $0x1,%esi
mov    %rbx,%rdi
mov    $0x14,%edx
call   1040 <printf@plt>
mov    $0x2,%esi
mov    %rbx,%rdi
mov    $0x1e,%edx
call   1040 <printf@plt>
mov    $0x3,%esi
mov    %rbx,%rdi
mov    $0x28,%edx
pop    %rbx
jmp    1040 <printf@plt>

LLVM IR (-O0):
@__const.fig07_20.b = [4 x i32] [i32 10, i32 20, i32 30, i32 40]
@.str = [47 x i8] c"Array b printed with:\0AArray sudirript notation\00"
@.str.1 = [14 x i8] c"b[ %u ] = %d\0A\00"
@.str.2 = [61 x i8] c"\0APointer/offset notation where\0Athe pointer is the array name\00"
@.str.3 = [18 x i8] c"*( b + %u ) = %d\0A\00"
@.str.4 = [28 x i8] c"\0APointer sudirript notation\00"
@.str.5 = [17 x i8] c"bPtr[ %u ] = %d\0A\00"
@.str.6 = [25 x i8] c"\0APointer/offset notation\00"
@.str.7 = [21 x i8] c"*( bPtr + %u ) = %d\0A\00"
define void @fig07_20() {
%1 = alloca [4 x i32]
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i64
%5 = bitcast [4 x i32]* %1 to i8*
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
store i32* %6, i32** %2
%7 = call i32 @puts(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %3
br label %8
8: ; preds = %17, %0
%9 = load i64, i64* %3
%10 = icmp ult i64 %9, 4
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = load i64, i64* %3
%13 = load i64, i64* %3
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %12, i32 %15)
br label %17
17: ; preds = %11
%18 = load i64, i64* %3
%19 = add i64 %18, 1
store i64 %19, i64* %3
br label %8
20: ; preds = %8
%21 = call i32 @puts(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0))
store i64 0, i64* %4
br label %22
22: ; preds = %32, %20
%23 = load i64, i64* %4
%24 = icmp ult i64 %23, 4
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = load i64, i64* %4
%27 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
%28 = load i64, i64* %4
%29 = getelementptr inbounds i32, i32* %27, i64 %28
%30 = load i32, i32* %29
%31 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i64 %26, i32 %30)
br label %32
32: ; preds = %25
%33 = load i64, i64* %4
%34 = add i64 %33, 1
store i64 %34, i64* %4
br label %22
35: ; preds = %22
%36 = call i32 @puts(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
store i64 0, i64* %3
br label %37
37: ; preds = %47, %35
%38 = load i64, i64* %3
%39 = icmp ult i64 %38, 4
br i1 %39, label %40, label %50
40: ; preds = %37
%41 = load i64, i64* %3
%42 = load i32*, i32** %2
%43 = load i64, i64* %3
%44 = getelementptr inbounds i32, i32* %42, i64 %43
%45 = load i32, i32* %44
%46 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i64 %41, i32 %45)
br label %47
47: ; preds = %40
%48 = load i64, i64* %3
%49 = add i64 %48, 1
store i64 %49, i64* %3
br label %37
50: ; preds = %37
%51 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
store i64 0, i64* %4
br label %52
52: ; preds = %62, %50
%53 = load i64, i64* %4
%54 = icmp ult i64 %53, 4
br i1 %54, label %55, label %65
55: ; preds = %52
%56 = load i64, i64* %4
%57 = load i32*, i32** %2
%58 = load i64, i64* %4
%59 = getelementptr inbounds i32, i32* %57, i64 %58
%60 = load i32, i32* %59
%61 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i64 %56, i32 %60)
br label %62
62: ; preds = %55
%63 = load i64, i64* %4
%64 = add i64 %63, 1
store i64 %64, i64* %4
br label %52
65: ; preds = %52
ret void
}

LLVM IR (-O2):
@.str = [47 x i8] c"Array b printed with:\0AArray sudirript notation\00"
@.str.1 = [14 x i8] c"b[ %u ] = %d\0A\00"
@.str.2 = [61 x i8] c"\0APointer/offset notation where\0Athe pointer is the array name\00"
@.str.3 = [18 x i8] c"*( b + %u ) = %d\0A\00"
@.str.4 = [28 x i8] c"\0APointer sudirript notation\00"
@.str.5 = [17 x i8] c"bPtr[ %u ] = %d\0A\00"
@.str.6 = [25 x i8] c"\0APointer/offset notation\00"
@.str.7 = [21 x i8] c"*( bPtr + %u ) = %d\0A\00"
define void @fig07_20() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 0, i32 10)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 1, i32 20)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 2, i32 30)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 3, i32 40)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i64 0, i32 10)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i64 1, i32 20)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i64 2, i32 30)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i64 3, i32 40)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%12 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i64 0, i32 10)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i64 1, i32 20)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i64 2, i32 30)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i64 3, i32 40)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%17 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i64 0, i32 10)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i64 1, i32 20)
%19 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i64 2, i32 30)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i64 3, i32 40)
ret void
}