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

; 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
declare dso_local void @_scs_accum_by_atrans(ptr noundef, ptr noundef, ptr noundef) #1

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

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

26:                                               ; preds = %76, %3
  %27 = load i32, ptr %8, align 4, !tbaa !12
  %28 = load i32, ptr %10, align 4, !tbaa !12
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %30, label %79

30:                                               ; preds = %26
  %31 = load ptr, ptr %11, align 8, !tbaa !5
  %32 = load i32, ptr %8, align 4, !tbaa !12
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i32, ptr %31, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !12
  store i32 %35, ptr %7, align 4, !tbaa !12
  br label %36

36:                                               ; preds = %72, %30
  %37 = load i32, ptr %7, align 4, !tbaa !12
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = load i32, ptr %8, align 4, !tbaa !12
  %40 = add nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr %38, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !12
  %44 = icmp slt i32 %37, %43
  br i1 %44, label %45, label %75

45:                                               ; preds = %36
  %46 = load ptr, ptr %12, align 8, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !12
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i32, ptr %46, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !12
  store i32 %50, ptr %9, align 4, !tbaa !12
  %51 = load i32, ptr %9, align 4, !tbaa !12
  %52 = load i32, ptr %8, align 4, !tbaa !12
  %53 = icmp ne i32 %51, %52
  br i1 %53, label %54, label %71

54:                                               ; preds = %45
  %55 = load ptr, ptr %13, 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 i32, ptr %8, align 4, !tbaa !12
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds double, ptr %60, i64 %62
  %64 = load double, ptr %63, align 8, !tbaa !16
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load i32, ptr %9, align 4, !tbaa !12
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds double, ptr %65, i64 %67
  %69 = load double, ptr %68, align 8, !tbaa !16
  %70 = call double @llvm.fmuladd.f64(double %59, double %64, double %69)
  store double %70, ptr %68, align 8, !tbaa !16
  br label %71

71:                                               ; preds = %54, %45
  br label %72

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

75:                                               ; preds = %36
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %8, align 4, !tbaa !12
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %8, align 4, !tbaa !12
  br label %26, !llvm.loop !20

79:                                               ; preds = %26
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_scs_accum_by_atrans(ptr noundef %80, ptr noundef %81, ptr noundef %82)
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, 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
}

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: nounwind uwtable
declare dso_local void @_scs_accum_by_atrans(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @_scs_accum_by_p(ptr noundef %0, ptr noundef %1, ptr 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.ph29.preheader, label %._crit_edge

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

.loopexit:                                        ; preds = %.prol.loopexit, %55, %.lr.ph29
  %exitcond35.not = icmp eq i64 %indvars.iv.next32, %wide.trip.count34
  br i1 %exitcond35.not, label %._crit_edge, label %.lr.ph29, !llvm.loop !15

.lr.ph29:                                         ; preds = %.lr.ph29.preheader, %.loopexit
  %12 = phi i32 [ %.pre, %.lr.ph29.preheader ], [ %14, %.loopexit ]
  %indvars.iv31 = phi i64 [ 0, %.lr.ph29.preheader ], [ %indvars.iv.next32, %.loopexit ]
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %13 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv.next32
  %14 = load i32, ptr %13, align 4, !tbaa !14
  %15 = icmp slt i32 %12, %14
  br i1 %15, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph29
  %16 = getelementptr inbounds double, ptr %1, i64 %indvars.iv31
  %17 = sext i32 %12 to i64
  %wide.trip.count = sext i32 %14 to i64
  %18 = sub nsw i64 %wide.trip.count, %17
  %xtraiter = and i64 %18, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.preheader

.prol.preheader:                                  ; preds = %.lr.ph
  %19 = getelementptr inbounds i32, ptr %9, i64 %17
  %20 = load i32, ptr %19, align 4, !tbaa !14
  %21 = zext i32 %20 to i64
  %.not.prol = icmp eq i64 %indvars.iv31, %21
  br i1 %.not.prol, label %.prol.loopexit.unr-lcssa, label %22

22:                                               ; preds = %.prol.preheader
  %23 = getelementptr inbounds double, ptr %10, i64 %17
  %24 = load double, ptr %23, align 8, !tbaa !17
  %25 = load double, ptr %16, align 8, !tbaa !17
  %26 = sext i32 %20 to i64
  %27 = getelementptr inbounds double, ptr %2, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !17
  %29 = tail call double @llvm.fmuladd.f64(double %24, double %25, double %28)
  store double %29, ptr %27, align 8, !tbaa !17
  br label %.prol.loopexit.unr-lcssa

.prol.loopexit.unr-lcssa:                         ; preds = %22, %.prol.preheader
  %indvars.iv.next.prol = add nsw i64 %17, 1
  br label %.prol.loopexit

.prol.loopexit:                                   ; preds = %.prol.loopexit.unr-lcssa, %.lr.ph
  %indvars.iv.unr = phi i64 [ %17, %.lr.ph ], [ %indvars.iv.next.prol, %.prol.loopexit.unr-lcssa ]
  %30 = add nsw i64 %wide.trip.count, -1
  %31 = icmp eq i64 %30, %17
  br i1 %31, label %.loopexit, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.prol.loopexit, %55
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %55 ], [ %indvars.iv.unr, %.prol.loopexit ]
  %32 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv
  %33 = load i32, ptr %32, align 4, !tbaa !14
  %34 = zext i32 %33 to i64
  %.not = icmp eq i64 %indvars.iv31, %34
  br i1 %.not, label %43, label %35

35:                                               ; preds = %.lr.ph.new
  %36 = getelementptr inbounds double, ptr %10, i64 %indvars.iv
  %37 = load double, ptr %36, align 8, !tbaa !17
  %38 = load double, ptr %16, align 8, !tbaa !17
  %39 = sext i32 %33 to i64
  %40 = getelementptr inbounds double, ptr %2, i64 %39
  %41 = load double, ptr %40, align 8, !tbaa !17
  %42 = tail call double @llvm.fmuladd.f64(double %37, double %38, double %41)
  store double %42, ptr %40, align 8, !tbaa !17
  br label %43

43:                                               ; preds = %.lr.ph.new, %35
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %44 = getelementptr inbounds i32, ptr %9, i64 %indvars.iv.next
  %45 = load i32, ptr %44, align 4, !tbaa !14
  %46 = zext i32 %45 to i64
  %.not.1 = icmp eq i64 %indvars.iv31, %46
  br i1 %.not.1, label %55, label %47

47:                                               ; preds = %43
  %48 = getelementptr inbounds double, ptr %10, i64 %indvars.iv.next
  %49 = load double, ptr %48, align 8, !tbaa !17
  %50 = load double, ptr %16, align 8, !tbaa !17
  %51 = sext i32 %45 to i64
  %52 = getelementptr inbounds double, ptr %2, i64 %51
  %53 = load double, ptr %52, align 8, !tbaa !17
  %54 = tail call double @llvm.fmuladd.f64(double %49, double %50, double %53)
  store double %54, ptr %52, align 8, !tbaa !17
  br label %55

55:                                               ; preds = %47, %43
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %wide.trip.count
  br i1 %exitcond.not.1, label %.loopexit, label %.lr.ph.new, !llvm.loop !19

._crit_edge:                                      ; preds = %.loopexit, %3
  tail call void @_scs_accum_by_atrans(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %2)
  ret void
}

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 = { 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 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !8, i64 0}
!19 = distinct !{!19, !16}


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