; LLVM IR from cvxgrp/scs :: src/cones.ll (scs_set_r_y)

; 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"

%struct.SCS_CONE_WORK = type { ptr, ptr, i32, i32, ptr, i32, double }
%struct.ScsCone = type { i32, i32, ptr, ptr, i32, ptr, i32, ptr, i32, i32, i32, ptr, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @_scs_set_r_y(ptr noundef %0, double noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %8

8:                                                ; preds = %24, %3
  %9 = load i32, ptr %7, align 4, !tbaa !11
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.SCS_CONE_WORK, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = getelementptr inbounds %struct.ScsCone, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !15
  %15 = icmp slt i32 %9, %14
  br i1 %15, label %16, label %27

16:                                               ; preds = %8
  %17 = load double, ptr %5, align 8, !tbaa !9
  %18 = fmul double 1.000000e+03, %17
  %19 = fdiv double 1.000000e+00, %18
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load i32, ptr %7, align 4, !tbaa !11
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds double, ptr %20, i64 %22
  store double %19, ptr %23, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %16
  %25 = load i32, ptr %7, align 4, !tbaa !11
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %7, align 4, !tbaa !11
  br label %8, !llvm.loop !17

27:                                               ; preds = %8
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.SCS_CONE_WORK, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  %31 = getelementptr inbounds %struct.ScsCone, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !15
  store i32 %32, ptr %7, align 4, !tbaa !11
  br label %33

33:                                               ; preds = %46, %27
  %34 = load i32, ptr %7, align 4, !tbaa !11
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.SCS_CONE_WORK, ptr %35, i32 0, i32 5
  %37 = load i32, ptr %36, align 8, !tbaa !19
  %38 = icmp slt i32 %34, %37
  br i1 %38, label %39, label %49

39:                                               ; preds = %33
  %40 = load double, ptr %5, align 8, !tbaa !9
  %41 = fdiv double 1.000000e+00, %40
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load i32, ptr %7, align 4, !tbaa !11
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds double, ptr %42, i64 %44
  store double %41, ptr %45, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %39
  %47 = load i32, ptr %7, align 4, !tbaa !11
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %7, align 4, !tbaa !11
  br label %33, !llvm.loop !20

49:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"SCS_CONE_WORK", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !6, i64 24, !12, i64 32, !10, i64 40}
!15 = !{!16, !12, i64 0}
!16 = !{!"", !12, i64 0, !12, i64 4, !6, i64 8, !6, i64 16, !12, i64 24, !6, i64 32, !12, i64 40, !6, i64 48, !12, i64 56, !12, i64 60, !12, i64 64, !6, i64 72, !12, i64 80}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!14, !12, i64 32}
!20 = distinct !{!20, !18}


; 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 norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_scs_set_r_y(ptr nocapture noundef readonly %0, double noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = load i32, ptr %4, align 8, !tbaa !12
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %.preheader

.lr.ph:                                           ; preds = %3
  %7 = fmul double %1, 1.000000e+03
  %8 = fdiv double 1.000000e+00, %7
  %wide.trip.count = zext nneg i32 %5 to i64
  %min.iters.check = icmp ult i32 %5, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

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

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %wide.trip.count, 2147483644
  %broadcast.splatinsert = insertelement <2 x double> poison, double %8, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %9 = getelementptr inbounds double, ptr %2, i64 %index
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  store <2 x double> %broadcast.splat, ptr %9, align 8, !tbaa !14
  store <2 x double> %broadcast.splat, ptr %10, align 8, !tbaa !14
  %index.next = add nuw i64 %index, 4
  %11 = icmp eq i64 %index.next, %n.vec
  br i1 %11, label %middle.block, label %vector.body, !llvm.loop !15

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

.preheader:                                       ; preds = %scalar.ph, %middle.block, %3
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  %13 = load i32, ptr %12, align 8, !tbaa !19
  %14 = icmp slt i32 %5, %13
  br i1 %14, label %.lr.ph15, label %._crit_edge

.lr.ph15:                                         ; preds = %.preheader
  %15 = fdiv double 1.000000e+00, %1
  %16 = sext i32 %5 to i64
  %wide.trip.count20 = sext i32 %13 to i64
  %17 = sub nsw i64 %wide.trip.count20, %16
  %min.iters.check24 = icmp ult i64 %17, 4
  br i1 %min.iters.check24, label %scalar.ph23.preheader, label %vector.ph25

scalar.ph23.preheader:                            ; preds = %middle.block22, %.lr.ph15
  %indvars.iv17.ph = phi i64 [ %16, %.lr.ph15 ], [ %ind.end, %middle.block22 ]
  br label %scalar.ph23

vector.ph25:                                      ; preds = %.lr.ph15
  %n.vec27 = and i64 %17, -4
  %ind.end = add nsw i64 %n.vec27, %16
  %broadcast.splatinsert31 = insertelement <2 x double> poison, double %15, i64 0
  %broadcast.splat32 = shufflevector <2 x double> %broadcast.splatinsert31, <2 x double> poison, <2 x i32> zeroinitializer
  %invariant.gep = getelementptr double, ptr %2, i64 %16
  br label %vector.body29

vector.body29:                                    ; preds = %vector.body29, %vector.ph25
  %index30 = phi i64 [ 0, %vector.ph25 ], [ %index.next33, %vector.body29 ]
  %gep = getelementptr double, ptr %invariant.gep, i64 %index30
  %18 = getelementptr inbounds i8, ptr %gep, i64 16
  store <2 x double> %broadcast.splat32, ptr %gep, align 8, !tbaa !14
  store <2 x double> %broadcast.splat32, ptr %18, align 8, !tbaa !14
  %index.next33 = add nuw i64 %index30, 4
  %19 = icmp eq i64 %index.next33, %n.vec27
  br i1 %19, label %middle.block22, label %vector.body29, !llvm.loop !20

middle.block22:                                   ; preds = %vector.body29
  %cmp.n34 = icmp eq i64 %17, %n.vec27
  br i1 %cmp.n34, label %._crit_edge, label %scalar.ph23.preheader

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %20 = getelementptr inbounds double, ptr %2, i64 %indvars.iv
  store double %8, ptr %20, align 8, !tbaa !14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %scalar.ph, !llvm.loop !21

scalar.ph23:                                      ; preds = %scalar.ph23.preheader, %scalar.ph23
  %indvars.iv17 = phi i64 [ %indvars.iv.next18, %scalar.ph23 ], [ %indvars.iv17.ph, %scalar.ph23.preheader ]
  %21 = getelementptr inbounds double, ptr %2, i64 %indvars.iv17
  store double %15, ptr %21, align 8, !tbaa !14
  %indvars.iv.next18 = add nsw i64 %indvars.iv17, 1
  %exitcond21.not = icmp eq i64 %indvars.iv.next18, %wide.trip.count20
  br i1 %exitcond21.not, label %._crit_edge, label %scalar.ph23, !llvm.loop !22

._crit_edge:                                      ; preds = %scalar.ph23, %middle.block22, %.preheader
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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" }

!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, !7, i64 0}
!6 = !{!"SCS_CONE_WORK", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !7, i64 24, !10, i64 32, !11, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!13, !10, i64 0}
!13 = !{!"", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 16, !10, i64 24, !7, i64 32, !10, i64 40, !7, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !7, i64 72, !10, i64 80}
!14 = !{!11, !11, i64 0}
!15 = distinct !{!15, !16, !17, !18}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!"llvm.loop.isvectorized", i32 1}
!18 = !{!"llvm.loop.unroll.runtime.disable"}
!19 = !{!6, !10, i64 32}
!20 = distinct !{!20, !16, !17, !18}
!21 = distinct !{!21, !16, !18, !17}
!22 = distinct !{!22, !16, !18, !17}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass