#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 *, ...);
void test() {
  int arr[3] = {1, 10, 3};
#pragma mark-- 递增一个指针
  int *p = arr;
  for (int i = 0; i < 3; i++) {
    printf("存储地址： arr[%d] = %p \n", i, p);
    printf("存储值： arr[%d] = %d \n", i, *p);
    p++;
  }
  printf("***********************************\n");
#pragma mark--递减一个指针
  int *p2 = &arr[2];
  for (int i = 2; i >= 0; i--) {
    printf("存储地址： arr[%d] = %p \n", i, p2);
    printf("存储值： arr[%d] = %d \n", i, *p2);
    p2--;
  }
  printf("***********************************\n");
#pragma mark-- 指针的比较 (指针可以用关系运算符进行比较，如 ==、< 和 >)
  int *p3 = arr;
  int i = 0;
  while (p3 <= &arr[2]) {
    printf("存储地址： arr[%d] = %p \n", i, p3);
    printf("存储值： arr[%d] = %d \n", i, *p3);
    p3++;
    i++;
  }
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0xee1(%rip),%rax
mov    %rax,-0xc(%rbp)
mov    0xedf(%rip),%eax
mov    %eax,-0x4(%rbp)
lea    -0xc(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    118b <test+0x7b>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113b <test+0x2b>
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xc(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
movl   $0x2,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     11fc <test+0xec>
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rdx
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ac <test+0x9c>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xc(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x38(%rbp),%rax
lea    -0xc(%rbp),%rcx
add    $0x8,%rcx
cmp    %rcx,%rax
ja     1274 <test+0x164>
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%rdx
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1219 <test+0x109>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0xed4(%rip),%eax
mov    %eax,0x10(%rsp)
mov    0xec1(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%rbx
lea    0xeb7(%rip),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%edx
lea    0xebc(%rip),%r12
mov    %r12,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%r13
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%edx
mov    %r12,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    $0x2,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%edx
mov    %r12,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe76(%rip),%rbp
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    $0x2,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%edx
mov    %r12,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%edx
mov    %r12,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%edx
mov    %r12,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%edx
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x4,%rbx
add    $0x1,%ebp
cmp    %r14,%rbx
jbe    1250 <test+0x130>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.test.arr = [3 x i32] [i32 1, i32 10, i32 3]
@.str = [31 x i8] c"\E5\AD\98\E5\82\A8\E5\9C\B0\E5\9D\80\EF\BC\9A arr[%d] = %p \0A\00"
@.str.1 = [28 x i8] c"\E5\AD\98\E5\82\A8\E5\80\BC\EF\BC\9A arr[%d] = %d \0A\00"
@.str.2 = [37 x i8] c"***********************************\0A\00"
define void @test() {
%1 = alloca [3 x i32]
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = bitcast [3 x i32]* %1 to i8*
%9 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
store i32* %9, i32** %2
store i32 0, i32* %3
br label %10
10: ; preds = %23, %0
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = load i32, i32* %3
%15 = load i32*, i32** %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %14, i32* %15)
%17 = load i32, i32* %3
%18 = load i32*, i32** %2
%19 = load i32, i32* %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %19)
%21 = load i32*, i32** %2
%22 = getelementptr inbounds i32, i32* %21, i32 1
store i32* %22, i32** %2
br label %23
23: ; preds = %13
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %10
26: ; preds = %10
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%28 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
store i32* %28, i32** %4
store i32 2, i32* %5
br label %29
29: ; preds = %42, %26
%30 = load i32, i32* %5
%31 = icmp sge i32 %30, 0
br i1 %31, label %32, label %45
32: ; preds = %29
%33 = load i32, i32* %5
%34 = load i32*, i32** %4
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %33, i32* %34)
%36 = load i32, i32* %5
%37 = load i32*, i32** %4
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %36, i32 %38)
%40 = load i32*, i32** %4
%41 = getelementptr inbounds i32, i32* %40, i32 -1
store i32* %41, i32** %4
br label %42
42: ; preds = %32
%43 = load i32, i32* %5
%44 = add nsw i32 %43, -1
store i32 %44, i32* %5
br label %29
45: ; preds = %29
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%47 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
store i32* %47, i32** %6
store i32 0, i32* %7
br label %48
48: ; preds = %52, %45
%49 = load i32*, i32** %6
%50 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
%51 = icmp ule i32* %49, %50
br i1 %51, label %52, label %64
52: ; preds = %48
%53 = load i32, i32* %7
%54 = load i32*, i32** %6
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %53, i32* %54)
%56 = load i32, i32* %7
%57 = load i32*, i32** %6
%58 = load i32, i32* %57
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %56, i32 %58)
%60 = load i32*, i32** %6
%61 = getelementptr inbounds i32, i32* %60, i32 1
store i32* %61, i32** %6
%62 = load i32, i32* %7
%63 = add nsw i32 %62, 1
store i32 %63, i32* %7
br label %48
64: ; preds = %48
ret void
}

LLVM IR (-O2):
@__const.test.arr = [3 x i32] [i32 1, i32 10, i32 3]
@.str = [31 x i8] c"\E5\AD\98\E5\82\A8\E5\9C\B0\E5\9D\80\EF\BC\9A arr[%d] = %p \0A\00"
@.str.1 = [28 x i8] c"\E5\AD\98\E5\82\A8\E5\80\BC\EF\BC\9A arr[%d] = %d \0A\00"
@str.3 = [36 x i8] c"***********************************\00"
define void @test() {
%1 = alloca [3 x i32]
%2 = bitcast [3 x i32]* %1 to i8*
%3 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 0, i32* %3)
%5 = load i32, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %5)
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 1, i32* %7)
%9 = load i32, i32* %7
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %9)
%11 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 2, i32* %11)
%13 = load i32, i32* %11
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 %13)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0))
%16 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 2, i32* %16)
%18 = load i32, i32* %16
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 %18)
%20 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 1, i32* %20)
%22 = load i32, i32* %20
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %22)
%24 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 0, i32* %24)
%26 = load i32, i32* %24
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %26)
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.3, i64 0, i64 0))
br label %29
29: ; preds = %0, %29
%30 = phi i32 [ 0, %0 ], [ %36, %29 ]
%31 = phi i32* [ %3, %0 ], [ %35, %29 ]
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %30, i32* %31)
%33 = load i32, i32* %31
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %33)
%35 = getelementptr inbounds i32, i32* %31, i64 1
%36 = add nuw nsw i32 %30, 1
%37 = icmp ugt i32* %35, %16
br i1 %37, label %38, label %29
38: ; preds = %29
ret void
}