#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 fabs(double);
void dirvet(double *sample, int n_samp, double dx) {
  int i;
  for (i = 0; i < n_samp; i++)
    sample[i] *= dx / fabs(dx);
}


x86 assembly (clang, -O0):
<dirvet>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    115c <dirvet+0x5c>
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movaps 0xecc(%rip),%xmm2
pand   %xmm2,%xmm1
divsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1117 <dirvet+0x17>
pop    %rbp
ret

x86 assembly (clang, -O2):
<dirvet>:
test   %esi,%esi
jle    11f7 <dirvet+0xf7>
movapd 0xef0(%rip),%xmm1
andpd  %xmm0,%xmm1
divsd  %xmm1,%xmm0
mov    %esi,%eax
cmp    $0x4,%esi
jae    1126 <dirvet+0x26>
xor    %ecx,%ecx
jmp    11e0 <dirvet+0xe0>
mov    %eax,%ecx
and    $0xfffffffc,%ecx
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
lea    -0x4(%rcx),%rdx
mov    %rdx,%r8
shr    $0x2,%r8
add    $0x1,%r8
test   %rdx,%rdx
je     11f8 <dirvet+0xf8>
mov    %r8,%rsi
and    $0xfffffffffffffffe,%rsi
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movupd (%rdi,%rdx,8),%xmm2
movupd 0x10(%rdi,%rdx,8),%xmm3
movupd 0x20(%rdi,%rdx,8),%xmm4
movupd 0x30(%rdi,%rdx,8),%xmm5
mulpd  %xmm1,%xmm2
mulpd  %xmm1,%xmm3
movupd %xmm2,(%rdi,%rdx,8)
movupd %xmm3,0x10(%rdi,%rdx,8)
mulpd  %xmm1,%xmm4
mulpd  %xmm1,%xmm5
movupd %xmm4,0x20(%rdi,%rdx,8)
movupd %xmm5,0x30(%rdi,%rdx,8)
add    $0x8,%rdx
add    $0xfffffffffffffffe,%rsi
jne    1160 <dirvet+0x60>
test   $0x1,%r8b
je     11cc <dirvet+0xcc>
movupd (%rdi,%rdx,8),%xmm2
movupd 0x10(%rdi,%rdx,8),%xmm3
mulpd  %xmm1,%xmm2
mulpd  %xmm1,%xmm3
movupd %xmm2,(%rdi,%rdx,8)
movupd %xmm3,0x10(%rdi,%rdx,8)
cmp    %rax,%rcx
je     11f7 <dirvet+0xf7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  (%rdi,%rcx,8),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rdi,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    11e0 <dirvet+0xe0>
ret
xor    %edx,%edx
test   $0x1,%r8b
jne    11ae <dirvet+0xae>
jmp    11cc <dirvet+0xcc>

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

LLVM IR (-O2):
define void @dirvet(double* nocapture %0, i32 %1, double %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %75
5: ; preds = %3
%6 = tail call double @llvm.fabs.f64(double %2)
%7 = fdiv double %2, %6
%8 = zext i32 %1 to i64
%9 = icmp ult i32 %1, 4
br i1 %9, label %66, label %10
10: ; preds = %5
%11 = and i64 %8, 4294967292
%12 = insertelement <2 x double> poison, double %7, i64 0
%13 = shufflevector <2 x double> %12, <2 x double> poison, <2 x i32> zeroinitializer
%14 = insertelement <2 x double> poison, double %7, i64 0
%15 = shufflevector <2 x double> %14, <2 x double> poison, <2 x i32> zeroinitializer
%16 = add nsw i64 %11, -4
%17 = lshr exact i64 %16, 2
%18 = add nuw nsw i64 %17, 1
%19 = and i64 %18, 1
%20 = icmp eq i64 %16, 0
br i1 %20, label %50, label %21
21: ; preds = %10
%22 = and i64 %18, 9223372036854775806
br label %23
23: ; preds = %23, %21
%24 = phi i64 [ 0, %21 ], [ %47, %23 ]
%25 = phi i64 [ 0, %21 ], [ %48, %23 ]
%26 = getelementptr inbounds double, double* %0, i64 %24
%27 = bitcast double* %26 to <2 x double>*
%28 = load <2 x double>, <2 x double>* %27
%29 = getelementptr inbounds double, double* %26, i64 2
%30 = bitcast double* %29 to <2 x double>*
%31 = load <2 x double>, <2 x double>* %30
%32 = fmul <2 x double> %13, %28
%33 = fmul <2 x double> %15, %31
%34 = bitcast double* %26 to <2 x double>*
store <2 x double> %32, <2 x double>* %34
%35 = bitcast double* %29 to <2 x double>*
store <2 x double> %33, <2 x double>* %35
%36 = or i64 %24, 4
%37 = getelementptr inbounds double, double* %0, i64 %36
%38 = bitcast double* %37 to <2 x double>*
%39 = load <2 x double>, <2 x double>* %38
%40 = getelementptr inbounds double, double* %37, i64 2
%41 = bitcast double* %40 to <2 x double>*
%42 = load <2 x double>, <2 x double>* %41
%43 = fmul <2 x double> %13, %39
%44 = fmul <2 x double> %15, %42
%45 = bitcast double* %37 to <2 x double>*
store <2 x double> %43, <2 x double>* %45
%46 = bitcast double* %40 to <2 x double>*
store <2 x double> %44, <2 x double>* %46
%47 = add nuw i64 %24, 8
%48 = add i64 %25, 2
%49 = icmp eq i64 %48, %22
br i1 %49, label %50, label %23
50: ; preds = %23, %10
%51 = phi i64 [ 0, %10 ], [ %47, %23 ]
%52 = icmp eq i64 %19, 0
br i1 %52, label %64, label %53
53: ; preds = %50
%54 = getelementptr inbounds double, double* %0, i64 %51
%55 = bitcast double* %54 to <2 x double>*
%56 = load <2 x double>, <2 x double>* %55
%57 = getelementptr inbounds double, double* %54, i64 2
%58 = bitcast double* %57 to <2 x double>*
%59 = load <2 x double>, <2 x double>* %58
%60 = fmul <2 x double> %13, %56
%61 = fmul <2 x double> %15, %59
%62 = bitcast double* %54 to <2 x double>*
store <2 x double> %60, <2 x double>* %62
%63 = bitcast double* %57 to <2 x double>*
store <2 x double> %61, <2 x double>* %63
br label %64
64: ; preds = %50, %53
%65 = icmp eq i64 %11, %8
br i1 %65, label %75, label %66
66: ; preds = %5, %64
%67 = phi i64 [ 0, %5 ], [ %11, %64 ]
br label %68
68: ; preds = %66, %68
%69 = phi i64 [ %73, %68 ], [ %67, %66 ]
%70 = getelementptr inbounds double, double* %0, i64 %69
%71 = load double, double* %70
%72 = fmul double %7, %71
store double %72, double* %70
%73 = add nuw nsw i64 %69, 1
%74 = icmp eq i64 %73, %8
br i1 %74, label %75, label %68
75: ; preds = %68, %64, %3
ret void
}