; LLVM IR from cvxgrp/scs :: linsys/scs_matrix.ll (scs_accum_by_atrans)

; 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.ScsMatrix = type { ptr, ptr, ptr, i32, i32 }

; 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 @_scs_accum_by_atrans(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ScsMatrix, ptr %16, i32 0, i32 4
  %18 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %18, ptr %12, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ScsMatrix, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  store ptr %21, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ScsMatrix, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  store ptr %24, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ScsMatrix, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  store ptr %27, ptr %15, align 8, !tbaa !5
  store i32 0, ptr %8, align 4, !tbaa !12
  br label %28

28:                                               ; preds = %80, %3
  %29 = load i32, ptr %8, align 4, !tbaa !12
  %30 = load i32, ptr %12, align 4, !tbaa !12
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %32, label %83

32:                                               ; preds = %28
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load i32, ptr %8, align 4, !tbaa !12
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds double, ptr %33, i64 %35
  %37 = load double, ptr %36, align 8, !tbaa !16
  store double %37, ptr %11, align 8, !tbaa !16
  %38 = load ptr, ptr %13, align 8, !tbaa !5
  %39 = load i32, ptr %8, align 4, !tbaa !12
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds i32, ptr %38, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !12
  store i32 %42, ptr %9, align 4, !tbaa !12
  %43 = load ptr, ptr %13, align 8, !tbaa !5
  %44 = load i32, ptr %8, align 4, !tbaa !12
  %45 = add nsw i32 %44, 1
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i32, ptr %43, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !12
  store i32 %48, ptr %10, align 4, !tbaa !12
  %49 = load i32, ptr %9, align 4, !tbaa !12
  store i32 %49, ptr %7, align 4, !tbaa !12
  br label %50

50:                                               ; preds = %71, %32
  %51 = load i32, ptr %7, align 4, !tbaa !12
  %52 = load i32, ptr %10, align 4, !tbaa !12
  %53 = icmp slt i32 %51, %52
  br i1 %53, label %54, label %74

54:                                               ; preds = %50
  %55 = load ptr, ptr %15, align 8, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !12
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds double, ptr %55, i64 %57
  %59 = load double, ptr %58, align 8, !tbaa !16
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = load ptr, ptr %14, align 8, !tbaa !5
  %62 = load i32, ptr %7, align 4, !tbaa !12
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i32, ptr %61, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !12
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds double, ptr %60, i64 %66
  %68 = load double, ptr %67, align 8, !tbaa !16
  %69 = load double, ptr %11, align 8, !tbaa !16
  %70 = call double @llvm.fmuladd.f64(double %59, double %68, double %69)
  store double %70, ptr %11, align 8, !tbaa !16
  br label %71

71:                                               ; preds = %54
  %72 = load i32, ptr %7, align 4, !tbaa !12
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %7, align 4, !tbaa !12
  br label %50, !llvm.loop !18

74:                                               ; preds = %50
  %75 = load double, ptr %11, align 8, !tbaa !16
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = load i32, ptr %8, align 4, !tbaa !12
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds double, ptr %76, i64 %78
  store double %75, ptr %79, align 8, !tbaa !16
  br label %80

80:                                               ; preds = %74
  %81 = load i32, ptr %8, align 4, !tbaa !12
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %8, align 4, !tbaa !12
  br label %28, !llvm.loop !20

83:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 28}
!10 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 28}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 16}
!14 = !{!10, !6, i64 8}
!15 = !{!10, !6, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; 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_accum_by_atrans(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 28
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = load ptr, ptr %0, align 8, !tbaa !13
  %11 = icmp sgt i32 %5, 0
  br i1 %11, label %.lr.ph31.preheader, label %._crit_edge32

.lr.ph31.preheader:                               ; preds = %3
  %wide.trip.count37 = zext nneg i32 %5 to i64
  %.pre = load i32, ptr %7, align 4, !tbaa !14
  br label %.lr.ph31

.lr.ph31:                                         ; preds = %.lr.ph31.preheader, %._crit_edge
  %12 = phi i32 [ %.pre, %.lr.ph31.preheader ], [ %16, %._crit_edge ]
  %indvars.iv34 = phi i64 [ 0, %.lr.ph31.preheader ], [ %indvars.iv.next35, %._crit_edge ]
  %13 = getelementptr inbounds double, ptr %2, i64 %indvars.iv34
  %14 = load double, ptr %13, align 8, !tbaa !15
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %15 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv.next35
  %16 = load i32, ptr %15, align 4, !tbaa !14
  %17 = icmp slt i32 %12, %16
  br i1 %17, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.lr.ph31
  %18 = sext i32 %12 to i64
  %wide.trip.count = sext i32 %16 to i64
  %19 = sub nsw i64 %wide.trip.count, %18
  %xtraiter = and i64 %19, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.lr.ph.prol ], [ %18, %.lr.ph.preheader ]
  %.02627.prol = phi double [ %27, %.lr.ph.prol ], [ %14, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %20 = getelementptr inbounds double, ptr %10, i64 %indvars.iv.prol
  %21 = load double, ptr %20, align 8, !tbaa !15
  %22 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv.prol
  %23 = load i32, ptr %22, align 4, !tbaa !14
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds double, ptr %1, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !15
  %27 = tail call double @llvm.fmuladd.f64(double %21, double %26, double %.02627.prol)
  %indvars.iv.next.prol = add nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !17

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.lcssa.unr = phi double [ poison, %.lr.ph.preheader ], [ %27, %.lr.ph.prol ]
  %indvars.iv.unr = phi i64 [ %18, %.lr.ph.preheader ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %.02627.unr = phi double [ %14, %.lr.ph.preheader ], [ %27, %.lr.ph.prol ]
  %28 = sub nsw i64 %18, %wide.trip.count
  %29 = icmp ugt i64 %28, -4
  br i1 %29, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.lr.ph ], [ %indvars.iv.unr, %.lr.ph.prol.loopexit ]
  %.02627 = phi double [ %61, %.lr.ph ], [ %.02627.unr, %.lr.ph.prol.loopexit ]
  %30 = getelementptr inbounds double, ptr %10, i64 %indvars.iv
  %31 = load double, ptr %30, align 8, !tbaa !15
  %32 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv
  %33 = load i32, ptr %32, align 4, !tbaa !14
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds double, ptr %1, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !15
  %37 = tail call double @llvm.fmuladd.f64(double %31, double %36, double %.02627)
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %38 = getelementptr inbounds double, ptr %10, i64 %indvars.iv.next
  %39 = load double, ptr %38, align 8, !tbaa !15
  %40 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv.next
  %41 = load i32, ptr %40, align 4, !tbaa !14
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds double, ptr %1, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !15
  %45 = tail call double @llvm.fmuladd.f64(double %39, double %44, double %37)
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, 2
  %46 = getelementptr inbounds double, ptr %10, i64 %indvars.iv.next.1
  %47 = load double, ptr %46, align 8, !tbaa !15
  %48 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv.next.1
  %49 = load i32, ptr %48, align 4, !tbaa !14
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds double, ptr %1, i64 %50
  %52 = load double, ptr %51, align 8, !tbaa !15
  %53 = tail call double @llvm.fmuladd.f64(double %47, double %52, double %45)
  %indvars.iv.next.2 = add nsw i64 %indvars.iv, 3
  %54 = getelementptr inbounds double, ptr %10, i64 %indvars.iv.next.2
  %55 = load double, ptr %54, align 8, !tbaa !15
  %56 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv.next.2
  %57 = load i32, ptr %56, align 4, !tbaa !14
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds double, ptr %1, i64 %58
  %60 = load double, ptr %59, align 8, !tbaa !15
  %61 = tail call double @llvm.fmuladd.f64(double %55, double %60, double %53)
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge, label %.lr.ph, !llvm.loop !19

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %.lr.ph31
  %.026.lcssa = phi double [ %14, %.lr.ph31 ], [ %.lcssa.unr, %.lr.ph.prol.loopexit ], [ %61, %.lr.ph ]
  store double %.026.lcssa, ptr %13, align 8, !tbaa !15
  %exitcond38.not = icmp eq i64 %indvars.iv.next35, %wide.trip.count37
  br i1 %exitcond38.not, label %._crit_edge32, label %.lr.ph31, !llvm.loop !21

._crit_edge32:                                    ; preds = %._crit_edge, %3
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !10, i64 28}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 16}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !7, i64 0}
!14 = !{!10, !10, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass