; 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.otri = type { ptr, i32 }
%struct.behavior = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, float, float, float, float }
%struct.mesh = type { %struct.memorypool, %struct.memorypool, %struct.memorypool, %struct.memorypool, %struct.memorypool, %struct.memorypool, %struct.memorypool, %struct.memorypool, [4096 x ptr], [4096 x ptr], [4096 x i32], i32, ptr, float, float, float, float, float, i32, i32, i32, i32, i32, i32, i64, i32, i32, i32, i64, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, i64, i64, i64, i64, i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %struct.otri }
%struct.memorypool = type { ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i64, i64, i32, i32 }

@plus1mod3 = external dso_local global [3 x i32], align 4
@.str.36 = external hidden unnamed_addr constant [54 x i8], align 1

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

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

; 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 @traversalinit(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @triangletraverse(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @makevertexmap(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.otri, align 8
  %6 = alloca ptr, align 8
  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 16, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.behavior, ptr %7, i32 0, i32 29
  %9 = load i32, ptr %8, align 4, !tbaa !9
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %13

11:                                               ; preds = %2
  %12 = call i32 (ptr, ...) @printf(ptr noundef @.str.36)
  br label %13

13:                                               ; preds = %11, %2
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.mesh, ptr %14, i32 0, i32 0
  call void @traversalinit(ptr noundef %15)
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call ptr @triangletraverse(ptr noundef %16)
  %18 = getelementptr inbounds %struct.otri, ptr %5, i32 0, i32 0
  store ptr %17, ptr %18, align 8, !tbaa !13
  br label %19

19:                                               ; preds = %59, %13
  %20 = getelementptr inbounds %struct.otri, ptr %5, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %63

23:                                               ; preds = %19
  %24 = getelementptr inbounds %struct.otri, ptr %5, i32 0, i32 1
  store i32 0, ptr %24, align 8, !tbaa !15
  br label %25

25:                                               ; preds = %55, %23
  %26 = getelementptr inbounds %struct.otri, ptr %5, i32 0, i32 1
  %27 = load i32, ptr %26, align 8, !tbaa !15
  %28 = icmp slt i32 %27, 3
  br i1 %28, label %29, label %59

29:                                               ; preds = %25
  %30 = getelementptr inbounds %struct.otri, ptr %5, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = getelementptr inbounds %struct.otri, ptr %5, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !15
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [3 x i32], ptr @plus1mod3, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !16
  %37 = add nsw i32 %36, 3
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds ptr, ptr %31, i64 %38
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  store ptr %40, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.otri, ptr %5, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = ptrtoint ptr %42 to i64
  %44 = getelementptr inbounds %struct.otri, ptr %5, i32 0, i32 1
  %45 = load i32, ptr %44, align 8, !tbaa !15
  %46 = sext i32 %45 to i64
  %47 = or i64 %43, %46
  %48 = inttoptr i64 %47 to ptr
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.mesh, ptr %50, i32 0, i32 31
  %52 = load i32, ptr %51, align 8, !tbaa !17
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds ptr, ptr %49, i64 %53
  store ptr %48, ptr %54, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %29
  %56 = getelementptr inbounds %struct.otri, ptr %5, i32 0, i32 1
  %57 = load i32, ptr %56, align 8, !tbaa !15
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %56, align 8, !tbaa !15
  br label %25, !llvm.loop !21

59:                                               ; preds = %25
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = call ptr @triangletraverse(ptr noundef %60)
  %62 = getelementptr inbounds %struct.otri, ptr %5, i32 0, i32 0
  store ptr %61, ptr %62, align 8, !tbaa !13
  br label %19, !llvm.loop !23

63:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #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 116}
!10 = !{!"behavior", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !11, i64 120, !11, i64 124, !11, i64 128, !11, i64 132, !12, i64 136, !12, i64 140, !12, i64 144, !12, i64 148}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"otri", !6, i64 0, !11, i64 8}
!15 = !{!14, !11, i64 8}
!16 = !{!11, !11, i64 0}
!17 = !{!18, !11, i64 82728}
!18 = !{!"mesh", !19, i64 0, !19, i64 88, !19, i64 176, !19, i64 264, !19, i64 352, !19, i64 440, !19, i64 528, !19, i64 616, !7, i64 704, !7, i64 33472, !7, i64 66240, !11, i64 82624, !6, i64 82632, !12, i64 82640, !12, i64 82644, !12, i64 82648, !12, i64 82652, !12, i64 82656, !11, i64 82660, !11, i64 82664, !11, i64 82668, !11, i64 82672, !11, i64 82676, !11, i64 82680, !20, i64 82688, !11, i64 82696, !11, i64 82700, !11, i64 82704, !20, i64 82712, !11, i64 82720, !11, i64 82724, !11, i64 82728, !11, i64 82732, !11, i64 82736, !11, i64 82740, !11, i64 82744, !11, i64 82748, !11, i64 82752, !20, i64 82760, !20, i64 82768, !20, i64 82776, !20, i64 82784, !20, i64 82792, !20, i64 82800, !20, i64 82808, !6, i64 82816, !6, i64 82824, !6, i64 82832, !6, i64 82840, !6, i64 82848, !6, i64 82856, !6, i64 82864, !14, i64 82872}
!19 = !{!"memorypool", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !20, i64 64, !20, i64 72, !11, i64 80, !11, i64 84}
!20 = !{!"long", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


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

@plus1mod3 = external dso_local local_unnamed_addr global [3 x i32], align 4
@.str.36 = external hidden unnamed_addr constant [54 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @triangletraverse(ptr noundef) local_unnamed_addr #1

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

5:                                                ; preds = %2
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.36)
  br label %7

7:                                                ; preds = %5, %2
  tail call void @traversalinit(ptr noundef %0)
  %8 = tail call ptr @triangletraverse(ptr noundef %0)
  %.not1113 = icmp eq ptr %8, null
  br i1 %.not1113, label %._crit_edge, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %7
  %9 = getelementptr inbounds i8, ptr %0, i64 82728
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %.preheader
  %.sroa.0.014 = phi ptr [ %8, %.preheader.lr.ph ], [ %35, %.preheader ]
  %10 = ptrtoint ptr %.sroa.0.014 to i64
  %11 = load i32, ptr %9, align 8, !tbaa !11
  %12 = sext i32 %11 to i64
  %13 = load i32, ptr @plus1mod3, align 4, !tbaa !17
  %14 = add nsw i32 %13, 3
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds ptr, ptr %.sroa.0.014, i64 %15
  %17 = load ptr, ptr %16, align 8, !tbaa !18
  %18 = getelementptr inbounds ptr, ptr %17, i64 %12
  store ptr %.sroa.0.014, ptr %18, align 8, !tbaa !18
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @plus1mod3, i64 4), align 4, !tbaa !17
  %20 = add nsw i32 %19, 3
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds ptr, ptr %.sroa.0.014, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !18
  %24 = or i64 %10, 1
  %25 = inttoptr i64 %24 to ptr
  %26 = getelementptr inbounds ptr, ptr %23, i64 %12
  store ptr %25, ptr %26, align 8, !tbaa !18
  %27 = load i32, ptr getelementptr inbounds (i8, ptr @plus1mod3, i64 8), align 4, !tbaa !17
  %28 = add nsw i32 %27, 3
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds ptr, ptr %.sroa.0.014, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !18
  %32 = or i64 %10, 2
  %33 = inttoptr i64 %32 to ptr
  %34 = getelementptr inbounds ptr, ptr %31, i64 %12
  store ptr %33, ptr %34, align 8, !tbaa !18
  %35 = tail call ptr @triangletraverse(ptr noundef %0)
  %.not11 = icmp eq ptr %35, null
  br i1 %.not11, label %._crit_edge, label %.preheader, !llvm.loop !19

._crit_edge:                                      ; preds = %.preheader, %7
  ret void
}

attributes #0 = { 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" }
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" }

!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 116}
!6 = !{!"behavior", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !7, i64 72, !7, i64 76, !7, i64 80, !7, i64 84, !7, i64 88, !7, i64 92, !7, i64 96, !7, i64 100, !7, i64 104, !7, i64 108, !7, i64 112, !7, i64 116, !7, i64 120, !7, i64 124, !7, i64 128, !7, i64 132, !10, i64 136, !10, i64 140, !10, i64 144, !10, i64 148}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!12, !7, i64 82728}
!12 = !{!"mesh", !13, i64 0, !13, i64 88, !13, i64 176, !13, i64 264, !13, i64 352, !13, i64 440, !13, i64 528, !13, i64 616, !8, i64 704, !8, i64 33472, !8, i64 66240, !7, i64 82624, !14, i64 82632, !10, i64 82640, !10, i64 82644, !10, i64 82648, !10, i64 82652, !10, i64 82656, !7, i64 82660, !7, i64 82664, !7, i64 82668, !7, i64 82672, !7, i64 82676, !7, i64 82680, !15, i64 82688, !7, i64 82696, !7, i64 82700, !7, i64 82704, !15, i64 82712, !7, i64 82720, !7, i64 82724, !7, i64 82728, !7, i64 82732, !7, i64 82736, !7, i64 82740, !7, i64 82744, !7, i64 82748, !7, i64 82752, !15, i64 82760, !15, i64 82768, !15, i64 82776, !15, i64 82784, !15, i64 82792, !15, i64 82800, !15, i64 82808, !14, i64 82816, !14, i64 82824, !14, i64 82832, !14, i64 82840, !14, i64 82848, !14, i64 82856, !14, i64 82864, !16, i64 82872}
!13 = !{!"memorypool", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !15, i64 64, !15, i64 72, !7, i64 80, !7, i64 84}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!"long", !8, i64 0}
!16 = !{!"otri", !14, i64 0, !7, i64 8}
!17 = !{!7, !7, i64 0}
!18 = !{!14, !14, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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