#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 */
typedef int /*<<< orphan*/ ptr;

/* Variables and functions */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char, int);
scalar_t__ realloc_rewrite(char **, int, int);
int main() {
  char *ptr = NULL;
  ptr = (char *)malloc(10);
  ptr[0] = 1;
  ptr[1] = 2;
  printf("%d %d\n", ptr[1], sizeof(ptr));
  if (realloc_rewrite(&ptr, 10, 100))
    printf("%d %d\n", ptr[1], sizeof(ptr));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0xa,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x1,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x2,0x1(%rax)
mov    -0x10(%rbp),%rax
lea    0xe91(%rip),%rdi
mov    $0x8,%edx
movsbl 0x1(%rax),%esi
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
mov    $0xa,%esi
mov    $0x64,%edx
call   1040 <realloc_rewrite@plt>
cmp    $0x0,%rax
je     11b3 <main+0x83>
mov    -0x10(%rbp),%rax
lea    0xe5b(%rip),%rdi
mov    $0x8,%edx
movsbl 0x1(%rax),%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0xa,%edi
call   1050 <malloc@plt>
mov    %rax,(%rsp)
movb   $0x1,(%rax)
mov    (%rsp),%rax
movb   $0x2,0x1(%rax)
mov    (%rsp),%rax
movsbl 0x1(%rax),%esi
lea    0xea7(%rip),%rdi
mov    $0x8,%edx
call   1030 <printf@plt>
mov    %rsp,%rdi
mov    $0xa,%esi
mov    $0x64,%edx
call   1040 <realloc_rewrite@plt>
test   %rax,%rax
je     1193 <main+0x63>
mov    (%rsp),%rax
movsbl 0x1(%rax),%esi
lea    0xe77(%rip),%rdi
mov    $0x8,%edx
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%d %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
store i8* null, i8** %2
%3 = call i64 @malloc(i32 10)
%4 = inttoptr i64 %3 to i8*
store i8* %4, i8** %2
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i64 0
store i8 1, i8* %6
%7 = load i8*, i8** %2
%8 = getelementptr inbounds i8, i8* %7, i64 1
store i8 2, i8* %8
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = load i8, i8* %10
%12 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 signext %11, i32 8)
%13 = call i64 @realloc_rewrite(i8** %2, i32 10, i32 100)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %0
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 signext %18, i32 8)
br label %20
20: ; preds = %15, %0
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d %d\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = tail call i64 @malloc(i32 10)
%4 = inttoptr i64 %3 to i8*
store i8* %4, i8** %1
store i8 1, i8* %4
%5 = load i8*, i8** %1
%6 = getelementptr inbounds i8, i8* %5, i64 1
store i8 2, i8* %6
%7 = load i8*, i8** %1
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = load i8, i8* %8
%10 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 signext %9, i32 8)
%11 = call i64 @realloc_rewrite(i8** %1, i32 10, i32 100)
%12 = icmp eq i64 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %0
%14 = load i8*, i8** %1
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 signext %16, i32 8)
br label %18
18: ; preds = %13, %0
ret i32 0
}