void main() {
  float *p, *q;
  int i;
  p = (float *)malloc(5 * sizeof(float));
  q = p;
  p = (float *)realloc(p, (5 + 3) * sizeof(float));
  printf("p=0x%x\n", p);
  printf("q=0x%x\n", q);
  printf("Len=%d\n", sizeof(float));
  for (i = 0; i < 5 + 3; i++) {
    p[i] = i;
    printf("p[%d]=%4.1f p[%d]=%4.1f\n", i, p[i], i, q[i]);
  }
  p = (float *)malloc(10);
  q = p;
  p = (float *)realloc(p, 1000);
  printf("p=0x%x\n", p);
  printf("q=0x%x\n", q);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x20,%esi
call   1050 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe85(%rip),%rdi
mov    $0x4,%esi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    11fe <main+0xce>
cvtsi2ssl -0x14(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe2f(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119e <main+0x6e>
mov    $0xa,%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3e8,%esi
call   1050 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    $0x20,%esi
mov    %rax,%rdi
call   1050 <realloc@plt>
mov    %rax,%r12
lea    0xedb(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xecf(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec3(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movl   $0x0,(%r12)
movss  (%rbx),%xmm0
cvtss2sd %xmm0,%xmm1
lea    0xea8(%rip),%r13
xorps  %xmm0,%xmm0
mov    %r13,%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    $0x2,%al
call   1030 <printf@plt>
movl   $0x3f800000,0x4(%r12)
80 3f
movss  0x4(%rbx),%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  0xe2a(%rip),%xmm0
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    $0x2,%al
call   1030 <printf@plt>
movl   $0x40000000,0x8(%r12)
movss  0x8(%rbx),%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  0xe01(%rip),%xmm0
mov    %r13,%rdi
mov    $0x2,%esi
mov    $0x2,%edx
mov    $0x2,%al
call   1030 <printf@plt>
movl   $0x40400000,0xc(%r12)
40 40
movss  0xc(%rbx),%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  0xdd8(%rip),%xmm0
mov    %r13,%rdi
mov    $0x3,%esi
mov    $0x3,%edx
mov    $0x2,%al
call   1030 <printf@plt>
movl   $0x40800000,0x10(%r12)
80 40
movss  0x10(%rbx),%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  0xdaf(%rip),%xmm0
mov    %r13,%rdi
mov    $0x4,%esi
mov    $0x4,%edx
mov    $0x2,%al
call   1030 <printf@plt>
movl   $0x40a00000,0x14(%r12)
a0 40
movss  0x14(%rbx),%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  0xd86(%rip),%xmm0
mov    %r13,%rdi
mov    $0x5,%esi
mov    $0x5,%edx
mov    $0x2,%al
call   1030 <printf@plt>
movl   $0x40c00000,0x18(%r12)
c0 40
movss  0x18(%rbx),%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  0xd5d(%rip),%xmm0
mov    %r13,%rdi
mov    $0x6,%esi
mov    $0x6,%edx
mov    $0x2,%al
call   1030 <printf@plt>
movl   $0x40e00000,0x1c(%r12)
e0 40
movss  0x1c(%rbx),%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  0xd34(%rip),%xmm0
mov    %r13,%rdi
mov    $0x7,%esi
mov    $0x7,%edx
mov    $0x2,%al
call   1030 <printf@plt>
mov    $0xa,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    $0x3e8,%esi
mov    %rax,%rdi
call   1050 <realloc@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"p=0x%x\0A\00"
@.str.1 = [8 x i8] c"q=0x%x\0A\00"
@.str.2 = [8 x i8] c"Len=%d\0A\00"
@.str.3 = [25 x i8] c"p[%d]=%4.1f p[%d]=%4.1f\0A\00"
define void @main() {
%1 = alloca float*
%2 = alloca float*
%3 = alloca i32
%4 = call i8* @malloc(i64 20)
%5 = bitcast i8* %4 to float*
store float* %5, float** %1
%6 = load float*, float** %1
store float* %6, float** %2
%7 = load float*, float** %1
%8 = bitcast float* %7 to i8*
%9 = call i8* @realloc(i8* %8, i64 32)
%10 = bitcast i8* %9 to float*
store float* %10, float** %1
%11 = load float*, float** %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), float* %11)
%13 = load float*, float** %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), float* %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64 4)
store i32 0, i32* %3
br label %16
16: ; preds = %41, %0
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 8
br i1 %18, label %19, label %44
19: ; preds = %16
%20 = load i32, i32* %3
%21 = sitofp i32 %20 to float
%22 = load float*, float** %1
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds float, float* %22, i64 %24
store float %21, float* %25
%26 = load i32, i32* %3
%27 = load float*, float** %1
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds float, float* %27, i64 %29
%31 = load float, float* %30
%32 = fpext float %31 to double
%33 = load i32, i32* %3
%34 = load float*, float** %2
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds float, float* %34, i64 %36
%38 = load float, float* %37
%39 = fpext float %38 to double
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %26, double %32, i32 %33, double %39)
br label %41
41: ; preds = %19
%42 = load i32, i32* %3
%43 = add nsw i32 %42, 1
store i32 %43, i32* %3
br label %16
44: ; preds = %16
%45 = call i8* @malloc(i64 10)
%46 = bitcast i8* %45 to float*
store float* %46, float** %1
%47 = load float*, float** %1
store float* %47, float** %2
%48 = load float*, float** %1
%49 = bitcast float* %48 to i8*
%50 = call i8* @realloc(i8* %49, i64 1000)
%51 = bitcast i8* %50 to float*
store float* %51, float** %1
%52 = load float*, float** %1
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), float* %52)
%54 = load float*, float** %2
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), float* %54)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"p=0x%x\0A\00"
@.str.1 = [8 x i8] c"q=0x%x\0A\00"
@.str.2 = [8 x i8] c"Len=%d\0A\00"
@.str.3 = [25 x i8] c"p[%d]=%4.1f p[%d]=%4.1f\0A\00"
define void @main() {
%1 = tail call dereferenceable_or_null(20) i8* @malloc(i64 20)
%2 = bitcast i8* %1 to float*
%3 = tail call dereferenceable_or_null(32) i8* @realloc(i8* %1, i64 32)
%4 = bitcast i8* %3 to float*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %3)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64 4)
store float 0.000000e+00, float* %4
%8 = load float, float* %2
%9 = fpext float %8 to double
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 0, double 0.000000e+00, i32 0, double %9)
%11 = getelementptr inbounds float, float* %4, i64 1
store float 1.000000e+00, float* %11
%12 = getelementptr inbounds float, float* %2, i64 1
%13 = load float, float* %12
%14 = fpext float %13 to double
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 1, double 1.000000e+00, i32 1, double %14)
%16 = getelementptr inbounds float, float* %4, i64 2
store float 2.000000e+00, float* %16
%17 = getelementptr inbounds float, float* %2, i64 2
%18 = load float, float* %17
%19 = fpext float %18 to double
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 2, double 2.000000e+00, i32 2, double %19)
%21 = getelementptr inbounds float, float* %4, i64 3
store float 3.000000e+00, float* %21
%22 = getelementptr inbounds float, float* %2, i64 3
%23 = load float, float* %22
%24 = fpext float %23 to double
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 3, double 3.000000e+00, i32 3, double %24)
%26 = getelementptr inbounds float, float* %4, i64 4
store float 4.000000e+00, float* %26
%27 = getelementptr inbounds float, float* %2, i64 4
%28 = load float, float* %27
%29 = fpext float %28 to double
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 4, double 4.000000e+00, i32 4, double %29)
%31 = getelementptr inbounds float, float* %4, i64 5
store float 5.000000e+00, float* %31
%32 = getelementptr inbounds float, float* %2, i64 5
%33 = load float, float* %32
%34 = fpext float %33 to double
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 5, double 5.000000e+00, i32 5, double %34)
%36 = getelementptr inbounds float, float* %4, i64 6
store float 6.000000e+00, float* %36
%37 = getelementptr inbounds float, float* %2, i64 6
%38 = load float, float* %37
%39 = fpext float %38 to double
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 6, double 6.000000e+00, i32 6, double %39)
%41 = getelementptr inbounds float, float* %4, i64 7
store float 7.000000e+00, float* %41
%42 = getelementptr inbounds float, float* %2, i64 7
%43 = load float, float* %42
%44 = fpext float %43 to double
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 7, double 7.000000e+00, i32 7, double %44)
%46 = tail call dereferenceable_or_null(10) i8* @malloc(i64 10)
%47 = tail call dereferenceable_or_null(1000) i8* @realloc(i8* %46, i64 1000)
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %47)
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %46)
ret void
}