; LLVM IR from robinrodricks/InspiritImage :: Inspirit.Assurf/clib (lkpyramid)

; 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._CvSize = type { i32, i32 }

@pyrPatchBuffer = external dso_local global ptr, align 8
@step = external dso_local global ptr, align 8
@scale = external dso_local global ptr, align 8
@size = external dso_local global ptr, align 8
@patchI = external dso_local global ptr, align 8
@patchJ = external dso_local global ptr, align 8
@Ix = external dso_local global ptr, align 8
@Iy = external dso_local global ptr, align 8

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(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 void @free(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @initOpticalFlow(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4, i32 noundef %5) #3 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  store i32 %5, ptr %12, align 4, !tbaa !9
  %20 = load ptr, ptr @step, align 8, !tbaa !5
  call void @free(ptr noundef %20) #4
  %21 = load ptr, ptr @scale, align 8, !tbaa !5
  call void @free(ptr noundef %21) #4
  %22 = load ptr, ptr @size, align 8, !tbaa !5
  call void @free(ptr noundef %22) #4
  %23 = load ptr, ptr @pyrPatchBuffer, align 8, !tbaa !5
  call void @free(ptr noundef %23) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 3, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %24 = load i32, ptr %13, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = mul i64 %25, 4
  %27 = call noalias ptr @malloc(i64 noundef %26) #5
  store ptr %27, ptr @step, align 8, !tbaa !5
  %28 = load i32, ptr %13, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = mul i64 %29, 8
  %31 = call noalias ptr @malloc(i64 noundef %30) #5
  store ptr %31, ptr @scale, align 8, !tbaa !5
  %32 = load i32, ptr %13, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = mul i64 %33, 8
  %35 = call noalias ptr @malloc(i64 noundef %34) #5
  store ptr %35, ptr @size, align 8, !tbaa !5
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %76, %6
  %37 = load i32, ptr %15, align 4, !tbaa !9
  %38 = load i32, ptr %13, align 4, !tbaa !9
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %40, label %79

40:                                               ; preds = %36
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = load i32, ptr %15, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i32, ptr %41, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = load ptr, ptr @step, align 8, !tbaa !5
  %47 = load i32, ptr %15, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i32, ptr %46, i64 %48
  store i32 %45, ptr %49, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %50 = load ptr, ptr @size, align 8, !tbaa !5
  %51 = load i32, ptr %15, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds %struct._CvSize, ptr %50, i64 %52
  store ptr %53, ptr %16, align 8, !tbaa !5
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = load i32, ptr %15, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i32, ptr %54, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !9
  %59 = load ptr, ptr %16, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._CvSize, ptr %59, i32 0, i32 0
  store i32 %58, ptr %60, align 4, !tbaa !11
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = load i32, ptr %15, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i32, ptr %61, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !9
  %66 = load ptr, ptr %16, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct._CvSize, ptr %66, i32 0, i32 1
  store i32 %65, ptr %67, align 4, !tbaa !13
  %68 = load i32, ptr %15, align 4, !tbaa !9
  %69 = shl i32 1, %68
  %70 = sitofp i32 %69 to double
  %71 = fdiv double 1.000000e+00, %70
  %72 = load ptr, ptr @scale, align 8, !tbaa !5
  %73 = load i32, ptr %15, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds double, ptr %72, i64 %74
  store double %71, ptr %75, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  br label %76

76:                                               ; preds = %40
  %77 = load i32, ptr %15, align 4, !tbaa !9
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %15, align 4, !tbaa !9
  br label %36, !llvm.loop !16

79:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  %80 = load i32, ptr %11, align 4, !tbaa !9
  %81 = mul nsw i32 %80, 2
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  %83 = load i32, ptr %17, align 4, !tbaa !9
  %84 = load i32, ptr %17, align 4, !tbaa !9
  %85 = mul nsw i32 %83, %84
  store i32 %85, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #4
  %86 = load i32, ptr %17, align 4, !tbaa !9
  %87 = add nsw i32 %86, 2
  %88 = load i32, ptr %17, align 4, !tbaa !9
  %89 = add nsw i32 %88, 2
  %90 = mul nsw i32 %87, %89
  store i32 %90, ptr %19, align 4, !tbaa !9
  %91 = load i32, ptr %19, align 4, !tbaa !9
  %92 = load i32, ptr %18, align 4, !tbaa !9
  %93 = mul nsw i32 %92, 3
  %94 = add nsw i32 %91, %93
  %95 = sext i32 %94 to i64
  %96 = mul i64 %95, 8
  %97 = trunc i64 %96 to i32
  store i32 %97, ptr %14, align 4, !tbaa !9
  %98 = load i32, ptr %14, align 4, !tbaa !9
  %99 = sext i32 %98 to i64
  %100 = call noalias ptr @malloc(i64 noundef %99) #5
  store ptr %100, ptr @pyrPatchBuffer, align 8, !tbaa !5
  %101 = load ptr, ptr @pyrPatchBuffer, align 8, !tbaa !5
  store ptr %101, ptr @patchI, align 8, !tbaa !5
  %102 = load ptr, ptr @patchI, align 8, !tbaa !5
  %103 = load i32, ptr %19, align 4, !tbaa !9
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds double, ptr %102, i64 %104
  store ptr %105, ptr @patchJ, align 8, !tbaa !5
  %106 = load ptr, ptr @patchJ, align 8, !tbaa !5
  %107 = load i32, ptr %18, align 4, !tbaa !9
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds double, ptr %106, i64 %108
  store ptr %109, ptr @Ix, align 8, !tbaa !5
  %110 = load ptr, ptr @Ix, align 8, !tbaa !5
  %111 = load i32, ptr %18, align 4, !tbaa !9
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds double, ptr %110, i64 %112
  store ptr %113, ptr @Iy, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 "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 }
attributes #5 = { nounwind allocsize(0) }

!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 0}
!12 = !{!"_CvSize", !10, i64 0, !10, i64 4}
!13 = !{!12, !10, i64 4}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@pyrPatchBuffer = external dso_local local_unnamed_addr global ptr, align 8
@step = external dso_local local_unnamed_addr global ptr, align 8
@scale = external dso_local local_unnamed_addr global ptr, align 8
@size = external dso_local local_unnamed_addr global ptr, align 8
@patchI = external dso_local local_unnamed_addr global ptr, align 8
@patchJ = external dso_local local_unnamed_addr global ptr, align 8
@Ix = external dso_local local_unnamed_addr global ptr, align 8
@Iy = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn uwtable
define dso_local void @initOpticalFlow(ptr nocapture noundef readnone %0, ptr nocapture noundef readnone %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #2 {
  %7 = load ptr, ptr @step, align 8, !tbaa !5
  tail call void @free(ptr noundef %7) #4
  %8 = load ptr, ptr @scale, align 8, !tbaa !5
  tail call void @free(ptr noundef %8) #4
  %9 = load ptr, ptr @size, align 8, !tbaa !5
  tail call void @free(ptr noundef %9) #4
  %10 = load ptr, ptr @pyrPatchBuffer, align 8, !tbaa !5
  tail call void @free(ptr noundef %10) #4
  %11 = tail call noalias dereferenceable_or_null(12) ptr @malloc(i64 noundef 12) #5
  store ptr %11, ptr @step, align 8, !tbaa !5
  %12 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #5
  store ptr %12, ptr @scale, align 8, !tbaa !5
  %13 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #5
  store ptr %13, ptr @size, align 8, !tbaa !5
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %11, ptr noundef nonnull align 4 dereferenceable(12) %2, i64 12, i1 false), !tbaa !9
  %14 = load <2 x i32>, ptr %2, align 4, !tbaa !9
  %15 = load <2 x i32>, ptr %3, align 4, !tbaa !9
  %16 = shufflevector <2 x i32> %14, <2 x i32> %15, <4 x i32> <i32 0, i32 2, i32 1, i32 3>
  store <4 x i32> %16, ptr %13, align 4, !tbaa !9
  store <2 x double> <double 1.000000e+00, double 5.000000e-01>, ptr %12, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %2, i64 8
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %13, i64 16
  store i32 %18, ptr %19, align 4, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %3, i64 8
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %13, i64 20
  store i32 %21, ptr %22, align 4, !tbaa !15
  %23 = getelementptr inbounds i8, ptr %12, i64 16
  store double 2.500000e-01, ptr %23, align 8, !tbaa !11
  %24 = shl nsw i32 %4, 1
  %25 = or disjoint i32 %24, 1
  %26 = mul nsw i32 %25, %25
  %27 = add nsw i32 %24, 3
  %28 = mul nsw i32 %27, %27
  %29 = mul nuw nsw i32 %26, 3
  %30 = add nuw nsw i32 %29, %28
  %31 = shl i32 %30, 3
  %32 = sext i32 %31 to i64
  %33 = tail call noalias ptr @malloc(i64 noundef %32) #5
  store ptr %33, ptr @pyrPatchBuffer, align 8, !tbaa !5
  store ptr %33, ptr @patchI, align 8, !tbaa !5
  %34 = zext nneg i32 %28 to i64
  %35 = getelementptr inbounds double, ptr %33, i64 %34
  store ptr %35, ptr @patchJ, align 8, !tbaa !5
  %36 = zext nneg i32 %26 to i64
  %37 = getelementptr inbounds double, ptr %35, i64 %36
  store ptr %37, ptr @Ix, align 8, !tbaa !5
  %38 = getelementptr inbounds double, ptr %37, i64 %36
  store ptr %38, ptr @Iy, align 8, !tbaa !5
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nounwind willreturn 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: readwrite) }
attributes #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_CvSize", !10, i64 0, !10, i64 4}
!15 = !{!14, !10, i64 4}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass