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

/* Variables and functions */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void main() {
  int N;
  int *a;
  int i;
  printf("Input array length:");
  scanf("%d\n", &N);
  a = (int *)calloc(N, sizeof(int));
  for (i = 0; i < N; i++) {
    a[i] = i + 1;
    printf("%-5d", a[i]);
    if ((i + 1) % 10 == 0)
      printf("\n");
  }
  free(a);
  a = NULL;
  printf("\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb7(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x4(%rbp),%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ec <main+0xac>
mov    -0x14(%rbp),%edx
add    $0x1,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11d9 <main+0x99>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11de <main+0x9e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117e <main+0x3e>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea4(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
cmpl   $0x0,0x4(%rsp)
jle    1200 <main+0xb0>
mov    $0x1,%ebp
lea    0xe7a(%rip),%r14
xor    %r13d,%r13d
jmp    11bd <main+0x6d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq 0x4(%rsp),%rax
add    $0x1,%ebp
cmp    %rax,%r13
jge    1200 <main+0xb0>
mov    %r13,%rbx
add    $0x1,%r13
mov    %ebp,%eax
mov    $0xcccccccd,%ecx
imul   %rcx,%rax
shr    $0x23,%rax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,1),%r12d
add    $0xffffffff,%r12d
mov    %r13d,(%r15,%rbx,4)
mov    %r14,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %ebx,%r12d
jne    11b0 <main+0x60>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    11b0 <main+0x60>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Input array length:\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [5 x i8] c"%-5d\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = call i64 @calloc(i32 %6, i32 4)
%8 = inttoptr i64 %7 to i32*
store i32* %8, i32** %2
store i32 0, i32* %3
br label %9
9: ; preds = %33, %0
%10 = load i32, i32* %3
%11 = load i32, i32* %1
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %36
13: ; preds = %9
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
%16 = load i32*, i32** %2
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
store i32 %15, i32* %19
%20 = load i32*, i32** %2
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
%28 = srem i32 %27, 10
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %13
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %13
br label %33
33: ; preds = %32
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %9
36: ; preds = %9
%37 = load i32*, i32** %2
%38 = call i32 @free(i32* %37)
store i32* null, i32** %2
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"Input array length:\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [5 x i8] c"%-5d\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = call i64 @calloc(i32 %5, i32 4)
%7 = inttoptr i64 %6 to i32*
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %24
10: ; preds = %0, %20
%11 = phi i64 [ %12, %20 ], [ 0, %0 ]
%12 = add nuw nsw i64 %11, 1
%13 = getelementptr inbounds i32, i32* %7, i64 %11
%14 = trunc i64 %12 to i32
store i32 %14, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = urem i32 %14, 10
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = call i32 @putchar(i32 10)
br label %20
20: ; preds = %10, %18
%21 = load i32, i32* %1
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %12, %22
br i1 %23, label %10, label %24
24: ; preds = %20, %0
%25 = call i32 @free(i32* %7)
%26 = call i32 @putchar(i32 10)
ret void
}