void sample3() {
  int a = 1;
  int b = 2;
  int c = 3;
  printf("The growth direction of the stack: &a=%d,&b=%d,&c=%d\n", &a, &b, &c);
  int *pInt = malloc(3 * sizeof(int));
  printf("The growth direction of the heap: p1=%d,p2=%d,p3=%d\n", pInt,
         pInt + 1, pInt + 2);
  free(pInt);
}


x86 assembly (clang, -O0):
<sample3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x1,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0x3,-0xc(%rbp)
lea    0xeac(%rip),%rdi
lea    -0x4(%rbp),%rsi
lea    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xc,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    $0x4,%rdx
mov    -0x18(%rbp),%rcx
add    $0x8,%rcx
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sample3>:
push   %rbx
sub    $0x10,%rsp
movl   $0x1,0xc(%rsp)
movl   $0x2,0x8(%rsp)
movl   $0x3,0x4(%rsp)
lea    0xeac(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xc,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0x4(%rax),%rdx
lea    0x8(%rax),%rcx
lea    0xeb0(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [54 x i8] c"The growth direction of the stack: &a=%d,&b=%d,&c=%d\0A\00"
@.str.1 = [53 x i8] c"The growth direction of the heap: p1=%d,p2=%d,p3=%d\0A\00"
define void @sample3() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
store i32 1, i32* %1
store i32 2, i32* %2
store i32 3, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%6 = call i8* @malloc(i64 12)
%7 = bitcast i8* %6 to i32*
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = load i32*, i32** %4
%10 = getelementptr inbounds i32, i32* %9, i64 1
%11 = load i32*, i32** %4
%12 = getelementptr inbounds i32, i32* %11, i64 2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i32* %8, i32* %10, i32* %12)
%14 = load i32*, i32** %4
%15 = bitcast i32* %14 to i8*
ret void
}

LLVM IR (-O2):
@.str = [54 x i8] c"The growth direction of the stack: &a=%d,&b=%d,&c=%d\0A\00"
@.str.1 = [53 x i8] c"The growth direction of the heap: p1=%d,p2=%d,p3=%d\0A\00"
define void @sample3() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%5 = bitcast i32* %2 to i8*
store i32 2, i32* %2
%6 = bitcast i32* %3 to i8*
store i32 3, i32* %3
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%8 = call dereferenceable_or_null(12) i8* @malloc(i64 12)
%9 = bitcast i8* %8 to i32*
%10 = getelementptr inbounds i32, i32* %9, i64 1
%11 = getelementptr inbounds i32, i32* %9, i64 2
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), i8* %8, i32* %10, i32* %11)
ret void
}