#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 *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  char *p = (char *)malloc(14);
  char *q = (char *)malloc(16);
  printf("p=%p q=%p dist=%d\n", p, q, (int)(q - p));
  strcpy(&p[24], "Overflow");
  printf("%s\n", q);
  free(p);
  free(q);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0xe,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x10,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%ecx
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
add    $0x18,%rdi
lea    0xe76(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rsi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0xe,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x10,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %ebx,%ecx
sub    %r14d,%ecx
lea    0xe96(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x18(%r14),%rdi
lea    0xe91(%rip),%rsi
call   1040 <strcpy@plt>
lea    0xe8e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"p=%p q=%p dist=%d\0A\00"
@.str.1 = [9 x i8] c"Overflow\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = call i64 @malloc(i32 14)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %5
%9 = call i64 @malloc(i32 16)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %6
%11 = load i8*, i8** %5
%12 = load i8*, i8** %6
%13 = load i8*, i8** %6
%14 = load i8*, i8** %5
%15 = ptrtoint i8* %13 to i64
%16 = ptrtoint i8* %14 to i64
%17 = sub i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %12, i32 %18)
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 24
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%23 = load i8*, i8** %6
%24 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %5
%26 = call i32 @free(i8* %25)
%27 = load i8*, i8** %6
%28 = call i32 @free(i8* %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"p=%p q=%p dist=%d\0A\00"
@.str.1 = [9 x i8] c"Overflow\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 14)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i64 @malloc(i32 16)
%6 = inttoptr i64 %5 to i8*
%7 = sub i64 %5, %3
%8 = trunc i64 %7 to i32
%9 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %4, i8* %6, i32 %8)
%10 = getelementptr inbounds i8, i8* %4, i64 24
%11 = tail call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%13 = tail call i32 @free(i8* %4)
%14 = tail call i32 @free(i8* %6)
ret i32 0
}