#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
char *realloc(char *, int);
int /*<<< orphan*/ stderr;
int main() {
  char *c = malloc(13);
  char *tmp;
  fprintf(stderr, "got %p\n", c);
  c[0] = 14;
  tmp = realloc(c, 12345);
  ++tmp[0];
  if (tmp[0] != 15)
    abort();
  free(tmp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xd,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe7f(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
movb   $0xe,(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x3039,%esi
call   1070 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
add    $0x1,%cl
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xf,%eax
je     11c1 <main+0x71>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0xd,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
movb   $0xe,(%rbx)
mov    %rbx,%rdi
mov    $0x3039,%esi
call   1070 <realloc@plt>
mov    (%rax),%cl
add    $0x1,%cl
mov    %cl,(%rax)
cmp    $0xf,%cl
jne    119e <main+0x4e>
mov    %rax,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [8 x i8] c"got %p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i8* @malloc(i32 13)
store i8* %4, i8** %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %2
%7 = call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %2
%9 = getelementptr inbounds i8, i8* %8, i64 0
store i8 14, i8* %9
%10 = load i8*, i8** %2
%11 = call i8* @realloc(i8* %10, i32 12345)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = add i8 %14, 1
store i8 %15, i8* %13
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 15
br i1 %20, label %21, label %23
21: ; preds = %0
%22 = call i32 (...) @abort()
unreachable
23: ; preds = %0
%24 = load i8*, i8** %3
%25 = call i32 @free(i8* %24)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [8 x i8] c"got %p\0A\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(13) i8* @malloc(i32 13)
%2 = load i32, i32* @stderr
%3 = tail call i32 @fprintf(i32 %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %1)
store i8 14, i8* %1
%4 = tail call i8* @realloc(i8* %1, i32 12345)
%5 = load i8, i8* %4
%6 = add i8 %5, 1
store i8 %6, i8* %4
%7 = icmp eq i8 %6, 15
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = tail call i32 (...) @abort()
unreachable
10: ; preds = %0
%11 = tail call i32 @free(i8* %4)
ret i32 0
}