main() {
  int a, b, *p, *q;
  p = &a;
  q = &b;
  printf("Address of p is %d and address of p+1 is %d.\n", p, p + 1);
  printf("Address of p is %d and address of p+3 is %d.\n", p, p + 3);
  printf("Address of p is %d and address of p-2 is %d.\n", p, p - 2);
  printf("Address of p is %d and address of q is %d and p-q is %d.\n", p, q,
         p - q);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x4(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rdx
add    $0x4,%rdx
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rdx
add    $0xc,%rdx
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rdx
add    $0xfffffffffffffff8,%rdx
lea    0xeed(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rax,%rcx
sar    $0x2,%rcx
lea    0xef6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rdx
lea    0xedf(%rip),%rdi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x14(%rsp),%rdx
lea    0xef2(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    (%rsp),%rdx
lea    0xf0b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xc(%rsp),%rdx
mov    %rbx,%rcx
sub    %rdx,%rcx
sar    $0x2,%rcx
lea    0xf19(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [46 x i8] c"Address of p is %d and address of p+1 is %d.\0A\00"
@.str.1 = [46 x i8] c"Address of p is %d and address of p+3 is %d.\0A\00"
@.str.2 = [46 x i8] c"Address of p is %d and address of p-2 is %d.\0A\00"
@.str.3 = [58 x i8] c"Address of p is %d and address of q is %d and p-q is %d.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
store i32* %1, i32** %3
store i32* %2, i32** %4
%5 = load i32*, i32** %3
%6 = load i32*, i32** %3
%7 = getelementptr inbounds i32, i32* %6, i64 1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %7)
%9 = load i32*, i32** %3
%10 = load i32*, i32** %3
%11 = getelementptr inbounds i32, i32* %10, i64 3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32* %9, i32* %11)
%13 = load i32*, i32** %3
%14 = load i32*, i32** %3
%15 = getelementptr inbounds i32, i32* %14, i64 -2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32* %13, i32* %15)
%17 = load i32*, i32** %3
%18 = load i32*, i32** %4
%19 = load i32*, i32** %3
%20 = load i32*, i32** %4
%21 = ptrtoint i32* %19 to i64
%22 = ptrtoint i32* %20 to i64
%23 = sub i64 %21, %22
%24 = sdiv exact i64 %23, 4
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i32* %17, i32* %18, i64 %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [46 x i8] c"Address of p is %d and address of p+1 is %d.\0A\00"
@.str.1 = [46 x i8] c"Address of p is %d and address of p+3 is %d.\0A\00"
@.str.2 = [46 x i8] c"Address of p is %d and address of p-2 is %d.\0A\00"
@.str.3 = [58 x i8] c"Address of p is %d and address of q is %d and p-q is %d.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds i32, i32* %1, i64 1
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %5)
%7 = getelementptr inbounds i32, i32* %1, i64 3
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %7)
%9 = getelementptr inbounds i32, i32* %1, i64 -2
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32* %1, i32* %9)
%11 = ptrtoint i32* %1 to i64
%12 = ptrtoint i32* %2 to i64
%13 = sub i64 %11, %12
%14 = ashr exact i64 %13, 2
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.3, i64 0, i64 0), i32* %1, i32* %2, i64 %14)
ret i32 0
}