#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 *dvector(int);
double *linearly_spaced_vector(double lower, double upper, int n) {
  double *v = dvector(n);
  double space = (upper - lower) / (n - 1);
  v[0] = 0;
  for (int i = 1; i < n; i++) {
    v[i] = v[i - 1] + space;
  }
  return v;
}


x86 assembly (clang, -O0):
<linearly_spaced_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <dvector@plt>
mov    %rax,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    119e <linearly_spaced_vector+0x8e>
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x28(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1160 <linearly_spaced_vector+0x50>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linearly_spaced_vector>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
call   1030 <dvector@plt>
movsd  0x8(%rsp),%xmm1
movq   $0x0,(%rax)
cmp    $0x2,%ebx
jl     11d2 <linearly_spaced_vector+0xc2>
subsd  (%rsp),%xmm1
lea    -0x1(%rbx),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
divsd  %xmm0,%xmm1
mov    %ebx,%edx
lea    -0x1(%rdx),%rsi
add    $0xfffffffffffffffe,%rdx
mov    %esi,%ecx
and    $0x3,%ecx
cmp    $0x3,%rdx
jae    1175 <linearly_spaced_vector+0x65>
mov    $0x1,%edx
xorpd  %xmm0,%xmm0
test   %rcx,%rcx
jne    11ba <linearly_spaced_vector+0xaa>
jmp    11d2 <linearly_spaced_vector+0xc2>
and    $0xfffffffffffffffc,%rsi
xorpd  %xmm0,%xmm0
xor    %edx,%edx
nop
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rax,%rdx,8)
addsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rax,%rdx,8)
addsd  %xmm1,%xmm0
movsd  %xmm0,0x18(%rax,%rdx,8)
addsd  %xmm1,%xmm0
movsd  %xmm0,0x20(%rax,%rdx,8)
add    $0x4,%rdx
cmp    %rdx,%rsi
jne    1180 <linearly_spaced_vector+0x70>
add    $0x1,%rdx
test   %rcx,%rcx
je     11d2 <linearly_spaced_vector+0xc2>
lea    (%rax,%rdx,8),%rdx
xor    %esi,%esi
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rdx,%rsi,8)
add    $0x1,%rsi
cmp    %rsi,%rcx
jne    11c0 <linearly_spaced_vector+0xb0>
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define double* @linearly_spaced_vector(double %0, double %1, i32 %2) {
%4 = tail call double* @dvector(i32 %2)
%5 = fsub double %1, %0
%6 = add nsw i32 %2, -1
%7 = sitofp i32 %6 to double
%8 = fdiv double %5, %7
store double 0.000000e+00, double* %4
%9 = icmp sgt i32 %2, 1
br i1 %9, label %10, label %31
10: ; preds = %3
%11 = zext i32 %2 to i64
%12 = add nsw i64 %11, -1
%13 = add nsw i64 %11, -2
%14 = and i64 %12, 3
%15 = icmp ult i64 %13, 3
br i1 %15, label %18, label %16
16: ; preds = %10
%17 = and i64 %12, -4
br label %32
18: ; preds = %32, %10
%19 = phi double [ 0.000000e+00, %10 ], [ %45, %32 ]
%20 = phi i64 [ 1, %10 ], [ %47, %32 ]
%21 = icmp eq i64 %14, 0
br i1 %21, label %31, label %22
22: ; preds = %18, %22
%23 = phi double [ %26, %22 ], [ %19, %18 ]
%24 = phi i64 [ %28, %22 ], [ %20, %18 ]
%25 = phi i64 [ %29, %22 ], [ 0, %18 ]
%26 = fadd double %8, %23
%27 = getelementptr inbounds double, double* %4, i64 %24
store double %26, double* %27
%28 = add nuw nsw i64 %24, 1
%29 = add i64 %25, 1
%30 = icmp eq i64 %29, %14
br i1 %30, label %31, label %22
31: ; preds = %18, %22, %3
ret double* %4
32: ; preds = %32, %16
%33 = phi double [ 0.000000e+00, %16 ], [ %45, %32 ]
%34 = phi i64 [ 1, %16 ], [ %47, %32 ]
%35 = phi i64 [ 0, %16 ], [ %48, %32 ]
%36 = fadd double %8, %33
%37 = getelementptr inbounds double, double* %4, i64 %34
store double %36, double* %37
%38 = add nuw nsw i64 %34, 1
%39 = fadd double %8, %36
%40 = getelementptr inbounds double, double* %4, i64 %38
store double %39, double* %40
%41 = add nuw nsw i64 %34, 2
%42 = fadd double %8, %39
%43 = getelementptr inbounds double, double* %4, i64 %41
store double %42, double* %43
%44 = add nuw nsw i64 %34, 3
%45 = fadd double %8, %42
%46 = getelementptr inbounds double, double* %4, i64 %44
store double %45, double* %46
%47 = add nuw nsw i64 %34, 4
%48 = add i64 %35, 4
%49 = icmp eq i64 %48, %17
br i1 %49, label %18, label %32
}