#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 get_length(double *, int);
void resize(double *vector, int n, double length) {
  double rate = get_length(vector, n) / length;
  for (int i = 0; i < n; i++) {
    vector[i] /= rate;
  }
}


x86 assembly (clang, -O0):
<resize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <get_length@plt>
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1176 <resize+0x66>
movsd  -0x20(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1141 <resize+0x31>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resize>:
push   %rbp
push   %rbx
push   %rax
movsd  %xmm0,(%rsp)
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <get_length@plt>
test   %ebp,%ebp
jle    11c7 <resize+0xb7>
divsd  (%rsp),%xmm0
mov    %ebp,%eax
cmp    $0x1,%ebp
jne    113a <resize+0x2a>
xor    %ecx,%ecx
jmp    11b0 <resize+0xa0>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x2(%rcx),%rsi
mov    %rsi,%rdx
shr    %rdx
add    $0x1,%rdx
test   %rsi,%rsi
je     11ce <resize+0xbe>
mov    %rdx,%rdi
and    $0xfffffffffffffffe,%rdi
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movupd (%rbx,%rsi,8),%xmm2
movupd 0x10(%rbx,%rsi,8),%xmm3
divpd  %xmm1,%xmm2
movupd %xmm2,(%rbx,%rsi,8)
divpd  %xmm1,%xmm3
movupd %xmm3,0x10(%rbx,%rsi,8)
add    $0x4,%rsi
add    $0xfffffffffffffffe,%rdi
jne    1170 <resize+0x60>
test   $0x1,%dl
je     11ab <resize+0x9b>
movupd (%rbx,%rsi,8),%xmm2
divpd  %xmm1,%xmm2
movupd %xmm2,(%rbx,%rsi,8)
cmp    %rax,%rcx
je     11c7 <resize+0xb7>
movsd  (%rbx,%rcx,8),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    11b0 <resize+0xa0>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %esi,%esi
test   $0x1,%dl
jne    119d <resize+0x8d>
jmp    11ab <resize+0x9b>

LLVM IR (-O0):
define void @resize(double* %0, i32 %1, double %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
store double %2, double* %6
%9 = load double*, double** %4
%10 = load i32, i32* %5
%11 = call double @get_length(double* %9, i32 %10)
%12 = load double, double* %6
%13 = fdiv double %11, %12
store double %13, double* %7
store i32 0, i32* %8
br label %14
14: ; preds = %26, %3
%15 = load i32, i32* %8
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %29
18: ; preds = %14
%19 = load double, double* %7
%20 = load double*, double** %4
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
%25 = fdiv double %24, %19
store double %25, double* %23
br label %26
26: ; preds = %18
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
br label %14
29: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @resize(double* %0, i32 %1, double %2) {
%4 = tail call double @get_length(double* %0, i32 %1)
%5 = fdiv double %4, %2
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %51
7: ; preds = %3
%8 = zext i32 %1 to i64
%9 = icmp eq i32 %1, 1
br i1 %9, label %49, label %10
10: ; preds = %7
%11 = and i64 %8, 4294967294
%12 = insertelement <2 x double> poison, double %5, i64 0
%13 = shufflevector <2 x double> %12, <2 x double> poison, <2 x i32> zeroinitializer
%14 = add nsw i64 %11, -2
%15 = lshr exact i64 %14, 1
%16 = add nuw i64 %15, 1
%17 = and i64 %16, 1
%18 = icmp eq i64 %14, 0
br i1 %18, label %38, label %19
19: ; preds = %10
%20 = and i64 %16, -2
br label %21
21: ; preds = %21, %19
%22 = phi i64 [ 0, %19 ], [ %35, %21 ]
%23 = phi i64 [ 0, %19 ], [ %36, %21 ]
%24 = getelementptr inbounds double, double* %0, i64 %22
%25 = bitcast double* %24 to <2 x double>*
%26 = load <2 x double>, <2 x double>* %25
%27 = fdiv <2 x double> %26, %13
%28 = bitcast double* %24 to <2 x double>*
store <2 x double> %27, <2 x double>* %28
%29 = or i64 %22, 2
%30 = getelementptr inbounds double, double* %0, i64 %29
%31 = bitcast double* %30 to <2 x double>*
%32 = load <2 x double>, <2 x double>* %31
%33 = fdiv <2 x double> %32, %13
%34 = bitcast double* %30 to <2 x double>*
store <2 x double> %33, <2 x double>* %34
%35 = add nuw i64 %22, 4
%36 = add nuw i64 %23, 2
%37 = icmp eq i64 %36, %20
br i1 %37, label %38, label %21
38: ; preds = %21, %10
%39 = phi i64 [ 0, %10 ], [ %35, %21 ]
%40 = icmp eq i64 %17, 0
br i1 %40, label %47, label %41
41: ; preds = %38
%42 = getelementptr inbounds double, double* %0, i64 %39
%43 = bitcast double* %42 to <2 x double>*
%44 = load <2 x double>, <2 x double>* %43
%45 = fdiv <2 x double> %44, %13
%46 = bitcast double* %42 to <2 x double>*
store <2 x double> %45, <2 x double>* %46
br label %47
47: ; preds = %38, %41
%48 = icmp eq i64 %11, %8
br i1 %48, label %51, label %49
49: ; preds = %7, %47
%50 = phi i64 [ 0, %7 ], [ %11, %47 ]
br label %52
51: ; preds = %52, %47, %3
ret void
52: ; preds = %49, %52
%53 = phi i64 [ %57, %52 ], [ %50, %49 ]
%54 = getelementptr inbounds double, double* %0, i64 %53
%55 = load double, double* %54
%56 = fdiv double %55, %5
store double %56, double* %54
%57 = add nuw nsw i64 %53, 1
%58 = icmp eq i64 %57, %8
br i1 %58, label %51, label %52
}