#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*/ flushall();
int /*<<< orphan*/ free(float *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
main() {
  float *float_array;
  int no_els, i;
  printf("How many numbers do you wish to allocate memory?\n");
  scanf("%d", &no_els);
  float_array = (float *)calloc(no_els, sizeof(float));
  if (float_array == NULL) {
    printf("Cannot allocate");
  } else {
    for (i = 0; i < no_els; i++) {
      printf("Element %d is %.1f\n", i, *(float_array + i));
    }
    free(float_array);
    flushall();
    getchar();
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeae(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x14(%rbp),%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bc <main+0x5c>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1216 <main+0xb6>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ff <main+0x9f>
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe5b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c3 <main+0x63>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1050 <flushall@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xea7(%rip),%rdi
call   1040 <puts@plt>
lea    0xe74(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1090 <scanf@plt>
mov    0xc(%rsp),%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
test   %rax,%rax
je     11fc <main+0x8c>
mov    %rax,%r14
cmpl   $0x0,0xc(%rsp)
jle    11e4 <main+0x74>
xor    %ebx,%ebx
lea    0xe57(%rip),%r15
nopl   0x0(%rax)
movss  (%r14,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r15,%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     11c0 <main+0x50>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1060 <flushall@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
jmp    120a <main+0x9a>
lea    0xe00(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [50 x i8] c"How many numbers do you wish to allocate memory?\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"Cannot allocate\00"
@.str.3 = [20 x i8] c"Element %d is %.1f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = load i32, i32* %3
%8 = call i64 @calloc(i32 %7, i32 4)
%9 = inttoptr i64 %8 to float*
store float* %9, float** %2
%10 = load float*, float** %2
%11 = icmp eq float* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %36
14: ; preds = %0
store i32 0, i32* %4
br label %15
15: ; preds = %28, %14
%16 = load i32, i32* %4
%17 = load i32, i32* %3
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %31
19: ; preds = %15
%20 = load i32, i32* %4
%21 = load float*, float** %2
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds float, float* %21, i64 %23
%25 = load float, float* %24
%26 = fpext float %25 to double
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %20, double %26)
br label %28
28: ; preds = %19
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %15
31: ; preds = %15
%32 = load float*, float** %2
%33 = call i32 @free(float* %32)
%34 = call i32 (...) @flushall()
%35 = call i32 (...) @getchar()
br label %36
36: ; preds = %31, %12
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"Cannot allocate\00"
@.str.3 = [20 x i8] c"Element %d is %.1f\0A\00"
@str = [49 x i8] c"How many numbers do you wish to allocate memory?\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 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 float*
%8 = icmp eq i64 %6, 0
br i1 %8, label %12, label %9
9: ; preds = %0
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %14, label %25
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %29
14: ; preds = %9, %14
%15 = phi i64 [ %21, %14 ], [ 0, %9 ]
%16 = getelementptr inbounds float, float* %7, i64 %15
%17 = load float, float* %16
%18 = fpext float %17 to double
%19 = trunc i64 %15 to i32
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %19, double %18)
%21 = add nuw nsw i64 %15, 1
%22 = load i32, i32* %1
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %21, %23
br i1 %24, label %14, label %25
25: ; preds = %14, %9
%26 = call i32 @free(float* %7)
%27 = call i32 (...) @flushall()
%28 = call i32 (...) @getchar()
br label %29
29: ; preds = %25, %12
ret i32 0
}