#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 */
double *malloc(double);
double *linspace(double lower, double upper, double n) {
  int i = 0;
  double *someArray = malloc(n * sizeof(double));
  while (i < n) {
    someArray[i] = (upper - lower) * i / (n - 1) + lower;
    i++;
  }
  return someArray;
}


x86 assembly (clang, -O0):
<linspace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movsd  0xeca(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
call   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11a0 <linspace+0x90>
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xe90(%rip),%xmm2
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
addsd  -0x8(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1144 <linspace+0x34>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linspace>:
sub    $0x18,%rsp
movsd  %xmm2,(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
movsd  0xed3(%rip),%xmm0
mulsd  %xmm2,%xmm0
call   1030 <malloc@plt>
movsd  0x8(%rsp),%xmm4
movsd  0x10(%rsp),%xmm3
movsd  (%rsp),%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jbe    1192 <linspace+0x82>
subsd  %xmm4,%xmm3
movsd  0xeab(%rip),%xmm1
addsd  %xmm2,%xmm1
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mulsd  %xmm3,%xmm0
divsd  %xmm1,%xmm0
addsd  %xmm4,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
add    $0x1,%rcx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
ucomisd %xmm0,%xmm2
ja     1170 <linspace+0x60>
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double* @linspace(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double*
store double %0, double* %4
store double %1, double* %5
store double %2, double* %6
store i32 0, i32* %7
%9 = load double, double* %6
%10 = fmul double %9, 8.000000e+00
%11 = call double* @malloc(double %10)
store double* %11, double** %8
br label %12
12: ; preds = %17, %3
%13 = load i32, i32* %7
%14 = sitofp i32 %13 to double
%15 = load double, double* %6
%16 = fcmp olt double %14, %15
br i1 %16, label %17, label %35
17: ; preds = %12
%18 = load double, double* %5
%19 = load double, double* %4
%20 = fsub double %18, %19
%21 = load i32, i32* %7
%22 = sitofp i32 %21 to double
%23 = fmul double %20, %22
%24 = load double, double* %6
%25 = fsub double %24, 1.000000e+00
%26 = fdiv double %23, %25
%27 = load double, double* %4
%28 = fadd double %26, %27
%29 = load double*, double** %8
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
store double %28, double* %32
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %12
35: ; preds = %12
%36 = load double*, double** %8
ret double* %36
}

LLVM IR (-O2):
define noalias double* @linspace(double %0, double %1, double %2) {
%4 = fmul double %2, 8.000000e+00
%5 = tail call double* @malloc(double %4)
%6 = fcmp ogt double %2, 0.000000e+00
br i1 %6, label %7, label %21
7: ; preds = %3
%8 = fsub double %1, %0
%9 = fadd double %2, -1.000000e+00
br label %10
10: ; preds = %7, %10
%11 = phi i64 [ 0, %7 ], [ %17, %10 ]
%12 = phi double [ 0.000000e+00, %7 ], [ %19, %10 ]
%13 = fmul double %8, %12
%14 = fdiv double %13, %9
%15 = fadd double %14, %0
%16 = getelementptr inbounds double, double* %5, i64 %11
store double %15, double* %16
%17 = add nuw i64 %11, 1
%18 = trunc i64 %17 to i32
%19 = sitofp i32 %18 to double
%20 = fcmp olt double %19, %2
br i1 %20, label %10, label %21
21: ; preds = %10, %3
ret double* %5
}