int main() {
  int *n, *p;
  int i, n1, n2;
  printf("请输入所要创建的动态数组的长度：");
  scanf("%d", &n1);
  n = (int *)calloc(n1, sizeof(int));
  for (i = 0; i < n1; i++) {
    n[i] = i + 1;
    if (i % 5 == 0)
      printf("\n");
    printf("%d\t", n[i]);
  }
  printf("\n请输入所要缩小的动态数组的长度：");
  scanf("%d", &n2);
  p = (int *)realloc(n, (n2) * sizeof(int));
  for (i = 0; i < n2; i++) {
    if (i % 5 == 0)
      printf("\n");
    printf("%d\t", p[i]);
  }
  printf("\n");
  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)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11fe <main+0xae>
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%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    11d7 <main+0x87>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1198 <main+0x48>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe1e(%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    128f <main+0x13f>
mov    -0x1c(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1268 <main+0x118>
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    123a <main+0xea>
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
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   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb0(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
movslq 0xc(%rsp),%rbx
mov    $0x4,%esi
mov    %rbx,%rdi
call   1060 <calloc@plt>
mov    %rax,%r15
test   %rbx,%rbx
jle    11fe <main+0x9e>
mov    $0xcccccccd,%ebp
lea    0xe81(%rip),%r14
xor    %eax,%eax
jmp    11d9 <main+0x79>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movslq 0xc(%rsp),%rcx
mov    %rbx,%rax
cmp    %rcx,%rbx
jge    11fe <main+0x9e>
lea    0x1(%rax),%rbx
mov    %eax,%ecx
imul   %rbp,%rcx
shr    $0x22,%rcx
lea    (%rcx,%rcx,4),%ecx
mov    %ebx,(%r15,%rax,4)
cmp    %ecx,%eax
jne    11c0 <main+0x60>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    11c0 <main+0x60>
lea    0xe33(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe1e(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
movslq 0x8(%rsp),%rbx
lea    0x0(,%rbx,4),%rsi
mov    %r15,%rdi
call   1070 <realloc@plt>
mov    %rax,%r12
test   %rbx,%rbx
jle    128c <main+0x12c>
mov    $0xcccccccd,%r15d
lea    0xdeb(%rip),%r14
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    126f <main+0x10f>
nop
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
add    $0xffffffff,%ebp
cmp    %rax,%rbx
jge    128c <main+0x12c>
mov    %ebx,%eax
imul   %r15,%rax
shr    $0x22,%rax
lea    (%rax,%rax,4),%eax
add    %ebp,%eax
jne    1250 <main+0xf0>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    1250 <main+0xf0>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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 = [2 x i8] c"\0A\00"
@.str.3 = [4 x i8] c"%d\09\00"
@.str.4 = [50 x i8] c"\0A\E8\AF\B7\E8\BE\93\E5\85\A5\E6\89\80\E8\A6\81\E7\BC\A9\E5\B0\8F\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"
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
store i32 0, i32* %4
br label %13
13: ; preds = %36, %0
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %39
17: ; preds = %13
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
%20 = load i32*, i32** %2
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
store i32 %19, i32* %23
%24 = load i32, i32* %4
%25 = srem i32 %24, 5
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %17
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %17
%30 = load i32*, i32** %2
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %29
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %13
39: ; preds = %13
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%42 = load i32*, i32** %2
%43 = bitcast i32* %42 to i8*
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = mul i64 %45, 4
%47 = call i8* @realloc(i8* %43, i64 %46)
%48 = bitcast i8* %47 to i32*
store i32* %48, i32** %3
store i32 0, i32* %4
br label %49
49: ; preds = %66, %39
%50 = load i32, i32* %4
%51 = load i32, i32* %6
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %69
53: ; preds = %49
%54 = load i32, i32* %4
%55 = srem i32 %54, 5
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %59
59: ; preds = %57, %53
%60 = load i32*, i32** %3
%61 = load i32, i32* %4
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %60, i64 %62
%64 = load i32, i32* %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %64)
br label %66
66: ; preds = %59
%67 = load i32, i32* %4
%68 = add nsw i32 %67, 1
store i32 %68, i32* %4
br label %49
69: ; preds = %49
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%71 = load i32*, i32** %3
%72 = bitcast i32* %71 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.3 = [4 x i8] c"%d\09\00"
@.str.4 = [50 x i8] c"\0A\E8\AF\B7\E8\BE\93\E5\85\A5\E6\89\80\E8\A6\81\E7\BC\A9\E5\B0\8F\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"
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 = load i32, i32* %1
%8 = sext i32 %7 to i64
%9 = call i8* @calloc(i64 %8, i64 4)
%10 = bitcast i8* %9 to i32*
%11 = icmp sgt i32 %7, 0
br i1 %11, label %12, label %27
12: ; preds = %0, %22
%13 = phi i64 [ %14, %22 ], [ 0, %0 ]
%14 = add nuw nsw i64 %13, 1
%15 = getelementptr inbounds i32, i32* %10, i64 %13
%16 = trunc i64 %14 to i32
store i32 %16, i32* %15
%17 = trunc i64 %13 to i32
%18 = urem i32 %17, 5
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 @putchar(i32 10)
br label %22
22: ; preds = %20, %12
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%24 = load i32, i32* %1
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %14, %25
br i1 %26, label %12, label %27
27: ; preds = %22, %0
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%30 = load i32, i32* %2
%31 = sext i32 %30 to i64
%32 = shl nsw i64 %31, 2
%33 = call i8* @realloc(i8* %9, i64 %32)
%34 = bitcast i8* %33 to i32*
%35 = icmp sgt i32 %30, 0
br i1 %35, label %36, label %51
36: ; preds = %27, %43
%37 = phi i64 [ %47, %43 ], [ 0, %27 ]
%38 = trunc i64 %37 to i32
%39 = urem i32 %38, 5
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = call i32 @putchar(i32 10)
br label %43
43: ; preds = %41, %36
%44 = getelementptr inbounds i32, i32* %34, i64 %37
%45 = load i32, i32* %44
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %45)
%47 = add nuw nsw i64 %37, 1
%48 = load i32, i32* %2
%49 = sext i32 %48 to i64
%50 = icmp slt i64 %47, %49
br i1 %50, label %36, label %51
51: ; preds = %43, %27
%52 = call i32 @putchar(i32 10)
ret i32 0
}