#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 = 0;
  int number;
  int i = 0;
  puts("What is the maximum number of type double entries?");
  if (scanf("%d", &max) != 1) {
    puts("Number not correctly entered -- bye.");
    exit(EXIT_FAILURE);
  }
  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,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe6c(%rip),%rdi
call   1050 <puts@plt>
lea    0xe93(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
cmp    $0x1,%eax
je     11ce <main+0x5e>
lea    0xe7b(%rip),%rdi
call   1050 <puts@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1206 <main+0x96>
lea    0xe68(%rip),%rdi
call   1050 <puts@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe71(%rip),%rdi
call   1050 <puts@plt>
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x1d(%rbp)
jge    1249 <main+0xd9>
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    0xe63(%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    1259 <main+0xe9>
jmp    1267 <main+0xf7>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1212 <main+0xa2>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
cvtsi2sd %eax,%xmm0
lea    0xe28(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12da <main+0x16a>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe17(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
cmp    $0x6,%edx
jne    12c7 <main+0x157>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    12cc <main+0x15c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1284 <main+0x114>
mov    -0x1c(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12f8 <main+0x188>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xdc2(%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
movl   $0x0,0xc(%rsp)
lea    0xe75(%rip),%rdi
call   1050 <puts@plt>
lea    0xe9c(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
cmp    $0x1,%eax
jne    12d8 <main+0x168>
mov    0xc(%rsp),%edi
shl    $0x3,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     12e1 <main+0x171>
mov    %rax,%r15
lea    0xeb3(%rip),%rdi
call   1050 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    12a5 <main+0x135>
lea    0xeba(%rip),%r14
mov    %r15,%rbx
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
cmp    $0x1,%eax
jne    1214 <main+0xa4>
add    $0x1,%r12
movslq 0xc(%rsp),%rax
add    $0x8,%rbx
cmp    %rax,%r12
jl     11f0 <main+0x80>
cvtsi2sd %r12d,%xmm0
lea    0xe80(%rip),%rdi
call   1060 <printf@plt>
test   %r12d,%r12d
je     12b5 <main+0x145>
xor    %ebx,%ebx
lea    0xe84(%rip),%r14
jmp    1249 <main+0xd9>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r12
je     128b <main+0x11b>
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    1240 <main+0xd0>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    1240 <main+0xd0>
imul   $0xb6db6db7,%r12d,%eax
cmp    $0x24924925,%eax
jb     12b5 <main+0x145>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    12b5 <main+0x145>
lea    0xdf4(%rip),%rdi
xorpd  %xmm0,%xmm0
call   1060 <printf@plt>
lea    0xe05(%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    0xd57(%rip),%rdi
jmp    12e8 <main+0x178>
lea    0xd73(%rip),%rdi
call   1050 <puts@plt>
mov    0x2cec(%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 = [37 x i8] c"Number not correctly entered -- bye.\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [35 x i8] c"Memory allocation failed. Goodbye.\00"
@.str.4 = [30 x i8] c"Enter the values (q to quit):\00"
@.str.5 = [4 x i8] c"%lf\00"
@.str.6 = [27 x i8] c"Here are your %d entries:\0A\00"
@.str.7 = [6 x i8] c"%7.2f\00"
@.str.8 = [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* %3
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 = icmp ne i32 %7, 1
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = call i32 @puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 8
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to double*
store double* %19, double** %2
%20 = load double*, double** %2
%21 = icmp eq double* %20, null
br i1 %21, label %22, label %26
22: ; preds = %13
%23 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %13
%27 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %28
28: ; preds = %41, %26
%29 = load i32, i32* %5
%30 = load i32, i32* %3
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %39
32: ; preds = %28
%33 = load double*, double** %2
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
%37 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), double* %36)
%38 = icmp eq i32 %37, 1
br label %39
39: ; preds = %32, %28
%40 = phi i1 [ false, %28 ], [ %38, %32 ]
br i1 %40, label %41, label %44
41: ; preds = %39
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %28
44: ; preds = %39
%45 = load i32, i32* %5
store i32 %45, i32* %4
%46 = sitofp i32 %45 to double
%47 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), double %46)
store i32 0, i32* %5
br label %48
48: ; preds = %65, %44
%49 = load i32, i32* %5
%50 = load i32, i32* %4
%51 = icmp slt i32 %49, %50
br i1 %51, label %52, label %68
52: ; preds = %48
%53 = load double*, double** %2
%54 = load i32, i32* %5
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
%57 = load double, double* %56
%58 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), double %57)
%59 = load i32, i32* %5
%60 = srem i32 %59, 7
%61 = icmp eq i32 %60, 6
br i1 %61, label %62, label %64
62: ; preds = %52
%63 = call i32 @putchar(i8 signext 10)
br label %64
64: ; preds = %62, %52
br label %65
65: ; preds = %64
%66 = load i32, i32* %5
%67 = add nsw i32 %66, 1
store i32 %67, i32* %5
br label %48
68: ; preds = %48
%69 = load i32, i32* %5
%70 = srem i32 %69, 7
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %68
%73 = call i32 @putchar(i8 signext 10)
br label %74
74: ; preds = %72, %68
%75 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%76 = load double*, double** %2
%77 = call i32 @free(double* %76)
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 = [37 x i8] c"Number not correctly entered -- bye.\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [35 x i8] c"Memory allocation failed. Goodbye.\00"
@.str.4 = [30 x i8] c"Enter the values (q to quit):\00"
@.str.5 = [4 x i8] c"%lf\00"
@.str.6 = [27 x i8] c"Here are your %d entries:\0A\00"
@.str.7 = [6 x i8] c"%7.2f\00"
@.str.8 = [6 x i8] c"Done.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%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 = icmp eq i32 %4, 1
br i1 %5, label %10, label %6
6: ; preds = %0
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = load i32, i32* %1
%12 = shl i32 %11, 3
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to double*
%15 = icmp eq i64 %13, 0
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %10
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%22 = load i32, i32* %1
%23 = icmp sgt i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), double 0.000000e+00)
br label %62
26: ; preds = %20, %31
%27 = phi i64 [ %32, %31 ], [ 0, %20 ]
%28 = getelementptr inbounds double, double* %14, i64 %27
%29 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), double* %28)
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = add nuw nsw i64 %27, 1
%33 = load i32, i32* %1
%34 = sext i32 %33 to i64
%35 = icmp slt i64 %32, %34
br i1 %35, label %26, label %36
36: ; preds = %26, %31
%37 = phi i64 [ %27, %26 ], [ %32, %31 ]
%38 = trunc i64 %37 to i32
%39 = sitofp i32 %38 to double
%40 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), double %39)
%41 = icmp eq i32 %38, 0
br i1 %41, label %62, label %42
42: ; preds = %36
%43 = and i64 %37, 4294967295
br label %44
44: ; preds = %42, %54
%45 = phi i64 [ 0, %42 ], [ %55, %54 ]
%46 = getelementptr inbounds double, double* %14, i64 %45
%47 = load double, double* %46
%48 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), double %47)
%49 = trunc i64 %45 to i32
%50 = urem i32 %49, 7
%51 = icmp eq i32 %50, 6
br i1 %51, label %52, label %54
52: ; preds = %44
%53 = call i32 @putchar(i8 signext 10)
br label %54
54: ; preds = %44, %52
%55 = add nuw nsw i64 %45, 1
%56 = icmp eq i64 %55, %43
br i1 %56, label %57, label %44
57: ; preds = %54
%58 = urem i32 %38, 7
%59 = icmp eq i32 %58, 0
br i1 %59, label %62, label %60
60: ; preds = %57
%61 = call i32 @putchar(i8 signext 10)
br label %62
62: ; preds = %24, %36, %60, %57
%63 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%64 = call i32 @free(double* %14)
ret i32 0
}