; LLVM IR from cvxgrp/scs :: linsys/cpu/direct (private)

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

@.str.1 = external hidden unnamed_addr constant [43 x i8], align 1

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

8:                                                ; preds = %42, %2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = icmp slt i32 %9, %12
  br i1 %13, label %14, label %45

14:                                               ; preds = %8
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %15, i32 0, i32 15
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds double, ptr %17, i64 %19
  %21 = load double, ptr %20, align 8, !tbaa !14
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds double, ptr %22, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !14
  %27 = fadd double %21, %26
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !16
  %31 = getelementptr inbounds %struct.ScsMatrix, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %33, i32 0, i32 7
  %35 = load ptr, ptr %34, align 8, !tbaa !19
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %35, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds double, ptr %32, i64 %40
  store double %27, ptr %41, align 8, !tbaa !14
  br label %42

42:                                               ; preds = %14
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %5, align 4, !tbaa !9
  br label %8, !llvm.loop !20

45:                                               ; preds = %8
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !11
  store i32 %48, ptr %5, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %80, %45
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !11
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 8, !tbaa !22
  %57 = add nsw i32 %53, %56
  %58 = icmp slt i32 %50, %57
  br i1 %58, label %59, label %83

59:                                               ; preds = %49
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load i32, ptr %5, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds double, ptr %60, i64 %62
  %64 = load double, ptr %63, align 8, !tbaa !14
  %65 = fneg double %64
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !16
  %69 = getelementptr inbounds %struct.ScsMatrix, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !17
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %71, i32 0, i32 7
  %73 = load ptr, ptr %72, align 8, !tbaa !19
  %74 = load i32, ptr %5, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds i32, ptr %73, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !9
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds double, ptr %70, i64 %78
  store double %65, ptr %79, align 8, !tbaa !14
  br label %80

80:                                               ; preds = %59
  %81 = load i32, ptr %5, align 4, !tbaa !9
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %5, align 4, !tbaa !9
  br label %49, !llvm.loop !23

83:                                               ; preds = %49
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %85, i32 0, i32 1
  %87 = load i32, ptr %86, align 4, !tbaa !11
  %88 = call i32 @ldl_factor(ptr noundef %84, i32 noundef %87)
  store i32 %88, ptr %6, align 4, !tbaa !9
  %89 = load i32, ptr %6, align 4, !tbaa !9
  %90 = icmp slt i32 %89, 0
  br i1 %90, label %91, label %93

91:                                               ; preds = %83
  %92 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  store i32 1, ptr %7, align 4
  br label %94

93:                                               ; preds = %83
  store i32 0, ptr %7, align 4
  br label %94

94:                                               ; preds = %93, %91
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %95 = load i32, ptr %7, align 4
  switch i32 %95, label %97 [
    i32 0, label %96
    i32 1, label %96
  ]

96:                                               ; preds = %94, %94
  ret void

97:                                               ; preds = %94
  unreachable
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @ldl_factor(ptr noundef, i32 noundef) #0

declare i32 @printf(ptr noundef, ...) #2

; 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 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"SCS_LIN_SYS_WORK", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112}
!13 = !{!12, !6, i64 112}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = !{!12, !6, i64 8}
!17 = !{!18, !6, i64 0}
!18 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 28}
!19 = !{!12, !6, i64 48}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!12, !10, i64 0}
!23 = distinct !{!23, !21}


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

@.str.1 = external hidden unnamed_addr constant [43 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @scs_update_lin_sys_diag_r(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %.preheader

.lr.ph:                                           ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 112
  %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 %9, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %0, i64 48
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %wide.trip.count = zext nneg i32 %4 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %13 = icmp eq i32 %4, 1
  br i1 %13, label %.preheader.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %33

.preheader.loopexit.unr-lcssa:                    ; preds = %33, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %33 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.preheader.loopexit.epilog-lcssa

.preheader.loopexit.epilog-lcssa:                 ; preds = %.preheader.loopexit.unr-lcssa
  %14 = getelementptr inbounds double, ptr %7, i64 %indvars.iv.unr
  %15 = load double, ptr %14, align 8, !tbaa !16
  %16 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.unr
  %17 = load double, ptr %16, align 8, !tbaa !16
  %18 = fadd double %15, %17
  %19 = getelementptr inbounds i32, ptr %12, i64 %indvars.iv.unr
  %20 = load i32, ptr %19, align 4, !tbaa !18
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds double, ptr %10, i64 %21
  store double %18, ptr %22, align 8, !tbaa !16
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit.epilog-lcssa, %.preheader.loopexit.unr-lcssa, %2
  %23 = load i32, ptr %0, align 8, !tbaa !19
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %.lr.ph25, label %._crit_edge

.lr.ph25:                                         ; preds = %.preheader
  %25 = add nsw i32 %23, %4
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %0, i64 48
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = sext i32 %4 to i64
  %32 = sext i32 %25 to i64
  br label %52

33:                                               ; preds = %33, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %33 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %33 ]
  %34 = getelementptr inbounds double, ptr %7, i64 %indvars.iv
  %35 = load double, ptr %34, align 8, !tbaa !16
  %36 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %37 = load double, ptr %36, align 8, !tbaa !16
  %38 = fadd double %35, %37
  %39 = getelementptr inbounds i32, ptr %12, i64 %indvars.iv
  %40 = load i32, ptr %39, align 4, !tbaa !18
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds double, ptr %10, i64 %41
  store double %38, ptr %42, align 8, !tbaa !16
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %43 = getelementptr inbounds double, ptr %7, i64 %indvars.iv.next
  %44 = load double, ptr %43, align 8, !tbaa !16
  %45 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next
  %46 = load double, ptr %45, align 8, !tbaa !16
  %47 = fadd double %44, %46
  %48 = getelementptr inbounds i32, ptr %12, i64 %indvars.iv.next
  %49 = load i32, ptr %48, align 4, !tbaa !18
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds double, ptr %10, i64 %50
  store double %47, ptr %51, align 8, !tbaa !16
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.preheader.loopexit.unr-lcssa, label %33, !llvm.loop !20

52:                                               ; preds = %.lr.ph25, %52
  %indvars.iv27 = phi i64 [ %31, %.lr.ph25 ], [ %indvars.iv.next28, %52 ]
  %53 = getelementptr inbounds double, ptr %1, i64 %indvars.iv27
  %54 = load double, ptr %53, align 8, !tbaa !16
  %55 = fneg double %54
  %56 = getelementptr inbounds i32, ptr %30, i64 %indvars.iv27
  %57 = load i32, ptr %56, align 4, !tbaa !18
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds double, ptr %28, i64 %58
  store double %55, ptr %59, align 8, !tbaa !16
  %indvars.iv.next28 = add nsw i64 %indvars.iv27, 1
  %60 = icmp slt i64 %indvars.iv.next28, %32
  br i1 %60, label %52, label %._crit_edge, !llvm.loop !22

._crit_edge:                                      ; preds = %52, %.preheader
  %61 = tail call i32 @ldl_factor(ptr noundef nonnull %0, i32 noundef %4)
  %62 = icmp slt i32 %61, 0
  br i1 %62, label %63, label %65

63:                                               ; preds = %._crit_edge
  %64 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %65

65:                                               ; preds = %._crit_edge, %63
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden i32 @ldl_factor(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { nofree 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" }

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


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