#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 *);
int main() {
  int p = 5;
  int *ptr1 = &p;
  int **ptr2 = &ptr1;
  int ***ptr3 = &ptr2;
  printf("value of *ptr1 %d\n", *ptr1);
  printf("value of **ptr2 %d\n", **ptr2);
  printf("value of ***ptr3 %d\n", ***ptr3);
  printf("address of ptr1 %p\n", (void *)&ptr1);
  printf("address of ptr2 %p\n", (void *)&ptr2);
  printf("address of ptr3 %p\n", (void *)&ptr3);
  printf("address of *ptr2 %p\n", (void *)ptr2);
  printf("address of *ptr3 %p\n", (void *)ptr3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x8(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq (%rax),%rsi
lea    0xeb4(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq (%rax),%rsi
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
movslq (%rax),%rsi
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
lea    -0x10(%rbp),%rsi
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
lea    -0x18(%rbp),%rsi
lea    0xeb5(%rip),%rdi
call   1030 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xeb9(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xebd(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xec2(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movl   $0x5,0x14(%rsp)
lea    0x14(%rsp),%rax
mov    %rax,0x20(%rsp)
lea    0x20(%rsp),%rbx
mov    %rbx,0x8(%rsp)
lea    0x8(%rsp),%r14
mov    %r14,0x18(%rsp)
lea    0xebc(%rip),%rdi
mov    $0x5,%esi
call   1030 <printf@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%rax
movslq (%rax),%rsi
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%rax
movslq (%rax),%rsi
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
lea    0xebe(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
lea    0xec3(%rip),%rdi
lea    0x18(%rsp),%rsi
call   1030 <printf@plt>
mov    0x8(%rsp),%rsi
lea    0xec1(%rip),%rdi
call   1030 <printf@plt>
mov    0x18(%rsp),%rsi
lea    0xec5(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"value of *ptr1 %d\0A\00"
@.str.1 = [20 x i8] c"value of **ptr2 %d\0A\00"
@.str.2 = [21 x i8] c"value of ***ptr3 %d\0A\00"
@.str.3 = [20 x i8] c"address of ptr1 %p\0A\00"
@.str.4 = [20 x i8] c"address of ptr2 %p\0A\00"
@.str.5 = [20 x i8] c"address of ptr3 %p\0A\00"
@.str.6 = [21 x i8] c"address of *ptr2 %p\0A\00"
@.str.7 = [21 x i8] c"address of *ptr3 %p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32**
%5 = alloca i32***
store i32 0, i32* %1
store i32 5, i32* %2
store i32* %2, i32** %3
store i32** %3, i32*** %4
store i32*** %4, i32**** %5
%6 = load i32*, i32** %3
%7 = load i32, i32* %6
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i8*
%10 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32**, i32*** %4
%12 = load i32*, i32** %11
%13 = load i32, i32* %12
%14 = sext i32 %13 to i64
%15 = inttoptr i64 %14 to i8*
%16 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i32***, i32**** %5
%18 = load i32**, i32*** %17
%19 = load i32*, i32** %18
%20 = load i32, i32* %19
%21 = sext i32 %20 to i64
%22 = inttoptr i64 %21 to i8*
%23 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = bitcast i32** %3 to i8*
%25 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = bitcast i32*** %4 to i8*
%27 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %26)
%28 = bitcast i32**** %5 to i8*
%29 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %28)
%30 = load i32**, i32*** %4
%31 = bitcast i32** %30 to i8*
%32 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %31)
%33 = load i32***, i32**** %5
%34 = bitcast i32*** %33 to i8*
%35 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %34)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"value of *ptr1 %d\0A\00"
@.str.1 = [20 x i8] c"value of **ptr2 %d\0A\00"
@.str.2 = [21 x i8] c"value of ***ptr3 %d\0A\00"
@.str.3 = [20 x i8] c"address of ptr1 %p\0A\00"
@.str.4 = [20 x i8] c"address of ptr2 %p\0A\00"
@.str.5 = [20 x i8] c"address of ptr3 %p\0A\00"
@.str.6 = [21 x i8] c"address of *ptr2 %p\0A\00"
@.str.7 = [21 x i8] c"address of *ptr3 %p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32**
%4 = alloca i32***
%5 = bitcast i32* %1 to i8*
store i32 5, i32* %1
%6 = bitcast i32** %2 to i8*
store i32* %1, i32** %2
%7 = bitcast i32*** %3 to i8*
store i32** %2, i32*** %3
%8 = bitcast i32**** %4 to i8*
store i32*** %3, i32**** %4
%9 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* inttoptr (i64 5 to i8*))
%10 = load i32**, i32*** %3
%11 = load i32*, i32** %10
%12 = load i32, i32* %11
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i8*
%15 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i32**, i32*** %3
%17 = load i32*, i32** %16
%18 = load i32, i32* %17
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i8*
%21 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%23 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%24 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%25 = bitcast i32*** %3 to i8**
%26 = load i8*, i8** %25
%27 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %26)
%28 = bitcast i32**** %4 to i8**
%29 = load i8*, i8** %28
%30 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %29)
ret i32 0
}