int main() {
  int *n, *p;
  int i, n1, n2;
  printf("请输入所要创建的动态数组的长度：");
  scanf("%d", &n1);
  n = (int *)calloc(n1, sizeof(int));
  printf("请输入所要扩展的动态数组的长度：");
  scanf("%d", &n2);
  p = (int *)realloc(n, (n2) * sizeof(int));
  for (i = 0; i < n2; i++) {
    p[i] = i + 1;
    if (i % 5 == 0)
      printf("\n");
    printf("%d\t", p[i]);
  }
  free(p);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebd(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
movslq -0x20(%rbp),%rdi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8b(%rip),%rdi
lea    -0x24(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x10(%rbp),%rdi
movslq -0x24(%rbp),%rsi
shl    $0x2,%rsi
call   1060 <realloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1233 <main+0xe3>
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    120c <main+0xbc>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11cd <main+0x7d>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xee4(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xed1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11d4 <main+0xa4>
mov    $0xcccccccd,%r14d
lea    0xed8(%rip),%rbx
xor    %eax,%eax
jmp    11b4 <main+0x84>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
cmp    0x8(%rsp),%ebp
jge    11d4 <main+0xa4>
lea    0x1(%rax),%ebp
mov    %eax,%ecx
imul   %r14,%rcx
shr    $0x22,%rcx
lea    (%rcx,%rcx,4),%ecx
cmp    %eax,%ecx
jne    11a0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11a0 <main+0x70>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"\E8\AF\B7\E8\BE\93\E5\85\A5\E6\89\80\E8\A6\81\E5\88\9B\E5\BB\BA\E7\9A\84\E5\8A\A8\E6\80\81\E6\95\B0\E7\BB\84\E7\9A\84\E9\95\BF\E5\BA\A6\EF\BC\9A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [49 x i8] c"\E8\AF\B7\E8\BE\93\E5\85\A5\E6\89\80\E8\A6\81\E6\89\A9\E5\B1\95\E7\9A\84\E5\8A\A8\E6\80\81\E6\95\B0\E7\BB\84\E7\9A\84\E9\95\BF\E5\BA\A6\EF\BC\9A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [4 x i8] c"%d\09\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = call i8* @calloc(i64 %10, i64 4)
%12 = bitcast i8* %11 to i32*
store i32* %12, i32** %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%15 = load i32*, i32** %2
%16 = bitcast i32* %15 to i8*
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 4
%20 = call i8* @realloc(i8* %16, i64 %19)
%21 = bitcast i8* %20 to i32*
store i32* %21, i32** %3
store i32 0, i32* %4
br label %22
22: ; preds = %45, %0
%23 = load i32, i32* %4
%24 = load i32, i32* %6
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %48
26: ; preds = %22
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
%29 = load i32*, i32** %3
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
store i32 %28, i32* %32
%33 = load i32, i32* %4
%34 = srem i32 %33, 5
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %26
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36, %26
%39 = load i32*, i32** %3
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %38
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %22
48: ; preds = %22
%49 = load i32*, i32** %3
%50 = bitcast i32* %49 to i8*
ret i32 0
}

LLVM IR (-O2):
@.str = [49 x i8] c"\E8\AF\B7\E8\BE\93\E5\85\A5\E6\89\80\E8\A6\81\E5\88\9B\E5\BB\BA\E7\9A\84\E5\8A\A8\E6\80\81\E6\95\B0\E7\BB\84\E7\9A\84\E9\95\BF\E5\BA\A6\EF\BC\9A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [49 x i8] c"\E8\AF\B7\E8\BE\93\E5\85\A5\E6\89\80\E8\A6\81\E6\89\A9\E5\B1\95\E7\9A\84\E5\8A\A8\E6\80\81\E6\95\B0\E7\BB\84\E7\9A\84\E9\95\BF\E5\BA\A6\EF\BC\9A\00"
@.str.4 = [4 x i8] c"%d\09\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %0, %18
%12 = phi i32 [ %13, %18 ], [ 0, %0 ]
%13 = add nuw nsw i32 %12, 1
%14 = urem i32 %12, 5
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @putchar(i32 10)
br label %18
18: ; preds = %16, %11
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %13)
%20 = load i32, i32* %2
%21 = icmp slt i32 %13, %20
br i1 %21, label %11, label %22
22: ; preds = %18, %0
ret i32 0
}