#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*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int *p1 = malloc(sizeof(int));
  int *p2 = malloc(sizeof(int));
  int *p3 = malloc(sizeof(int));
  *p1 = 10;
  *p2 = 20;
  *p3 = *p1 + *p2;
  printf("address of p1 = %p, p2 = %p, p3 = %p\n", &p1, &p2, &p3);
  printf("address pointed by p1 = %p, p2 = %p, p3 = %p\n", p1, p2, p3);
  printf("value at address pointed by p1 = %d, p2 = %d, p3 = %d\n", *p1, *p2,
         *p3);
  free(p1);
  free(p2);
  free(p3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movl   $0xa,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x14,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
add    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
lea    0xe6a(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rax,0x10(%rsp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,0x8(%rsp)
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,(%rsp)
movl   $0xa,(%r14)
movl   $0x14,(%rbx)
movl   $0x1e,(%rax)
lea    0xe7d(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rsp,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
mov    (%rsp),%rcx
lea    0xe7a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%rax
mov    (%rax),%esi
mov    0x8(%rsp),%rax
mov    (%rax),%edx
mov    (%rsp),%rax
mov    (%rax),%ecx
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [38 x i8] c"address of p1 = %p, p2 = %p, p3 = %p\0A\00"
@.str.1 = [46 x i8] c"address pointed by p1 = %p, p2 = %p, p3 = %p\0A\00"
@.str.2 = [55 x i8] c"value at address pointed by p1 = %d, p2 = %d, p3 = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32* @malloc(i32 4)
store i32* %5, i32** %2
%6 = call i32* @malloc(i32 4)
store i32* %6, i32** %3
%7 = call i32* @malloc(i32 4)
store i32* %7, i32** %4
%8 = load i32*, i32** %2
store i32 10, i32* %8
%9 = load i32*, i32** %3
store i32 20, i32* %9
%10 = load i32*, i32** %2
%11 = load i32, i32* %10
%12 = load i32*, i32** %3
%13 = load i32, i32* %12
%14 = add nsw i32 %11, %13
%15 = load i32*, i32** %4
store i32 %14, i32* %15
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32** %2, i32** %3, i32** %4)
%17 = load i32*, i32** %2
%18 = load i32*, i32** %3
%19 = load i32*, i32** %4
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32* %17, i32* %18, i32* %19)
%21 = load i32*, i32** %2
%22 = load i32, i32* %21
%23 = load i32*, i32** %3
%24 = load i32, i32* %23
%25 = load i32*, i32** %4
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i32 %22, i32 %24, i32 %26)
%28 = load i32*, i32** %2
%29 = call i32 @free(i32* %28)
%30 = load i32*, i32** %3
%31 = call i32 @free(i32* %30)
%32 = load i32*, i32** %4
%33 = call i32 @free(i32* %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [38 x i8] c"address of p1 = %p, p2 = %p, p3 = %p\0A\00"
@.str.1 = [46 x i8] c"address pointed by p1 = %p, p2 = %p, p3 = %p\0A\00"
@.str.2 = [55 x i8] c"value at address pointed by p1 = %d, p2 = %d, p3 = %d\0A\00"
define i32 @main() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca i32*
%4 = bitcast i32** %1 to i8*
%5 = tail call i32* @malloc(i32 4)
store i32* %5, i32** %1
%6 = bitcast i32** %2 to i8*
%7 = tail call i32* @malloc(i32 4)
store i32* %7, i32** %2
%8 = bitcast i32** %3 to i8*
%9 = tail call i32* @malloc(i32 4)
store i32* %9, i32** %3
store i32 10, i32* %5
store i32 20, i32* %7
store i32 30, i32* %9
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32** %1, i32** %2, i32** %3)
%11 = load i32*, i32** %1
%12 = load i32*, i32** %2
%13 = load i32*, i32** %3
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32* %11, i32* %12, i32* %13)
%15 = load i32*, i32** %1
%16 = load i32, i32* %15
%17 = load i32*, i32** %2
%18 = load i32, i32* %17
%19 = load i32*, i32** %3
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i32 %16, i32 %18, i32 %20)
%22 = load i32*, i32** %1
%23 = call i32 @free(i32* %22)
%24 = load i32*, i32** %2
%25 = call i32 @free(i32* %24)
%26 = load i32*, i32** %3
%27 = call i32 @free(i32* %26)
ret i32 0
}