#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 *fun();
int /*<<< orphan*/ printf(char *, ...);
char *teststack();
int main() {
  int *ret = fun();
  printf("ret addr=0x%p, val=%d\n", ret, ret[0]);
  ret[0] = 200;
  printf("----ret addr=0x%p, val=%d\n", ret, ret[0]);
  char *ptr = teststack();
  printf("ptr=0x%p, data=%s\n", ptr, ptr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <fun@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
movl   $0xc8,(%rax)
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <teststack@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1030 <fun@plt>
mov    %rax,%rbx
mov    (%rax),%edx
lea    0xec0(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0xc8,(%rbx)
lea    0xea5(%rip),%rdi
mov    %rbx,%rsi
mov    $0xc8,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <teststack@plt>
lea    0xea3(%rip),%rdi
mov    %rax,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"ret addr=0x%p, val=%d\0A\00"
@.str.1 = [27 x i8] c"----ret addr=0x%p, val=%d\0A\00"
@.str.2 = [19 x i8] c"ptr=0x%p, data=%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i32* (...) @fun()
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = load i32*, i32** %2
%7 = getelementptr inbounds i32, i32* %6, i64 0
%8 = load i32, i32* %7
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32* %5, i32 %8)
%10 = load i32*, i32** %2
%11 = getelementptr inbounds i32, i32* %10, i64 0
store i32 200, i32* %11
%12 = load i32*, i32** %2
%13 = load i32*, i32** %2
%14 = getelementptr inbounds i32, i32* %13, i64 0
%15 = load i32, i32* %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32* %12, i32 %15)
%17 = call i8* (...) @teststack()
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = load i8*, i8** %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %18, i8* %19)
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"ret addr=0x%p, val=%d\0A\00"
@.str.1 = [27 x i8] c"----ret addr=0x%p, val=%d\0A\00"
@.str.2 = [19 x i8] c"ptr=0x%p, data=%s\0A\00"
define i32 @main() {
%1 = tail call i32* (...) @fun()
%2 = load i32, i32* %1
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32* %1, i32 %2)
store i32 200, i32* %1
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32 200)
%5 = tail call i8* (...) @teststack()
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %5, i8* %5)
ret i32 0
}