; LLVM IR from MIT-SPARK/Kimera-VIO :: third_party/triangle/src (triangle)

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

; 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 @vertexmedian(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @alternateaxes(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = ashr i32 %8, 1
  store i32 %9, ptr %7, align 4, !tbaa !9
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = icmp sle i32 %10, 3
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %12, %3
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = load i32, ptr %6, align 4, !tbaa !9
  call void @vertexmedian(ptr noundef %14, i32 noundef %15, i32 noundef %16, i32 noundef %17)
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = sub nsw i32 %18, %19
  %21 = icmp sge i32 %20, 2
  br i1 %21, label %22, label %40

22:                                               ; preds = %13
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = icmp sge i32 %23, 2
  br i1 %24, label %25, label %30

25:                                               ; preds = %22
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = sub nsw i32 1, %28
  call void @alternateaxes(ptr noundef %26, i32 noundef %27, i32 noundef %29)
  br label %30

30:                                               ; preds = %25, %22
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds ptr, ptr %31, i64 %33
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = sub nsw i32 %35, %36
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = sub nsw i32 1, %38
  call void @alternateaxes(ptr noundef %34, i32 noundef %37, i32 noundef %39)
  br label %40

40:                                               ; preds = %30, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  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 = { 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}


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

; Function Attrs: nounwind uwtable
define dso_local void @alternateaxes(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = ashr i32 %1, 1
  %5 = icmp slt i32 %1, 4
  %spec.select20 = select i1 %5, i32 0, i32 %2
  tail call void @vertexmedian(ptr noundef %0, i32 noundef %1, i32 noundef %4, i32 noundef %spec.select20)
  %6 = sub nsw i32 %1, %4
  %7 = icmp sgt i32 %6, 1
  br i1 %7, label %.lr.ph.preheader, label %tailrecurse._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %8 = sub nsw i32 1, %2
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %tailrecurse
  %9 = phi i32 [ %18, %tailrecurse ], [ %6, %.lr.ph.preheader ]
  %spec.select23 = phi i32 [ %spec.select, %tailrecurse ], [ %spec.select20, %.lr.ph.preheader ]
  %10 = phi i32 [ %16, %tailrecurse ], [ %4, %.lr.ph.preheader ]
  %.tr1922 = phi i32 [ %spec.select23, %tailrecurse ], [ %8, %.lr.ph.preheader ]
  %.tr21 = phi ptr [ %14, %tailrecurse ], [ %0, %.lr.ph.preheader ]
  %11 = icmp sgt i32 %10, 1
  br i1 %11, label %12, label %tailrecurse

12:                                               ; preds = %.lr.ph
  tail call void @alternateaxes(ptr noundef %.tr21, i32 noundef %10, i32 noundef %.tr1922)
  br label %tailrecurse

tailrecurse:                                      ; preds = %12, %.lr.ph
  %13 = sext i32 %10 to i64
  %14 = getelementptr inbounds ptr, ptr %.tr21, i64 %13
  %15 = sub nsw i32 1, %spec.select23
  %16 = lshr i32 %9, 1
  %17 = icmp ult i32 %9, 4
  %spec.select = select i1 %17, i32 0, i32 %15
  tail call void @vertexmedian(ptr noundef %14, i32 noundef %9, i32 noundef %16, i32 noundef %spec.select)
  %18 = sub nsw i32 %9, %16
  %19 = icmp sgt i32 %18, 1
  br i1 %19, label %.lr.ph, label %tailrecurse._crit_edge

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %3
  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" }

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass