#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*/ s;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, int);
char *realloc(char *, int);
int main() {
  char *s;
  printf("Before malloc:\n\tsizeof(s) = [%d]\n", (int)sizeof(s));
  s = malloc(sizeof(char) * 10);
  printf("After malloc(char * 10):\n\tsizeof(s) = [%d]\n", (int)sizeof(s));
  s = realloc(s, sizeof(char) * 100);
  printf("After realloc(char * 100):\n\tsizeof(s) = [%d]\n", (int)sizeof(s));
  free(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x8,%esi
call   1040 <printf@plt>
mov    $0xa,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xead(%rip),%rdi
mov    $0x8,%esi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x64,%esi
call   1060 <realloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xeb6(%rip),%rdi
mov    $0x8,%esi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rdi
mov    $0x8,%esi
call   1040 <printf@plt>
mov    $0xa,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xebc(%rip),%rdi
mov    $0x8,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
call   1060 <realloc@plt>
mov    %rax,%rbx
lea    0xec7(%rip),%rdi
mov    $0x8,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Before malloc:\0A\09sizeof(s) = [%d]\0A\00"
@.str.1 = [44 x i8] c"After malloc(char * 10):\0A\09sizeof(s) = [%d]\0A\00"
@.str.2 = [46 x i8] c"After realloc(char * 100):\0A\09sizeof(s) = [%d]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 8)
%4 = call i8* @malloc(i32 10)
store i8* %4, i8** %2
%5 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 8)
%6 = load i8*, i8** %2
%7 = call i8* @realloc(i8* %6, i32 100)
store i8* %7, i8** %2
%8 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 8)
%9 = load i8*, i8** %2
%10 = call i32 @free(i8* %9)
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"Before malloc:\0A\09sizeof(s) = [%d]\0A\00"
@.str.1 = [44 x i8] c"After malloc(char * 10):\0A\09sizeof(s) = [%d]\0A\00"
@.str.2 = [46 x i8] c"After realloc(char * 100):\0A\09sizeof(s) = [%d]\0A\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 8)
%2 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 8)
%4 = tail call i8* @realloc(i8* %2, i32 100)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 8)
%6 = tail call i32 @free(i8* %4)
ret i32 0
}