; LLVM IR from darnstrom/daqp :: src (auxiliary)

; 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.DAQPWorkspace = type { ptr, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, double, ptr, ptr, ptr, ptr, i32, ptr, i32, i32, i32, double, ptr, ptr, i32, ptr }
%struct.DAQPSettings = type { double, double, double, double, double, i32, i32, double, double, double, double, double, double }
%struct.DAQPBnB = type { ptr, i32, i32, ptr, i32, ptr, i32, i32, ptr, i32, i32 }

; Function Attrs: nounwind uwtable
declare dso_local void @remove_constraint(ptr noundef, i32 noundef) #0

; 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
define dso_local void @pivot_last(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.DAQPWorkspace, ptr %7, i32 0, i32 24
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = sub nsw i32 %9, 2
  store i32 %10, ptr %3, align 4, !tbaa !13
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.DAQPWorkspace, ptr %11, i32 0, i32 24
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = icmp sgt i32 %13, 1
  br i1 %14, label %15, label %122

15:                                               ; preds = %1
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.DAQPWorkspace, ptr %16, i32 0, i32 19
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = load i32, ptr %3, align 4, !tbaa !13
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds double, ptr %18, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !15
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.DAQPWorkspace, ptr %23, i32 0, i32 28
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %26 = getelementptr inbounds %struct.DAQPSettings, ptr %25, i32 0, i32 3
  %27 = load double, ptr %26, align 8, !tbaa !17
  %28 = fcmp olt double %22, %27
  br i1 %28, label %29, label %122

29:                                               ; preds = %15
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.DAQPWorkspace, ptr %30, i32 0, i32 19
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = load i32, ptr %3, align 4, !tbaa !13
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds double, ptr %32, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !15
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.DAQPWorkspace, ptr %37, i32 0, i32 19
  %39 = load ptr, ptr %38, align 8, !tbaa !14
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.DAQPWorkspace, ptr %40, i32 0, i32 24
  %42 = load i32, ptr %41, align 8, !tbaa !9
  %43 = sub nsw i32 %42, 1
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds double, ptr %39, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !15
  %47 = fcmp olt double %36, %46
  br i1 %47, label %48, label %122

48:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.DAQPWorkspace, ptr %49, i32 0, i32 23
  %51 = load ptr, ptr %50, align 8, !tbaa !19
  %52 = load i32, ptr %3, align 4, !tbaa !13
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i32, ptr %51, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !13
  store i32 %55, ptr %4, align 4, !tbaa !13
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.DAQPWorkspace, ptr %56, i32 0, i32 9
  %58 = load ptr, ptr %57, align 8, !tbaa !20
  %59 = load i32, ptr %4, align 4, !tbaa !13
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i32, ptr %58, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !13
  %63 = and i32 %62, 16
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %85

65:                                               ; preds = %48
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.DAQPWorkspace, ptr %66, i32 0, i32 9
  %68 = load ptr, ptr %67, align 8, !tbaa !20
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.DAQPWorkspace, ptr %69, i32 0, i32 23
  %71 = load ptr, ptr %70, align 8, !tbaa !19
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.DAQPWorkspace, ptr %72, i32 0, i32 24
  %74 = load i32, ptr %73, align 8, !tbaa !9
  %75 = sub nsw i32 %74, 1
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds i32, ptr %71, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !13
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds i32, ptr %68, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !13
  %82 = and i32 %81, 16
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %85

84:                                               ; preds = %65
  store i32 1, ptr %5, align 4
  br label %119

85:                                               ; preds = %65, %48
  %86 = load ptr, ptr %2, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.DAQPWorkspace, ptr %86, i32 0, i32 29
  %88 = load ptr, ptr %87, align 8, !tbaa !21
  %89 = icmp ne ptr %88, null
  br i1 %89, label %90, label %99

90:                                               ; preds = %85
  %91 = load i32, ptr %3, align 4, !tbaa !13
  %92 = load ptr, ptr %2, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.DAQPWorkspace, ptr %92, i32 0, i32 29
  %94 = load ptr, ptr %93, align 8, !tbaa !21
  %95 = getelementptr inbounds %struct.DAQPBnB, ptr %94, i32 0, i32 7
  %96 = load i32, ptr %95, align 4, !tbaa !22
  %97 = icmp slt i32 %91, %96
  br i1 %97, label %98, label %99

98:                                               ; preds = %90
  store i32 1, ptr %5, align 4
  br label %119

99:                                               ; preds = %90, %85
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %100 = load ptr, ptr %2, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.DAQPWorkspace, ptr %100, i32 0, i32 14
  %102 = load ptr, ptr %101, align 8, !tbaa !24
  %103 = load i32, ptr %3, align 4, !tbaa !13
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds double, ptr %102, i64 %104
  %106 = load double, ptr %105, align 8, !tbaa !15
  store double %106, ptr %6, align 8, !tbaa !15
  %107 = load ptr, ptr %2, align 8, !tbaa !5
  %108 = load i32, ptr %3, align 4, !tbaa !13
  call void @remove_constraint(ptr noundef %107, i32 noundef %108)
  %109 = load ptr, ptr %2, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.DAQPWorkspace, ptr %109, i32 0, i32 26
  %111 = load i32, ptr %110, align 8, !tbaa !25
  %112 = icmp ne i32 %111, -1
  br i1 %112, label %113, label %114

113:                                              ; preds = %99
  store i32 1, ptr %5, align 4
  br label %118

114:                                              ; preds = %99
  %115 = load ptr, ptr %2, align 8, !tbaa !5
  %116 = load i32, ptr %4, align 4, !tbaa !13
  %117 = load double, ptr %6, align 8, !tbaa !15
  call void @add_constraint(ptr noundef %115, i32 noundef %116, double noundef %117)
  store i32 0, ptr %5, align 4
  br label %118

118:                                              ; preds = %114, %113
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %119

119:                                              ; preds = %118, %98, %84
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %120 = load i32, ptr %5, align 4
  switch i32 %120, label %123 [
    i32 0, label %121
  ]

121:                                              ; preds = %119
  br label %122

122:                                              ; preds = %121, %29, %15, %1
  store i32 0, ptr %5, align 4
  br label %123

123:                                              ; preds = %122, %119
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  %124 = load i32, ptr %5, align 4
  switch i32 %124, label %126 [
    i32 0, label %125
    i32 1, label %125
  ]

125:                                              ; preds = %123, %123
  ret void

126:                                              ; preds = %123
  unreachable
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @add_constraint(ptr noundef, i32 noundef, double noundef) #0

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, !11, i64 184}
!10 = !{!"", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !12, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !11, i64 168, !6, i64 176, !11, i64 184, !11, i64 188, !11, i64 192, !12, i64 200, !6, i64 208, !6, i64 216, !11, i64 224, !6, i64 232}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 144}
!15 = !{!12, !12, i64 0}
!16 = !{!10, !6, i64 208}
!17 = !{!18, !12, i64 24}
!18 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !11, i64 40, !11, i64 44, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88}
!19 = !{!10, !6, i64 176}
!20 = !{!10, !6, i64 64}
!21 = !{!10, !6, i64 216}
!22 = !{!23, !11, i64 44}
!23 = !{!"", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16, !11, i64 24, !6, i64 32, !11, i64 40, !11, i64 44, !6, i64 48, !11, i64 56, !11, i64 60}
!24 = !{!10, !6, i64 104}
!25 = !{!10, !11, i64 192}


; 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 @remove_constraint(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @pivot_last(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 184
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = add nsw i32 %3, -2
  %5 = icmp sgt i32 %3, 1
  br i1 %5, label %6, label %.critedge

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 144
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %9 = zext nneg i32 %4 to i64
  %10 = getelementptr inbounds double, ptr %8, i64 %9
  %11 = load double, ptr %10, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %0, i64 208
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %13, i64 24
  %15 = load double, ptr %14, align 8, !tbaa !15
  %16 = fcmp olt double %11, %15
  br i1 %16, label %17, label %.critedge

17:                                               ; preds = %6
  %18 = add nsw i32 %3, -1
  %19 = zext nneg i32 %18 to i64
  %20 = getelementptr inbounds double, ptr %8, i64 %19
  %21 = load double, ptr %20, align 8, !tbaa !13
  %22 = fcmp olt double %11, %21
  br i1 %22, label %23, label %.critedge

23:                                               ; preds = %17
  %24 = getelementptr inbounds i8, ptr %0, i64 176
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  %26 = getelementptr inbounds i32, ptr %25, i64 %9
  %27 = load i32, ptr %26, align 4, !tbaa !18
  %28 = getelementptr inbounds i8, ptr %0, i64 64
  %29 = load ptr, ptr %28, align 8, !tbaa !19
  %30 = sext i32 %27 to i64
  %31 = getelementptr inbounds i32, ptr %29, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !18
  %33 = and i32 %32, 16
  %.not = icmp eq i32 %33, 0
  br i1 %.not, label %41, label %34

34:                                               ; preds = %23
  %35 = getelementptr inbounds i32, ptr %25, i64 %19
  %36 = load i32, ptr %35, align 4, !tbaa !18
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %29, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !18
  %40 = and i32 %39, 16
  %.not30 = icmp eq i32 %40, 0
  br i1 %.not30, label %41, label %.critedge

41:                                               ; preds = %34, %23
  %42 = getelementptr inbounds i8, ptr %0, i64 216
  %43 = load ptr, ptr %42, align 8, !tbaa !20
  %.not31 = icmp eq ptr %43, null
  br i1 %.not31, label %48, label %44

44:                                               ; preds = %41
  %45 = getelementptr inbounds i8, ptr %43, i64 44
  %46 = load i32, ptr %45, align 4, !tbaa !21
  %47 = icmp slt i32 %4, %46
  br i1 %47, label %.critedge, label %48

48:                                               ; preds = %44, %41
  %49 = getelementptr inbounds i8, ptr %0, i64 104
  %50 = load ptr, ptr %49, align 8, !tbaa !23
  %51 = getelementptr inbounds double, ptr %50, i64 %9
  %52 = load double, ptr %51, align 8, !tbaa !13
  tail call void @remove_constraint(ptr noundef nonnull %0, i32 noundef %4)
  %53 = getelementptr inbounds i8, ptr %0, i64 192
  %54 = load i32, ptr %53, align 8, !tbaa !24
  %.not32 = icmp eq i32 %54, -1
  br i1 %.not32, label %55, label %.critedge

55:                                               ; preds = %48
  tail call void @add_constraint(ptr noundef nonnull %0, i32 noundef %27, double noundef %52)
  br label %.critedge

.critedge:                                        ; preds = %55, %48, %34, %44, %1, %6, %17
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @add_constraint(ptr noundef, i32 noundef, double noundef) local_unnamed_addr #0

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

!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 184}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !11, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !7, i64 160, !10, i64 168, !7, i64 176, !10, i64 184, !10, i64 188, !10, i64 192, !11, i64 200, !7, i64 208, !7, i64 216, !10, i64 224, !7, i64 232}
!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 = !{!6, !7, i64 144}
!13 = !{!11, !11, i64 0}
!14 = !{!6, !7, i64 208}
!15 = !{!16, !11, i64 24}
!16 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !10, i64 40, !10, i64 44, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88}
!17 = !{!6, !7, i64 176}
!18 = !{!10, !10, i64 0}
!19 = !{!6, !7, i64 64}
!20 = !{!6, !7, i64 216}
!21 = !{!22, !10, i64 44}
!22 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16, !10, i64 24, !7, i64 32, !10, i64 40, !10, i64 44, !7, i64 48, !10, i64 56, !10, i64 60}
!23 = !{!6, !7, i64 104}
!24 = !{!6, !10, i64 192}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass