; LLVM IR from bbrister/SIFT3D :: sift3d (sift)

; 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._Keypoint_store = type { ptr, %struct._Slab, i32, i32, i32 }
%struct._Slab = type { ptr, i64, i64 }
%struct._Keypoint = type { [9 x float], %struct._Mat_rm, double, double, double, double, i32, i32 }
%struct._Mat_rm = type { %union.anon, i64, i32, i32, i32, i32 }
%union.anon = type { ptr }

declare void @init_Slab(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @init_Keypoint(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @resize_Keypoint_store(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._Keypoint_store, ptr %12, i32 0, i32 1
  %14 = getelementptr inbounds %struct._Slab, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  store ptr %15, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = add i64 %16, 500
  %18 = sub i64 %17, 1
  %19 = udiv i64 %18, 500
  store i64 %19, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = mul i64 %20, 500
  %22 = mul i64 %21, 112
  store i64 %22, ptr %8, align 8, !tbaa !9
  %23 = load i64, ptr %8, align 8, !tbaa !9
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._Keypoint_store, ptr %24, i32 0, i32 1
  %26 = getelementptr inbounds %struct._Slab, ptr %25, i32 0, i32 2
  %27 = load i64, ptr %26, align 8, !tbaa !15
  %28 = icmp ne i64 %23, %27
  br i1 %28, label %29, label %55

29:                                               ; preds = %2
  %30 = load i64, ptr %8, align 8, !tbaa !9
  %31 = icmp eq i64 %30, 0
  br i1 %31, label %32, label %37

32:                                               ; preds = %29
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._Keypoint_store, ptr %33, i32 0, i32 1
  call void @cleanup_Slab(ptr noundef %34)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._Keypoint_store, ptr %35, i32 0, i32 1
  call void @init_Slab(ptr noundef %36)
  br label %50

37:                                               ; preds = %29
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._Keypoint_store, ptr %38, i32 0, i32 1
  %40 = getelementptr inbounds %struct._Slab, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  %42 = load i64, ptr %8, align 8, !tbaa !9
  %43 = call ptr @SIFT3D_safe_realloc(ptr noundef %41, i64 noundef %42)
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._Keypoint_store, ptr %44, i32 0, i32 1
  %46 = getelementptr inbounds %struct._Slab, ptr %45, i32 0, i32 0
  store ptr %43, ptr %46, align 8, !tbaa !11
  %47 = icmp eq ptr %43, null
  br i1 %47, label %48, label %49

48:                                               ; preds = %37
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %60

49:                                               ; preds = %37
  br label %50

50:                                               ; preds = %49, %32
  %51 = load i64, ptr %8, align 8, !tbaa !9
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._Keypoint_store, ptr %52, i32 0, i32 1
  %54 = getelementptr inbounds %struct._Slab, ptr %53, i32 0, i32 2
  store i64 %51, ptr %54, align 8, !tbaa !15
  br label %55

55:                                               ; preds = %50, %2
  %56 = load i64, ptr %5, align 8, !tbaa !9
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._Keypoint_store, ptr %57, i32 0, i32 1
  %59 = getelementptr inbounds %struct._Slab, ptr %58, i32 0, i32 1
  store i64 %56, ptr %59, align 8, !tbaa !16
  store i32 0, ptr %9, align 4
  br label %60

60:                                               ; preds = %55, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %61 = load i32, ptr %9, align 4
  switch i32 %61, label %107 [
    i32 0, label %62
  ]

62:                                               ; preds = %60
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._Keypoint_store, ptr %63, i32 0, i32 1
  %65 = getelementptr inbounds %struct._Slab, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !11
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._Keypoint_store, ptr %67, i32 0, i32 0
  store ptr %66, ptr %68, align 8, !tbaa !17
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._Keypoint_store, ptr %70, i32 0, i32 1
  %72 = getelementptr inbounds %struct._Slab, ptr %71, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !11
  %74 = icmp ne ptr %69, %73
  br i1 %74, label %75, label %106

75:                                               ; preds = %62
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !18
  br label %76

76:                                               ; preds = %99, %75
  %77 = load i32, ptr %10, align 4, !tbaa !18
  %78 = sext i32 %77 to i64
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct._Keypoint_store, ptr %79, i32 0, i32 1
  %81 = getelementptr inbounds %struct._Slab, ptr %80, i32 0, i32 1
  %82 = load i64, ptr %81, align 8, !tbaa !16
  %83 = icmp ult i64 %78, %82
  br i1 %83, label %84, label %102

84:                                               ; preds = %76
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct._Keypoint_store, ptr %85, i32 0, i32 0
  %87 = load ptr, ptr %86, align 8, !tbaa !17
  %88 = load i32, ptr %10, align 4, !tbaa !18
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds %struct._Keypoint, ptr %87, i64 %89
  store ptr %90, ptr %11, align 8, !tbaa !5
  %91 = load ptr, ptr %11, align 8, !tbaa !5
  %92 = call i32 @init_Keypoint(ptr noundef %91)
  %93 = icmp ne i32 %92, 0
  br i1 %93, label %94, label %95

94:                                               ; preds = %84
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %96

95:                                               ; preds = %84
  store i32 0, ptr %9, align 4
  br label %96

96:                                               ; preds = %95, %94
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %97 = load i32, ptr %9, align 4
  switch i32 %97, label %103 [
    i32 0, label %98
  ]

98:                                               ; preds = %96
  br label %99

99:                                               ; preds = %98
  %100 = load i32, ptr %10, align 4, !tbaa !18
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %10, align 4, !tbaa !18
  br label %76, !llvm.loop !19

102:                                              ; preds = %76
  store i32 0, ptr %9, align 4
  br label %103

103:                                              ; preds = %102, %96
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %104 = load i32, ptr %9, align 4
  switch i32 %104, label %107 [
    i32 0, label %105
  ]

105:                                              ; preds = %103
  br label %106

106:                                              ; preds = %105, %62
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %107

107:                                              ; preds = %106, %103, %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %108 = load i32, ptr %3, align 4
  ret i32 %108
}

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

declare void @cleanup_Slab(ptr noundef) #0

declare ptr @SIFT3D_safe_realloc(ptr noundef, i64 noundef) #0

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

attributes #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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_Keypoint_store", !6, i64 0, !13, i64 8, !14, i64 32, !14, i64 36, !14, i64 40}
!13 = !{!"_Slab", !6, i64 0, !10, i64 8, !10, i64 16}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !10, i64 24}
!16 = !{!12, !10, i64 16}
!17 = !{!12, !6, i64 0}
!18 = !{!14, !14, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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

%struct._Keypoint = type { [9 x float], %struct._Mat_rm, double, double, double, double, i32, i32 }
%struct._Mat_rm = type { %union.anon, i64, i32, i32, i32, i32 }
%union.anon = type { ptr }

declare void @init_Slab(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @resize_Keypoint_store(ptr noundef %0, i64 noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = add i64 %1, 499
  %6 = urem i64 %5, 500
  %7 = sub nuw i64 %5, %6
  %8 = mul i64 %7, 112
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load i64, ptr %9, align 8, !tbaa !13
  %.not = icmp eq i64 %8, %10
  br i1 %.not, label %.critedge.thread, label %12

.critedge.thread:                                 ; preds = %2
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %1, ptr %11, align 8, !tbaa !14
  store ptr %4, ptr %0, align 8, !tbaa !15
  br label %.critedge39

12:                                               ; preds = %2
  %13 = icmp eq i64 %8, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %12
  tail call void @cleanup_Slab(ptr noundef nonnull %3) #2
  tail call void @init_Slab(ptr noundef nonnull %3) #2
  %.pre.pre = load ptr, ptr %3, align 8, !tbaa !5
  br label %.critedge

15:                                               ; preds = %12
  %16 = tail call ptr @SIFT3D_safe_realloc(ptr noundef %4, i64 noundef %8) #2
  store ptr %16, ptr %3, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %.critedge39, label %.critedge

.critedge:                                        ; preds = %14, %15
  %.pre = phi ptr [ %16, %15 ], [ %.pre.pre, %14 ]
  store i64 %8, ptr %9, align 8, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %1, ptr %18, align 8, !tbaa !14
  store ptr %.pre, ptr %0, align 8, !tbaa !15
  %.not35 = icmp eq ptr %4, %.pre
  %.not3740.not = icmp eq i64 %1, 0
  %or.cond = or i1 %.not35, %.not3740.not
  br i1 %or.cond, label %.critedge39, label %.lr.ph

19:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = load i64, ptr %18, align 8, !tbaa !14
  %.not37 = icmp ugt i64 %20, %indvars.iv.next
  br i1 %.not37, label %.lr.ph, label %.critedge39, !llvm.loop !16

.lr.ph:                                           ; preds = %.critedge, %19
  %indvars.iv = phi i64 [ %indvars.iv.next, %19 ], [ 0, %.critedge ]
  %21 = load ptr, ptr %0, align 8, !tbaa !15
  %22 = getelementptr inbounds %struct._Keypoint, ptr %21, i64 %indvars.iv
  %23 = tail call i32 @init_Keypoint(ptr noundef %22)
  %.not36 = icmp eq i32 %23, 0
  br i1 %.not36, label %19, label %.critedge39

.critedge39:                                      ; preds = %.lr.ph, %19, %.critedge.thread, %.critedge, %15
  %.4 = phi i32 [ -1, %15 ], [ 0, %.critedge ], [ 0, %.critedge.thread ], [ -1, %.lr.ph ], [ 0, %19 ]
  ret i32 %.4
}

declare void @cleanup_Slab(ptr noundef) local_unnamed_addr #0

declare ptr @SIFT3D_safe_realloc(ptr noundef, i64 noundef) local_unnamed_addr #0

attributes #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 = { 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, !7, i64 8}
!6 = !{!"_Keypoint_store", !7, i64 0, !10, i64 8, !12, i64 32, !12, i64 36, !12, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Slab", !7, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"long", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!6, !11, i64 24}
!14 = !{!6, !11, i64 16}
!15 = !{!6, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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