#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(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  char *a, *b, *c;
  a = malloc(0x100 - 8);
  b = malloc(0x100 - 8);
  c = malloc(0x80 - 8);
  printf("---------------init---------------\n");
  printf("a: %p -> %p\nb: %p -> %p\n", a, a + 0x100 - 8, b, b + 0x100 - 8);
  printf("c: %p -> %p\n", c, c + 0x80 - 8);
  printf("----------------------------------\n");
  free(b);
  a[0x100 - 8] = 0x81;
  printf("overflow: %x\n", a[0x100 - 8]);
  b = malloc(0x100 + 0x80 - 8);
  printf("------------overflowed------------\n");
  printf("b: %p -> %p [*]\n", b, b + 0x100 + 0x80 - 8);
  printf("a: %p -> %p\nc: %p -> %p\n", a, a + 0x100 - 8, c, c + 0x80 - 8);
  printf("----------------------------------\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0xf8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0xf8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x78,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    $0x100,%rdx
add    $0xfffffffffffffff8,%rdx
mov    -0x20(%rbp),%rcx
mov    -0x20(%rbp),%r8
add    $0x100,%r8
add    $0xfffffffffffffff8,%r8
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rsi
mov    -0x28(%rbp),%rdx
add    $0x80,%rdx
add    $0xfffffffffffffff8,%rdx
lea    0xeeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
movb   $0x81,0xf8(%rax)
mov    -0x18(%rbp),%rax
movsbl 0xf8(%rax),%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x178,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x20(%rbp),%rdx
add    $0x100,%rdx
add    $0x80,%rdx
add    $0xfffffffffffffff8,%rdx
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    $0x100,%rdx
add    $0xfffffffffffffff8,%rdx
mov    -0x28(%rbp),%rcx
mov    -0x28(%rbp),%r8
add    $0x80,%r8
add    $0xfffffffffffffff8,%r8
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xf8,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0xf8,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    $0x78,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0xed8(%rip),%rdi
call   1040 <puts@plt>
lea    0xf8(%rbx),%r15
lea    0xf8(%rbp),%r8
lea    0xe6d(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x78(%r14),%r12
lea    0xe96(%rip),%rdi
mov    %r14,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed5(%rip),%r13
mov    %r13,%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
movb   $0x81,0xf8(%rbx)
lea    0xe39(%rip),%rdi
mov    $0xffffff81,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x178,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
lea    0xe74(%rip),%rdi
call   1040 <puts@plt>
lea    0x178(%rbp),%rdx
lea    0xe14(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe14(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"---------------init---------------\0A\00"
@.str.1 = [25 x i8] c"a: %p -> %p\0Ab: %p -> %p\0A\00"
@.str.2 = [13 x i8] c"c: %p -> %p\0A\00"
@.str.3 = [36 x i8] c"----------------------------------\0A\00"
@.str.4 = [14 x i8] c"overflow: %x\0A\00"
@.str.5 = [36 x i8] c"------------overflowed------------\0A\00"
@.str.6 = [17 x i8] c"b: %p -> %p [*]\0A\00"
@.str.7 = [25 x i8] c"a: %p -> %p\0Ac: %p -> %p\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = call i8* @malloc(i32 248)
store i8* %8, i8** %5
%9 = call i8* @malloc(i32 248)
store i8* %9, i8** %6
%10 = call i8* @malloc(i32 120)
store i8* %10, i8** %7
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%12 = load i8*, i8** %5
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i64 256
%15 = getelementptr inbounds i8, i8* %14, i64 -8
%16 = load i8*, i8** %6
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i64 256
%19 = getelementptr inbounds i8, i8* %18, i64 -8
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* %15, i8* %16, i8* %19)
%21 = load i8*, i8** %7
%22 = load i8*, i8** %7
%23 = getelementptr inbounds i8, i8* %22, i64 128
%24 = getelementptr inbounds i8, i8* %23, i64 -8
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %21, i8* %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%27 = load i8*, i8** %6
%28 = call i32 @free(i8* %27)
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i64 248
store i8 -127, i8* %30
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i64 248
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %34)
%36 = call i8* @malloc(i32 376)
store i8* %36, i8** %6
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%38 = load i8*, i8** %6
%39 = load i8*, i8** %6
%40 = getelementptr inbounds i8, i8* %39, i64 256
%41 = getelementptr inbounds i8, i8* %40, i64 128
%42 = getelementptr inbounds i8, i8* %41, i64 -8
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %38, i8* %42)
%44 = load i8*, i8** %5
%45 = load i8*, i8** %5
%46 = getelementptr inbounds i8, i8* %45, i64 256
%47 = getelementptr inbounds i8, i8* %46, i64 -8
%48 = load i8*, i8** %7
%49 = load i8*, i8** %7
%50 = getelementptr inbounds i8, i8* %49, i64 128
%51 = getelementptr inbounds i8, i8* %50, i64 -8
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %44, i8* %47, i8* %48, i8* %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [25 x i8] c"a: %p -> %p\0Ab: %p -> %p\0A\00"
@.str.2 = [13 x i8] c"c: %p -> %p\0A\00"
@.str.4 = [14 x i8] c"overflow: %x\0A\00"
@.str.6 = [17 x i8] c"b: %p -> %p [*]\0A\00"
@.str.7 = [25 x i8] c"a: %p -> %p\0Ac: %p -> %p\0A\00"
@str = [35 x i8] c"---------------init---------------\00"
@str.9 = [35 x i8] c"------------overflowed------------\00"
@str.10 = [35 x i8] c"----------------------------------\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(248) i8* @malloc(i32 248)
%4 = tail call dereferenceable_or_null(248) i8* @malloc(i32 248)
%5 = tail call dereferenceable_or_null(120) i8* @malloc(i32 120)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%7 = getelementptr inbounds i8, i8* %3, i64 248
%8 = getelementptr inbounds i8, i8* %4, i64 248
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %7, i8* %4, i8* %8)
%10 = getelementptr inbounds i8, i8* %5, i64 120
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %5, i8* %10)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.10, i64 0, i64 0))
%13 = tail call i32 @free(i8* %4)
store i8 -127, i8* %7
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 -127)
%15 = tail call dereferenceable_or_null(376) i8* @malloc(i32 376)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.9, i64 0, i64 0))
%17 = getelementptr inbounds i8, i8* %15, i64 376
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %15, i8* %17)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %3, i8* %7, i8* %5, i8* %10)
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.10, i64 0, i64 0))
ret i32 0
}