#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int scanf(char *, ...);
int main(void) {
  double *ptd;
  int max;
  int number;
  int i = 0;
  puts("What is the maximum number of type double entries?");
  scanf("%d", &max);
  ptd = (double *)malloc(max * sizeof(double));
  if (ptd == NULL) {
    puts("Memory allocation failed. Goodbye.");
    exit(EXIT_FAILURE);
  }
  puts("Enter the values (q to quit): ");
  while (i < max && scanf("%lf", &ptd[i]) == 1)
    ++i;
  printf("Here are your %d entries: \n", number = i);
  for (i = 0; i < number; i++) {
    printf("%7.2f ", ptd[i]);
    if (i % 7 == 6)
      putchar('\n');
  }
  if (i % 7 != 0)
    putchar('\n');
  puts("Done.");
  free(ptd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe73(%rip),%rdi
call   1050 <puts@plt>
lea    0xe9a(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11dc <main+0x6c>
lea    0xe6d(%rip),%rdi
call   1050 <puts@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe76(%rip),%rdi
call   1050 <puts@plt>
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x1d(%rbp)
jge    121f <main+0xaf>
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1080 <scanf@plt>
cmp    $0x1,%eax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    122f <main+0xbf>
jmp    123d <main+0xcd>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e8 <main+0x78>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
cvtsi2sd %eax,%xmm0
lea    0xe2e(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12b0 <main+0x140>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe1e(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
cmp    $0x6,%edx
jne    129d <main+0x12d>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    12a2 <main+0x132>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    125a <main+0xea>
mov    -0x1c(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12ce <main+0x15e>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xdca(%rip),%rdi
call   1050 <puts@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe7d(%rip),%rdi
call   1050 <puts@plt>
lea    0xea4(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0xc(%rsp),%edi
shl    $0x3,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     12c8 <main+0x158>
mov    %rax,%r15
lea    0xe9f(%rip),%rdi
call   1050 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    1295 <main+0x125>
lea    0xea7(%rip),%r14
mov    %r15,%rbx
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
cmp    $0x1,%eax
jne    1204 <main+0x94>
add    $0x1,%r12
movslq 0xc(%rsp),%rax
add    $0x8,%rbx
cmp    %rax,%r12
jl     11e0 <main+0x70>
cvtsi2sd %r12d,%xmm0
lea    0xe6c(%rip),%rdi
call   1060 <printf@plt>
test   %r12d,%r12d
je     12a5 <main+0x135>
xor    %ebx,%ebx
lea    0xe71(%rip),%r14
jmp    1239 <main+0xc9>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r12
je     127b <main+0x10b>
mov    %ebx,%eax
imul   $0x24924925,%rax,%rax
shr    $0x20,%rax
mov    %ebx,%ecx
sub    %eax,%ecx
shr    %ecx
add    %eax,%ecx
shr    $0x2,%ecx
lea    0x0(,%rcx,8),%ebp
sub    %ecx,%ebp
add    $0x6,%ebp
movsd  (%r15,%rbx,8),%xmm0
mov    %r14,%rdi
call   1060 <printf@plt>
cmp    %ebx,%ebp
jne    1230 <main+0xc0>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    1230 <main+0xc0>
imul   $0xb6db6db7,%r12d,%eax
cmp    $0x24924925,%eax
jb     12a5 <main+0x135>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    12a5 <main+0x135>
lea    0xde0(%rip),%rdi
xorpd  %xmm0,%xmm0
call   1060 <printf@plt>
lea    0xdf3(%rip),%rdi
call   1050 <puts@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd67(%rip),%rdi
call   1050 <puts@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [51 x i8] c"What is the maximum number of type double entries?\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [35 x i8] c"Memory allocation failed. Goodbye.\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [31 x i8] c"Enter the values (q to quit): \00"
@.str.4 = [4 x i8] c"%lf\00"
@.str.5 = [28 x i8] c"Here are your %d entries: \0A\00"
@.str.6 = [7 x i8] c"%7.2f \00"
@.str.7 = [6 x i8] c"Done.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
%6 = call i32 @puts(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 8
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to double*
store double* %13, double** %2
%14 = load double*, double** %2
%15 = icmp eq double* %14, null
br i1 %15, label %16, label %20
16: ; preds = %0
%17 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %0
%21 = call i32 @puts(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %35, %20
%23 = load i32, i32* %5
%24 = load i32, i32* %3
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %33
26: ; preds = %22
%27 = load double*, double** %2
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %30)
%32 = icmp eq i32 %31, 1
br label %33
33: ; preds = %26, %22
%34 = phi i1 [ false, %22 ], [ %32, %26 ]
br i1 %34, label %35, label %38
35: ; preds = %33
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %22
38: ; preds = %33
%39 = load i32, i32* %5
store i32 %39, i32* %4
%40 = sitofp i32 %39 to double
%41 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), double %40)
store i32 0, i32* %5
br label %42
42: ; preds = %59, %38
%43 = load i32, i32* %5
%44 = load i32, i32* %4
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %62
46: ; preds = %42
%47 = load double*, double** %2
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
%51 = load double, double* %50
%52 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), double %51)
%53 = load i32, i32* %5
%54 = srem i32 %53, 7
%55 = icmp eq i32 %54, 6
br i1 %55, label %56, label %58
56: ; preds = %46
%57 = call i32 @putchar(i8 signext 10)
br label %58
58: ; preds = %56, %46
br label %59
59: ; preds = %58
%60 = load i32, i32* %5
%61 = add nsw i32 %60, 1
store i32 %61, i32* %5
br label %42
62: ; preds = %42
%63 = load i32, i32* %5
%64 = srem i32 %63, 7
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %62
%67 = call i32 @putchar(i8 signext 10)
br label %68
68: ; preds = %66, %62
%69 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%70 = load double*, double** %2
%71 = call i32 @free(double* %70)
ret i32 0
}

LLVM IR (-O2):
@.str = [51 x i8] c"What is the maximum number of type double entries?\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [35 x i8] c"Memory allocation failed. Goodbye.\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [31 x i8] c"Enter the values (q to quit): \00"
@.str.4 = [4 x i8] c"%lf\00"
@.str.5 = [28 x i8] c"Here are your %d entries: \0A\00"
@.str.6 = [7 x i8] c"%7.2f \00"
@.str.7 = [6 x i8] c"Done.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = shl i32 %5, 3
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to double*
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%16 = load i32, i32* %1
%17 = icmp sgt i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), double 0.000000e+00)
br label %56
20: ; preds = %14, %25
%21 = phi i64 [ %26, %25 ], [ 0, %14 ]
%22 = getelementptr inbounds double, double* %8, i64 %21
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), double* %22)
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = add nuw nsw i64 %21, 1
%27 = load i32, i32* %1
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %26, %28
br i1 %29, label %20, label %30
30: ; preds = %20, %25
%31 = phi i64 [ %21, %20 ], [ %26, %25 ]
%32 = trunc i64 %31 to i32
%33 = sitofp i32 %32 to double
%34 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), double %33)
%35 = icmp eq i32 %32, 0
br i1 %35, label %56, label %36
36: ; preds = %30
%37 = and i64 %31, 4294967295
br label %38
38: ; preds = %36, %48
%39 = phi i64 [ 0, %36 ], [ %49, %48 ]
%40 = getelementptr inbounds double, double* %8, i64 %39
%41 = load double, double* %40
%42 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), double %41)
%43 = trunc i64 %39 to i32
%44 = urem i32 %43, 7
%45 = icmp eq i32 %44, 6
br i1 %45, label %46, label %48
46: ; preds = %38
%47 = call i32 @putchar(i8 signext 10)
br label %48
48: ; preds = %38, %46
%49 = add nuw nsw i64 %39, 1
%50 = icmp eq i64 %49, %37
br i1 %50, label %51, label %38
51: ; preds = %48
%52 = urem i32 %32, 7
%53 = icmp eq i32 %52, 0
br i1 %53, label %56, label %54
54: ; preds = %51
%55 = call i32 @putchar(i8 signext 10)
br label %56
56: ; preds = %18, %30, %54, %51
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%58 = call i32 @free(double* %8)
ret i32 0
}