; LLVM IR from siavashserver/neonrvm :: example (rbf)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @rbf(i64 noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, double noundef %4, i1 noundef zeroext %5, ptr noundef %6) #1 {
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca double, align 8
  %13 = alloca i8, align 1
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  %17 = alloca i64, align 8
  %18 = alloca double, align 8
  %19 = alloca double, align 8
  %20 = alloca i64, align 8
  store i64 %0, ptr %8, align 8, !tbaa !5
  store i64 %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !9
  store double %4, ptr %12, align 8, !tbaa !11
  %21 = zext i1 %5 to i8
  store i8 %21, ptr %13, align 1, !tbaa !13
  store ptr %6, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  store i64 0, ptr %15, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %62, %7
  %23 = load i64, ptr %15, align 8, !tbaa !5
  %24 = load i64, ptr %9, align 8, !tbaa !5
  %25 = icmp ult i64 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  store i32 2, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  br label %65

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  store i64 0, ptr %17, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %58, %27
  %29 = load i64, ptr %17, align 8, !tbaa !5
  %30 = load i64, ptr %8, align 8, !tbaa !5
  %31 = icmp ult i64 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  store i32 5, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  br label %61

33:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %34 = load ptr, ptr %11, align 8, !tbaa !9
  %35 = load i64, ptr %15, align 8, !tbaa !5
  %36 = getelementptr inbounds double, ptr %34, i64 %35
  %37 = load double, ptr %36, align 8, !tbaa !11
  %38 = load ptr, ptr %10, align 8, !tbaa !9
  %39 = load i64, ptr %17, align 8, !tbaa !5
  %40 = getelementptr inbounds double, ptr %38, i64 %39
  %41 = load double, ptr %40, align 8, !tbaa !11
  %42 = fsub double %37, %41
  store double %42, ptr %18, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  %43 = load double, ptr %12, align 8, !tbaa !11
  %44 = fneg double %43
  %45 = load double, ptr %18, align 8, !tbaa !11
  %46 = fmul double %44, %45
  %47 = load double, ptr %18, align 8, !tbaa !11
  %48 = fmul double %46, %47
  %49 = call double @exp(double noundef %48) #3
  store double %49, ptr %19, align 8, !tbaa !11
  %50 = load double, ptr %19, align 8, !tbaa !11
  %51 = load ptr, ptr %14, align 8, !tbaa !9
  %52 = load i64, ptr %15, align 8, !tbaa !5
  %53 = load i64, ptr %8, align 8, !tbaa !5
  %54 = mul i64 %52, %53
  %55 = load i64, ptr %17, align 8, !tbaa !5
  %56 = add i64 %54, %55
  %57 = getelementptr inbounds double, ptr %51, i64 %56
  store double %50, ptr %57, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  br label %58

58:                                               ; preds = %33
  %59 = load i64, ptr %17, align 8, !tbaa !5
  %60 = add i64 %59, 1
  store i64 %60, ptr %17, align 8, !tbaa !5
  br label %28, !llvm.loop !15

61:                                               ; preds = %32
  br label %62

62:                                               ; preds = %61
  %63 = load i64, ptr %15, align 8, !tbaa !5
  %64 = add i64 %63, 1
  store i64 %64, ptr %15, align 8, !tbaa !5
  br label %22, !llvm.loop !17

65:                                               ; preds = %26
  %66 = load i8, ptr %13, align 1, !tbaa !13, !range !18, !noundef !19
  %67 = trunc i8 %66 to i1
  br i1 %67, label %68, label %86

68:                                               ; preds = %65
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  store i64 0, ptr %20, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %82, %68
  %70 = load i64, ptr %20, align 8, !tbaa !5
  %71 = load i64, ptr %8, align 8, !tbaa !5
  %72 = icmp ult i64 %70, %71
  br i1 %72, label %74, label %73

73:                                               ; preds = %69
  store i32 8, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  br label %85

74:                                               ; preds = %69
  %75 = load ptr, ptr %14, align 8, !tbaa !9
  %76 = load i64, ptr %8, align 8, !tbaa !5
  %77 = load i64, ptr %9, align 8, !tbaa !5
  %78 = mul i64 %76, %77
  %79 = load i64, ptr %20, align 8, !tbaa !5
  %80 = add i64 %78, %79
  %81 = getelementptr inbounds double, ptr %75, i64 %80
  store double 1.000000e+00, ptr %81, align 8, !tbaa !11
  br label %82

82:                                               ; preds = %74
  %83 = load i64, ptr %20, align 8, !tbaa !5
  %84 = add i64 %83, 1
  store i64 %84, ptr %20, align 8, !tbaa !5
  br label %69, !llvm.loop !20

85:                                               ; preds = %73
  br label %86

86:                                               ; preds = %85, %65
  ret void
}

; Function Attrs: nounwind
declare double @exp(double noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = distinct !{!20, !16}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nofree nounwind memory(write, argmem: readwrite) uwtable
define dso_local void @rbf(i64 noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, double noundef %4, i1 noundef zeroext %5, ptr nocapture noundef writeonly %6) local_unnamed_addr #0 {
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %._crit_edge32, label %.preheader29.lr.ph

.preheader29.lr.ph:                               ; preds = %7
  %.not34 = icmp eq i64 %0, 0
  %8 = fneg double %4
  br i1 %.not34, label %.loopexit, label %.preheader29.us

.preheader29.us:                                  ; preds = %.preheader29.lr.ph, %._crit_edge.us
  %.02531.us = phi i64 [ %22, %._crit_edge.us ], [ 0, %.preheader29.lr.ph ]
  %9 = getelementptr inbounds double, ptr %3, i64 %.02531.us
  %10 = mul i64 %.02531.us, %0
  %11 = getelementptr double, ptr %6, i64 %10
  br label %12

12:                                               ; preds = %.preheader29.us, %12
  %.02630.us = phi i64 [ 0, %.preheader29.us ], [ %21, %12 ]
  %13 = load double, ptr %9, align 8, !tbaa !5
  %14 = getelementptr inbounds double, ptr %2, i64 %.02630.us
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = fsub double %13, %15
  %17 = fmul double %16, %8
  %18 = fmul double %16, %17
  %19 = tail call double @exp(double noundef %18) #2
  %20 = getelementptr double, ptr %11, i64 %.02630.us
  store double %19, ptr %20, align 8, !tbaa !5
  %21 = add nuw i64 %.02630.us, 1
  %exitcond.not = icmp eq i64 %21, %0
  br i1 %exitcond.not, label %._crit_edge.us, label %12, !llvm.loop !9

._crit_edge.us:                                   ; preds = %12
  %22 = add nuw i64 %.02531.us, 1
  %exitcond36.not = icmp eq i64 %22, %1
  br i1 %exitcond36.not, label %._crit_edge32, label %.preheader29.us, !llvm.loop !11

._crit_edge32:                                    ; preds = %._crit_edge.us, %7
  %23 = icmp ne i64 %0, 0
  %or.cond = and i1 %23, %5
  br i1 %or.cond, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %._crit_edge32
  %24 = mul i64 %1, %0
  %25 = getelementptr double, ptr %6, i64 %24
  %min.iters.check = icmp ult i64 %0, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %0, -4
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %26 = getelementptr double, ptr %25, i64 %index
  %27 = getelementptr i8, ptr %26, i64 16
  store <2 x double> <double 1.000000e+00, double 1.000000e+00>, ptr %26, align 8, !tbaa !5
  store <2 x double> <double 1.000000e+00, double 1.000000e+00>, ptr %27, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %28 = icmp eq i64 %index.next, %n.vec
  br i1 %28, label %middle.block, label %vector.body, !llvm.loop !12

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %0
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %.033.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.033 = phi i64 [ %30, %scalar.ph ], [ %.033.ph, %scalar.ph.preheader ]
  %29 = getelementptr double, ptr %25, i64 %.033
  store double 1.000000e+00, ptr %29, align 8, !tbaa !5
  %30 = add nuw i64 %.033, 1
  %exitcond37.not = icmp eq i64 %30, %0
  br i1 %exitcond37.not, label %.loopexit, label %scalar.ph, !llvm.loop !15

.loopexit:                                        ; preds = %scalar.ph, %middle.block, %.preheader29.lr.ph, %._crit_edge32
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @exp(double noundef) local_unnamed_addr #1

attributes #0 = { nofree nounwind memory(write, argmem: readwrite) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nofree nounwind willreturn memory(write) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10, !13, !14}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !10, !14, !13}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass