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

@.str.11 = external hidden unnamed_addr constant [72 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

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

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

declare i32 @resize_Mat_rm(ptr noundef) #1

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

17:                                               ; preds = %2
  %18 = load i32, ptr %7, align 4, !tbaa !13
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.11, i32 noundef %18)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %90

20:                                               ; preds = %2
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._Mat_rm, ptr %21, i32 0, i32 5
  store i32 0, ptr %22, align 4, !tbaa !14
  %23 = load i32, ptr %7, align 4, !tbaa !13
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._Mat_rm, ptr %24, i32 0, i32 3
  store i32 %23, ptr %25, align 4, !tbaa !16
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._Mat_rm, ptr %26, i32 0, i32 2
  store i32 3, ptr %27, align 8, !tbaa !17
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = call i32 @resize_Mat_rm(ptr noundef %28)
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %20
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %90

32:                                               ; preds = %20
  store i32 0, ptr %6, align 4, !tbaa !13
  br label %33

33:                                               ; preds = %86, %32
  %34 = load i32, ptr %6, align 4, !tbaa !13
  %35 = load i32, ptr %7, align 4, !tbaa !13
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %37, label %89

37:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._SIFT3D_Descriptor_store, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !18
  %41 = load i32, ptr %6, align 4, !tbaa !13
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds %struct._SIFT3D_Descriptor, ptr %40, i64 %42
  store ptr %43, ptr %10, align 8, !tbaa !5
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._SIFT3D_Descriptor, ptr %44, i32 0, i32 1
  %46 = load double, ptr %45, align 8, !tbaa !19
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._Mat_rm, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !22
  %50 = load i32, ptr %6, align 4, !tbaa !13
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._Mat_rm, ptr %51, i32 0, i32 2
  %53 = load i32, ptr %52, align 8, !tbaa !17
  %54 = mul nsw i32 %50, %53
  %55 = add nsw i32 0, %54
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds double, ptr %49, i64 %56
  store double %46, ptr %57, align 8, !tbaa !23
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._SIFT3D_Descriptor, ptr %58, i32 0, i32 2
  %60 = load double, ptr %59, align 8, !tbaa !24
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._Mat_rm, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !22
  %64 = load i32, ptr %6, align 4, !tbaa !13
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._Mat_rm, ptr %65, i32 0, i32 2
  %67 = load i32, ptr %66, align 8, !tbaa !17
  %68 = mul nsw i32 %64, %67
  %69 = add nsw i32 1, %68
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds double, ptr %63, i64 %70
  store double %60, ptr %71, align 8, !tbaa !23
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct._SIFT3D_Descriptor, ptr %72, i32 0, i32 3
  %74 = load double, ptr %73, align 8, !tbaa !25
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._Mat_rm, ptr %75, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !22
  %78 = load i32, ptr %6, align 4, !tbaa !13
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct._Mat_rm, ptr %79, i32 0, i32 2
  %81 = load i32, ptr %80, align 8, !tbaa !17
  %82 = mul nsw i32 %78, %81
  %83 = add nsw i32 2, %82
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds double, ptr %77, i64 %84
  store double %74, ptr %85, align 8, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %86

86:                                               ; preds = %37
  %87 = load i32, ptr %6, align 4, !tbaa !13
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %6, align 4, !tbaa !13
  br label %33, !llvm.loop !26

89:                                               ; preds = %33
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %90

90:                                               ; preds = %89, %31, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %91 = load i32, ptr %3, align 4
  ret i32 %91
}

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 8}
!10 = !{!"_SIFT3D_Descriptor_store", !6, i64 0, !11, i64 8, !12, i64 16, !12, i64 20, !12, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!15, !12, i64 28}
!15 = !{!"_Mat_rm", !7, i64 0, !11, i64 8, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28}
!16 = !{!15, !12, i64 20}
!17 = !{!15, !12, i64 16}
!18 = !{!10, !6, i64 0}
!19 = !{!20, !21, i64 3072}
!20 = !{!"_SIFT3D_Descriptor", !7, i64 0, !21, i64 3072, !21, i64 3080, !21, i64 3088, !21, i64 3096}
!21 = !{!"double", !7, i64 0}
!22 = !{!7, !7, i64 0}
!23 = !{!21, !21, i64 0}
!24 = !{!20, !21, i64 3080}
!25 = !{!20, !21, i64 3088}
!26 = distinct !{!26, !27}
!27 = !{!"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._SIFT3D_Descriptor = type { [64 x %struct._Hist], double, double, double, double }
%struct._Hist = type { [12 x float] }

@.str.11 = external hidden unnamed_addr constant [72 x i8], align 1

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

declare i32 @resize_Mat_rm(ptr noundef) local_unnamed_addr #1

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

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

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %1, i64 28
  store i32 0, ptr %10, align 4, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %1, i64 20
  store i32 %5, ptr %11, align 4, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %1, i64 16
  store i32 3, ptr %12, align 8, !tbaa !15
  %13 = tail call i32 @resize_Mat_rm(ptr noundef %1) #3
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %9
  %14 = load ptr, ptr %0, align 8, !tbaa !16
  %15 = load i32, ptr %12, align 8, !tbaa !15
  %16 = sext i32 %15 to i64
  %wide.trip.count = and i64 %4, 2147483647
  %xtraiter = and i64 %4, 1
  %17 = icmp eq i64 %wide.trip.count, 1
  br i1 %17, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = sub nsw i64 %wide.trip.count, %xtraiter
  br label %18

18:                                               ; preds = %18, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %18 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %18 ]
  %19 = getelementptr inbounds %struct._SIFT3D_Descriptor, ptr %14, i64 %indvars.iv
  %20 = getelementptr inbounds i8, ptr %19, i64 3072
  %21 = load double, ptr %20, align 8, !tbaa !17
  %22 = load ptr, ptr %1, align 8, !tbaa !20
  %23 = mul nsw i64 %indvars.iv, %16
  %24 = getelementptr inbounds double, ptr %22, i64 %23
  store double %21, ptr %24, align 8, !tbaa !21
  %25 = getelementptr inbounds i8, ptr %19, i64 3080
  %26 = load double, ptr %25, align 8, !tbaa !22
  %27 = load ptr, ptr %1, align 8, !tbaa !20
  %28 = getelementptr double, ptr %27, i64 %23
  %29 = getelementptr i8, ptr %28, i64 8
  store double %26, ptr %29, align 8, !tbaa !21
  %30 = getelementptr inbounds i8, ptr %19, i64 3088
  %31 = load double, ptr %30, align 8, !tbaa !23
  %32 = load ptr, ptr %1, align 8, !tbaa !20
  %33 = getelementptr double, ptr %32, i64 %23
  %34 = getelementptr i8, ptr %33, i64 16
  store double %31, ptr %34, align 8, !tbaa !21
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %35 = getelementptr inbounds %struct._SIFT3D_Descriptor, ptr %14, i64 %indvars.iv.next
  %36 = getelementptr inbounds i8, ptr %35, i64 3072
  %37 = load double, ptr %36, align 8, !tbaa !17
  %38 = load ptr, ptr %1, align 8, !tbaa !20
  %39 = mul nsw i64 %indvars.iv.next, %16
  %40 = getelementptr inbounds double, ptr %38, i64 %39
  store double %37, ptr %40, align 8, !tbaa !21
  %41 = getelementptr inbounds i8, ptr %35, i64 3080
  %42 = load double, ptr %41, align 8, !tbaa !22
  %43 = load ptr, ptr %1, align 8, !tbaa !20
  %44 = getelementptr double, ptr %43, i64 %39
  %45 = getelementptr i8, ptr %44, i64 8
  store double %42, ptr %45, align 8, !tbaa !21
  %46 = getelementptr inbounds i8, ptr %35, i64 3088
  %47 = load double, ptr %46, align 8, !tbaa !23
  %48 = load ptr, ptr %1, align 8, !tbaa !20
  %49 = getelementptr double, ptr %48, i64 %39
  %50 = getelementptr i8, ptr %49, i64 16
  store double %47, ptr %50, align 8, !tbaa !21
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %18, !llvm.loop !24

.loopexit.loopexit.unr-lcssa:                     ; preds = %18, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %18 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.loopexit.loopexit.epilog-lcssa

.loopexit.loopexit.epilog-lcssa:                  ; preds = %.loopexit.loopexit.unr-lcssa
  %51 = getelementptr inbounds %struct._SIFT3D_Descriptor, ptr %14, i64 %indvars.iv.unr
  %52 = getelementptr inbounds i8, ptr %51, i64 3072
  %53 = load double, ptr %52, align 8, !tbaa !17
  %54 = load ptr, ptr %1, align 8, !tbaa !20
  %55 = mul nsw i64 %indvars.iv.unr, %16
  %56 = getelementptr inbounds double, ptr %54, i64 %55
  store double %53, ptr %56, align 8, !tbaa !21
  %57 = getelementptr inbounds i8, ptr %51, i64 3080
  %58 = load double, ptr %57, align 8, !tbaa !22
  %59 = load ptr, ptr %1, align 8, !tbaa !20
  %60 = getelementptr double, ptr %59, i64 %55
  %61 = getelementptr i8, ptr %60, i64 8
  store double %58, ptr %61, align 8, !tbaa !21
  %62 = getelementptr inbounds i8, ptr %51, i64 3088
  %63 = load double, ptr %62, align 8, !tbaa !23
  %64 = load ptr, ptr %1, align 8, !tbaa !20
  %65 = getelementptr double, ptr %64, i64 %55
  %66 = getelementptr i8, ptr %65, i64 16
  store double %63, ptr %66, align 8, !tbaa !21
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.epilog-lcssa, %.loopexit.loopexit.unr-lcssa, %9, %7
  %.0 = phi i32 [ -1, %7 ], [ -1, %9 ], [ 0, %.loopexit.loopexit.unr-lcssa ], [ 0, %.loopexit.loopexit.epilog-lcssa ]
  ret i32 %.0
}

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 = { "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, !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 = !{!13, !11, i64 28}
!13 = !{!"_Mat_rm", !8, i64 0, !10, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}
!14 = !{!13, !11, i64 20}
!15 = !{!13, !11, i64 16}
!16 = !{!6, !7, i64 0}
!17 = !{!18, !19, i64 3072}
!18 = !{!"_SIFT3D_Descriptor", !8, i64 0, !19, i64 3072, !19, i64 3080, !19, i64 3088, !19, i64 3096}
!19 = !{!"double", !8, i64 0}
!20 = !{!8, !8, i64 0}
!21 = !{!19, !19, i64 0}
!22 = !{!18, !19, i64 3080}
!23 = !{!18, !19, i64 3088}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


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