#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 *, ...);
void change_pointedto(int *pointer) {
  printf("CPT: Pointer is %p\n", pointer);
  printf("CPT: Pointer points to %d\n", *pointer);
  int *temp = malloc(sizeof(int));
  *temp = 12;
  printf("CPT: Temp is %p\n", temp);
  printf("CPT: Temp points to %d\n", *temp);
  *pointer = *temp;
  printf("CPT: Pointer is %p\n", pointer);
  printf("CPT: Pointer points to %d\n", *pointer);
  free(temp);
}


x86 assembly (clang, -O0):
<change_pointedto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0xc,(%rax)
mov    -0x10(%rbp),%rsi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rsi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_pointedto>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
lea    0xebe(%rip),%r14
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r12),%esi
lea    0xeba(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movl   $0xc,(%rax)
lea    0xeb1(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%esi
lea    0xeaf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%eax
mov    %eax,(%r12)
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r12),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"CPT: Pointer is %p\0A\00"
@.str.1 = [27 x i8] c"CPT: Pointer points to %d\0A\00"
@.str.2 = [17 x i8] c"CPT: Temp is %p\0A\00"
@.str.3 = [24 x i8] c"CPT: Temp points to %d\0A\00"
define void @change_pointedto(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
store i32* %0, i32** %2
%4 = load i32*, i32** %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32* %4)
%6 = load i32*, i32** %2
%7 = load i32, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = call i32* @malloc(i32 4)
store i32* %9, i32** %3
%10 = load i32*, i32** %3
store i32 12, i32* %10
%11 = load i32*, i32** %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32* %11)
%13 = load i32*, i32** %3
%14 = load i32, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = load i32*, i32** %3
%17 = load i32, i32* %16
%18 = load i32*, i32** %2
store i32 %17, i32* %18
%19 = load i32*, i32** %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32* %19)
%21 = load i32*, i32** %2
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load i32*, i32** %3
%25 = call i32 @free(i32* %24)
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"CPT: Pointer is %p\0A\00"
@.str.1 = [27 x i8] c"CPT: Pointer points to %d\0A\00"
@.str.2 = [17 x i8] c"CPT: Temp is %p\0A\00"
@.str.3 = [24 x i8] c"CPT: Temp points to %d\0A\00"
define void @change_pointedto(i32* %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32* %0)
%3 = load i32, i32* %0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = tail call i32* @malloc(i32 4)
store i32 12, i32* %5
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%7 = load i32, i32* %5
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %5
store i32 %9, i32* %0
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32* %0)
%11 = load i32, i32* %0
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = tail call i32 @free(i32* %5)
ret void
}