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

%struct.memorypool = type { ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i64, i64, i32, i32 }

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

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

; Function Attrs: nounwind uwtable
define dso_local void @poolinit(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %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
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = icmp ugt i64 %12, 8
  br i1 %13, label %14, label %18

14:                                               ; preds = %5
  %15 = load i32, ptr %10, align 4, !tbaa !9
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.memorypool, ptr %16, i32 0, i32 6
  store i32 %15, ptr %17, align 8, !tbaa !11
  br label %21

18:                                               ; preds = %5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.memorypool, ptr %19, i32 0, i32 6
  store i32 8, ptr %20, align 8, !tbaa !11
  br label %21

21:                                               ; preds = %18, %14
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = sub nsw i32 %22, 1
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.memorypool, ptr %24, i32 0, i32 6
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = sdiv i32 %23, %26
  %28 = add nsw i32 %27, 1
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.memorypool, ptr %29, i32 0, i32 6
  %31 = load i32, ptr %30, align 8, !tbaa !11
  %32 = mul nsw i32 %28, %31
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.memorypool, ptr %33, i32 0, i32 7
  store i32 %32, ptr %34, align 4, !tbaa !14
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.memorypool, ptr %36, i32 0, i32 8
  store i32 %35, ptr %37, align 8, !tbaa !15
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %44

40:                                               ; preds = %21
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.memorypool, ptr %42, i32 0, i32 9
  store i32 %41, ptr %43, align 4, !tbaa !16
  br label %48

44:                                               ; preds = %21
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.memorypool, ptr %46, i32 0, i32 9
  store i32 %45, ptr %47, align 4, !tbaa !16
  br label %48

48:                                               ; preds = %44, %40
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.memorypool, ptr %49, i32 0, i32 9
  %51 = load i32, ptr %50, align 4, !tbaa !16
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.memorypool, ptr %52, i32 0, i32 7
  %54 = load i32, ptr %53, align 4, !tbaa !14
  %55 = mul nsw i32 %51, %54
  %56 = add nsw i32 %55, 8
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.memorypool, ptr %57, i32 0, i32 6
  %59 = load i32, ptr %58, align 8, !tbaa !11
  %60 = add nsw i32 %56, %59
  %61 = call ptr @trimalloc(i32 noundef %60)
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.memorypool, ptr %62, i32 0, i32 0
  store ptr %61, ptr %63, align 8, !tbaa !17
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.memorypool, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !17
  store ptr null, ptr %66, align 8, !tbaa !5
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  call void @poolrestart(ptr noundef %67)
  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)"}
!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 48}
!12 = !{!"memorypool", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !13, i64 64, !13, i64 72, !10, i64 80, !10, i64 84}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !10, i64 52}
!15 = !{!12, !10, i64 56}
!16 = !{!12, !10, i64 60}
!17 = !{!12, !6, 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 ptr @trimalloc(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @poolrestart(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @poolinit(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %spec.select = tail call i32 @llvm.umax.i32(i32 %4, i32 8)
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %spec.select, ptr %6, align 8
  %7 = add nsw i32 %1, -1
  %8 = sdiv i32 %7, %spec.select
  %9 = add nsw i32 %8, 1
  %10 = mul nsw i32 %9, %spec.select
  %11 = getelementptr inbounds i8, ptr %0, i64 52
  store i32 %10, ptr %11, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 56
  store i32 %2, ptr %12, align 8, !tbaa !12
  %13 = icmp eq i32 %3, 0
  %.sink20 = select i1 %13, i32 %2, i32 %3
  %14 = getelementptr inbounds i8, ptr %0, i64 60
  store i32 %.sink20, ptr %14, align 4
  %15 = mul nsw i32 %.sink20, %10
  %16 = add i32 %spec.select, 8
  %17 = add i32 %16, %15
  %18 = tail call ptr @trimalloc(i32 noundef %17)
  store ptr %18, ptr %0, align 8, !tbaa !13
  store ptr null, ptr %18, align 8, !tbaa !14
  tail call void @poolrestart(ptr noundef nonnull %0)
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #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 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 52}
!6 = !{!"memorypool", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !11, i64 64, !11, i64 72, !10, i64 80, !10, i64 84}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !10, i64 56}
!13 = !{!6, !7, i64 0}
!14 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass