#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*/ abort();
int *malloc(int);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int stack[80];
  int *heap;
  int *heap_save;
  heap = malloc(80 * sizeof(int));
  if (!heap) {
    perror(NULL);
    abort();
  }
  heap_save = heap;
  printf("second int: stack=%d heap=%d\n", stack[1], heap[1]);
  printf("second int: stack=%d heap=%d\n", *(stack + 1), *(heap + 1));
  printf("before: %p\n", heap);
  heap++;
  printf("after: %p\n", heap);
  printf("second int: %d %d\n", *heap, heap[0]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x140,%edi
call   1050 <malloc@plt>
mov    %rax,-0x158(%rbp)
cmpq   $0x0,-0x158(%rbp)
jne    1181 <main+0x41>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x158(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x14c(%rbp),%esi
mov    -0x158(%rbp),%rax
mov    0x4(%rax),%edx
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14c(%rbp),%esi
mov    -0x158(%rbp),%rax
mov    0x4(%rax),%edx
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x158(%rbp),%rsi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x158(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x158(%rbp)
mov    -0x158(%rbp),%rsi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x158(%rbp),%rax
mov    (%rax),%esi
mov    -0x158(%rbp),%rax
mov    (%rax),%edx
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x140,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11c4 <main+0x84>
mov    %rax,%rbx
mov    %rax,%r14
add    $0x4,%r14
mov    0x4(%rax),%ebp
lea    0xe96(%rip),%r15
mov    %r15,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe95(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe90(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rbx),%edx
lea    0xe87(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   1060 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"second int: stack=%d heap=%d\0A\00"
@.str.1 = [12 x i8] c"before: %p\0A\00"
@.str.2 = [11 x i8] c"after: %p\0A\00"
@.str.3 = [19 x i8] c"second int: %d %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [80 x i32]
%6 = alloca i32*
%7 = alloca i32*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = call i32* @malloc(i32 320)
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = call i32 @perror(i32* null)
%13 = call i32 (...) @abort()
unreachable
14: ; preds = %2
%15 = load i32*, i32** %6
store i32* %15, i32** %7
%16 = getelementptr inbounds [80 x i32], [80 x i32]* %5, i64 0, i64 1
%17 = load i32, i32* %16
%18 = load i32*, i32** %6
%19 = getelementptr inbounds i32, i32* %18, i64 1
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %20)
%22 = getelementptr inbounds [80 x i32], [80 x i32]* %5, i64 0, i64 0
%23 = getelementptr inbounds i32, i32* %22, i64 1
%24 = load i32, i32* %23
%25 = load i32*, i32** %6
%26 = getelementptr inbounds i32, i32* %25, i64 1
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %24, i32 %27)
%29 = load i32*, i32** %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32* %29)
%31 = load i32*, i32** %6
%32 = getelementptr inbounds i32, i32* %31, i32 1
store i32* %32, i32** %6
%33 = load i32*, i32** %6
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32* %33)
%35 = load i32*, i32** %6
%36 = load i32, i32* %35
%37 = load i32*, i32** %6
%38 = getelementptr inbounds i32, i32* %37, i64 0
%39 = load i32, i32* %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %36, i32 %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"second int: stack=%d heap=%d\0A\00"
@.str.1 = [12 x i8] c"before: %p\0A\00"
@.str.2 = [11 x i8] c"after: %p\0A\00"
@.str.3 = [19 x i8] c"second int: %d %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @malloc(i32 320)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i32* null)
%7 = tail call i32 (...) @abort()
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i32, i32* %3, i64 1
%10 = load i32, i32* %9
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 undef, i32 %10)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 undef, i32 %10)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32* %9)
%15 = load i32, i32* %9
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %15, i32 %15)
ret i32 0
}