; 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._SIFT3D_Descriptor_store = type { ptr, i64, i32, i32, i32 }
%struct._SIFT3D_Descriptor = type { [64 x %struct._Hist], double, double, double, double }
%struct._Hist = type { [12 x float] }

@stderr = external global ptr, align 8
@.str.15 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [35 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 ptr @SIFT3D_safe_realloc(ptr noundef, i64 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
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @SIFT3D_nn_match(ptr noundef %0, ptr noundef %1, float noundef %2, ptr noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca float, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store float %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._SIFT3D_Descriptor_store, ptr %15, i32 0, i32 1
  %17 = load i64, ptr %16, align 8, !tbaa !11
  %18 = trunc i64 %17 to i32
  store i32 %18, ptr %11, align 4, !tbaa !15
  %19 = load i32, ptr %11, align 4, !tbaa !15
  %20 = icmp slt i32 %19, 1
  br i1 %20, label %21, label %25

21:                                               ; preds = %4
  %22 = load ptr, ptr @stderr, align 8, !tbaa !5
  %23 = load i32, ptr %11, align 4, !tbaa !15
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef @.str.15, i32 noundef %23) #4
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %103

25:                                               ; preds = %4
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = load i32, ptr %11, align 4, !tbaa !15
  %29 = sext i32 %28 to i64
  %30 = mul i64 %29, 4
  %31 = call ptr @SIFT3D_safe_realloc(ptr noundef %27, i64 noundef %30)
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %31, ptr %32, align 8, !tbaa !5
  %33 = icmp eq ptr %31, null
  br i1 %33, label %34, label %37

34:                                               ; preds = %25
  %35 = load ptr, ptr @stderr, align 8, !tbaa !5
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str.16) #4
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %103

37:                                               ; preds = %25
  store i32 0, ptr %10, align 4, !tbaa !15
  br label %38

38:                                               ; preds = %51, %37
  %39 = load i32, ptr %10, align 4, !tbaa !15
  %40 = sext i32 %39 to i64
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._SIFT3D_Descriptor_store, ptr %41, i32 0, i32 1
  %43 = load i64, ptr %42, align 8, !tbaa !11
  %44 = icmp ult i64 %40, %43
  br i1 %44, label %45, label %54

45:                                               ; preds = %38
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = load i32, ptr %10, align 4, !tbaa !15
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i32, ptr %47, i64 %49
  store i32 -1, ptr %50, align 4, !tbaa !15
  br label %51

51:                                               ; preds = %45
  %52 = load i32, ptr %10, align 4, !tbaa !15
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %10, align 4, !tbaa !15
  br label %38, !llvm.loop !16

54:                                               ; preds = %38
  store i32 0, ptr %10, align 4, !tbaa !15
  br label %55

55:                                               ; preds = %99, %54
  %56 = load i32, ptr %10, align 4, !tbaa !15
  %57 = load i32, ptr %11, align 4, !tbaa !15
  %58 = icmp slt i32 %56, %57
  br i1 %58, label %59, label %102

59:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._SIFT3D_Descriptor_store, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !18
  %63 = load i32, ptr %10, align 4, !tbaa !15
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds %struct._SIFT3D_Descriptor, ptr %62, i64 %64
  store ptr %65, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  %68 = load i32, ptr %10, align 4, !tbaa !15
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i32, ptr %67, i64 %69
  store ptr %70, ptr %14, align 8, !tbaa !5
  %71 = load ptr, ptr %13, align 8, !tbaa !5
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = load float, ptr %8, align 4, !tbaa !9
  %74 = call i32 @match_desc(ptr noundef %71, ptr noundef %72, float noundef %73)
  %75 = load ptr, ptr %14, align 8, !tbaa !5
  store i32 %74, ptr %75, align 4, !tbaa !15
  %76 = load ptr, ptr %14, align 8, !tbaa !5
  %77 = load i32, ptr %76, align 4, !tbaa !15
  %78 = icmp slt i32 %77, 0
  br i1 %78, label %79, label %80

79:                                               ; preds = %59
  store i32 7, ptr %12, align 4
  br label %96

80:                                               ; preds = %59
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct._SIFT3D_Descriptor_store, ptr %81, i32 0, i32 0
  %83 = load ptr, ptr %82, align 8, !tbaa !18
  %84 = load ptr, ptr %14, align 8, !tbaa !5
  %85 = load i32, ptr %84, align 4, !tbaa !15
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds %struct._SIFT3D_Descriptor, ptr %83, i64 %86
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = load float, ptr %8, align 4, !tbaa !9
  %90 = call i32 @match_desc(ptr noundef %87, ptr noundef %88, float noundef %89)
  %91 = load i32, ptr %10, align 4, !tbaa !15
  %92 = icmp ne i32 %90, %91
  br i1 %92, label %93, label %95

93:                                               ; preds = %80
  %94 = load ptr, ptr %14, align 8, !tbaa !5
  store i32 -1, ptr %94, align 4, !tbaa !15
  br label %95

95:                                               ; preds = %93, %80
  store i32 0, ptr %12, align 4
  br label %96

96:                                               ; preds = %95, %79
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  %97 = load i32, ptr %12, align 4
  switch i32 %97, label %105 [
    i32 0, label %98
    i32 7, label %99
  ]

98:                                               ; preds = %96
  br label %99

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

102:                                              ; preds = %55
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %103

103:                                              ; preds = %102, %34, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %104 = load i32, ptr %5, align 4
  ret i32 %104

105:                                              ; preds = %96
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden i32 @match_desc(ptr noundef, ptr noundef, float noundef) #3

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 "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 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 #4 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"_SIFT3D_Descriptor_store", !6, i64 0, !13, i64 8, !14, i64 16, !14, i64 20, !14, i64 24}
!13 = !{!"long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!14, !14, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!12, !6, i64 0}
!19 = distinct !{!19, !17}


; 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._SIFT3D_Descriptor = type { [64 x %struct._Hist], double, double, double, double }
%struct._Hist = type { [12 x float] }

@stderr = external local_unnamed_addr global ptr, align 8
@.str.15 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [35 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @SIFT3D_nn_match(ptr noundef %0, ptr noundef %1, float noundef %2, ptr nocapture noundef %3) local_unnamed_addr #2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = trunc i64 %6 to i32
  %8 = icmp slt i32 %7, 1
  br i1 %8, label %9, label %12

9:                                                ; preds = %4
  %10 = load ptr, ptr @stderr, align 8, !tbaa !12
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str.15, i32 noundef %7) #4
  br label %.loopexit

12:                                               ; preds = %4
  %13 = load ptr, ptr %3, align 8, !tbaa !12
  %14 = shl i64 %6, 2
  %15 = and i64 %14, 8589934588
  %16 = tail call ptr @SIFT3D_safe_realloc(ptr noundef %13, i64 noundef %15) #5
  store ptr %16, ptr %3, align 8, !tbaa !12
  %17 = icmp eq ptr %16, null
  br i1 %17, label %20, label %.preheader34

.preheader34:                                     ; preds = %12
  %18 = load i64, ptr %5, align 8, !tbaa !5
  %.not38 = icmp eq i64 %18, 0
  br i1 %.not38, label %.lr.ph37.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader34
  %19 = shl nuw i64 %18, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 %16, i8 -1, i64 %19, i1 false), !tbaa !13
  br label %.lr.ph37.preheader

20:                                               ; preds = %12
  %21 = load ptr, ptr @stderr, align 8, !tbaa !12
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str.16) #4
  br label %.loopexit

.lr.ph37.preheader:                               ; preds = %.preheader34, %.lr.ph.preheader
  %wide.trip.count = and i64 %6, 2147483647
  br label %.lr.ph37

.lr.ph37:                                         ; preds = %.lr.ph37.preheader, %36
  %indvars.iv = phi i64 [ 0, %.lr.ph37.preheader ], [ %indvars.iv.next, %36 ]
  %23 = load ptr, ptr %0, align 8, !tbaa !14
  %24 = getelementptr inbounds %struct._SIFT3D_Descriptor, ptr %23, i64 %indvars.iv
  %25 = load ptr, ptr %3, align 8, !tbaa !12
  %26 = getelementptr inbounds i32, ptr %25, i64 %indvars.iv
  %27 = tail call i32 @match_desc(ptr noundef %24, ptr noundef %1, float noundef %2)
  store i32 %27, ptr %26, align 4, !tbaa !13
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %36, label %29

29:                                               ; preds = %.lr.ph37
  %30 = load ptr, ptr %1, align 8, !tbaa !14
  %31 = zext nneg i32 %27 to i64
  %32 = getelementptr inbounds %struct._SIFT3D_Descriptor, ptr %30, i64 %31
  %33 = tail call i32 @match_desc(ptr noundef %32, ptr noundef nonnull %0, float noundef %2)
  %34 = zext i32 %33 to i64
  %.not = icmp eq i64 %indvars.iv, %34
  br i1 %.not, label %36, label %35

35:                                               ; preds = %29
  store i32 -1, ptr %26, align 4, !tbaa !13
  br label %36

36:                                               ; preds = %29, %35, %.lr.ph37
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph37, !llvm.loop !15

.loopexit:                                        ; preds = %36, %20, %9
  %.0 = phi i32 [ -1, %9 ], [ -1, %20 ], [ 0, %36 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @match_desc(ptr noundef, ptr noundef, float noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { cold nounwind }
attributes #5 = { 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, !10, i64 8}
!6 = !{!"_SIFT3D_Descriptor_store", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 20, !11, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!6, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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