; LLVM IR from casensiom/fast-image-processing :: src (hough)

; 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.SHoughWorkspace = type { i32, i32, double, i32, i32, ptr, i32, i32, ptr, i32, ptr, ptr }
%struct.SCollisionPoint = type { i32, i32 }

; 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

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

19:                                               ; preds = %89, %3
  %20 = load i32, ptr %10, align 4, !tbaa !5
  %21 = load i32, ptr %9, align 4, !tbaa !5
  %22 = icmp ult i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 2, ptr %11, align 4
  br label %92

24:                                               ; preds = %19
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = load ptr, ptr %8, align 8, !tbaa !9
  %27 = load i32, ptr %10, align 4, !tbaa !5
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds %struct.SCollisionPoint, ptr %26, i64 %28
  %30 = getelementptr inbounds %struct.SCollisionPoint, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !16
  %32 = icmp ugt i32 %25, %31
  br i1 %32, label %51, label %33

33:                                               ; preds = %24
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = load ptr, ptr %8, align 8, !tbaa !9
  %36 = load i32, ptr %10, align 4, !tbaa !5
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds %struct.SCollisionPoint, ptr %35, i64 %37
  %39 = getelementptr inbounds %struct.SCollisionPoint, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !16
  %41 = icmp eq i32 %34, %40
  br i1 %41, label %42, label %88

42:                                               ; preds = %33
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = load ptr, ptr %8, align 8, !tbaa !9
  %45 = load i32, ptr %10, align 4, !tbaa !5
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds %struct.SCollisionPoint, ptr %44, i64 %46
  %48 = getelementptr inbounds %struct.SCollisionPoint, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 4, !tbaa !18
  %50 = icmp ult i32 %43, %49
  br i1 %50, label %51, label %88

51:                                               ; preds = %42, %24
  store i8 1, ptr %7, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %52 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %52, ptr %12, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %68, %51
  %54 = load i32, ptr %12, align 4, !tbaa !5
  %55 = load i32, ptr %10, align 4, !tbaa !5
  %56 = icmp ugt i32 %54, %55
  br i1 %56, label %58, label %57

57:                                               ; preds = %53
  store i32 5, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %71

58:                                               ; preds = %53
  %59 = load ptr, ptr %8, align 8, !tbaa !9
  %60 = load i32, ptr %12, align 4, !tbaa !5
  %61 = zext i32 %60 to i64
  %62 = getelementptr inbounds %struct.SCollisionPoint, ptr %59, i64 %61
  %63 = load ptr, ptr %8, align 8, !tbaa !9
  %64 = load i32, ptr %12, align 4, !tbaa !5
  %65 = sub i32 %64, 1
  %66 = zext i32 %65 to i64
  %67 = getelementptr inbounds %struct.SCollisionPoint, ptr %63, i64 %66
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %62, ptr align 4 %67, i64 8, i1 false), !tbaa.struct !19
  br label %68

68:                                               ; preds = %58
  %69 = load i32, ptr %12, align 4, !tbaa !5
  %70 = add i32 %69, -1
  store i32 %70, ptr %12, align 4, !tbaa !5
  br label %53, !llvm.loop !20

71:                                               ; preds = %57
  %72 = load ptr, ptr %6, align 8, !tbaa !9
  %73 = getelementptr inbounds %struct.SHoughWorkspace, ptr %72, i32 0, i32 9
  %74 = load i32, ptr %73, align 8, !tbaa !15
  %75 = add i32 %74, 1
  store i32 %75, ptr %73, align 8, !tbaa !15
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = load ptr, ptr %8, align 8, !tbaa !9
  %78 = load i32, ptr %10, align 4, !tbaa !5
  %79 = zext i32 %78 to i64
  %80 = getelementptr inbounds %struct.SCollisionPoint, ptr %77, i64 %79
  %81 = getelementptr inbounds %struct.SCollisionPoint, ptr %80, i32 0, i32 1
  store i32 %76, ptr %81, align 4, !tbaa !16
  %82 = load i32, ptr %4, align 4, !tbaa !5
  %83 = load ptr, ptr %8, align 8, !tbaa !9
  %84 = load i32, ptr %10, align 4, !tbaa !5
  %85 = zext i32 %84 to i64
  %86 = getelementptr inbounds %struct.SCollisionPoint, ptr %83, i64 %85
  %87 = getelementptr inbounds %struct.SCollisionPoint, ptr %86, i32 0, i32 0
  store i32 %82, ptr %87, align 4, !tbaa !18
  store i32 2, ptr %11, align 4
  br label %92

88:                                               ; preds = %42, %33
  br label %89

89:                                               ; preds = %88
  %90 = load i32, ptr %10, align 4, !tbaa !5
  %91 = add i32 %90, 1
  store i32 %91, ptr %10, align 4, !tbaa !5
  br label %19, !llvm.loop !22

92:                                               ; preds = %71, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %93

93:                                               ; preds = %92
  %94 = load i8, ptr %7, align 1, !tbaa !11
  %95 = zext i8 %94 to i32
  %96 = icmp eq i32 %95, 0
  br i1 %96, label %97, label %114

97:                                               ; preds = %93
  %98 = load i32, ptr %5, align 4, !tbaa !5
  %99 = load ptr, ptr %8, align 8, !tbaa !9
  %100 = load i32, ptr %9, align 4, !tbaa !5
  %101 = zext i32 %100 to i64
  %102 = getelementptr inbounds %struct.SCollisionPoint, ptr %99, i64 %101
  %103 = getelementptr inbounds %struct.SCollisionPoint, ptr %102, i32 0, i32 1
  store i32 %98, ptr %103, align 4, !tbaa !16
  %104 = load i32, ptr %4, align 4, !tbaa !5
  %105 = load ptr, ptr %8, align 8, !tbaa !9
  %106 = load i32, ptr %9, align 4, !tbaa !5
  %107 = zext i32 %106 to i64
  %108 = getelementptr inbounds %struct.SCollisionPoint, ptr %105, i64 %107
  %109 = getelementptr inbounds %struct.SCollisionPoint, ptr %108, i32 0, i32 0
  store i32 %104, ptr %109, align 4, !tbaa !18
  %110 = load ptr, ptr %6, align 8, !tbaa !9
  %111 = getelementptr inbounds %struct.SHoughWorkspace, ptr %110, i32 0, i32 9
  %112 = load i32, ptr %111, align 8, !tbaa !15
  %113 = add i32 %112, 1
  store i32 %113, ptr %111, align 8, !tbaa !15
  br label %114

114:                                              ; preds = %97, %93
  %115 = load i8, ptr %7, align 1, !tbaa !11
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  ret i8 %115
}

; 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) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 40}
!13 = !{!"SHoughWorkspace", !6, i64 0, !6, i64 4, !14, i64 8, !6, i64 16, !6, i64 20, !10, i64 24, !6, i64 32, !6, i64 36, !10, i64 40, !6, i64 48, !10, i64 56, !10, i64 64}
!14 = !{!"double", !7, i64 0}
!15 = !{!13, !6, i64 48}
!16 = !{!17, !6, i64 4}
!17 = !{!"SCollisionPoint", !6, i64 0, !6, i64 4}
!18 = !{!17, !6, i64 0}
!19 = !{i64 0, i64 4, !5, i64 4, i64 4, !5}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


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

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local zeroext range(i8 0, 2) i8 @insert_sort(i32 noundef %0, i32 noundef %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %2, i64 40
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %2, i64 48
  %7 = load i32, ptr %6, align 8, !tbaa !12
  %.not48.not = icmp eq i32 %7, 0
  br i1 %.not48.not, label %.thread, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %wide.trip.count = zext i32 %7 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %34
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %34 ]
  %8 = getelementptr inbounds %struct.SCollisionPoint, ptr %5, i64 %indvars.iv
  %9 = getelementptr inbounds i8, ptr %8, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !13
  %11 = icmp ult i32 %10, %1
  br i1 %11, label %17, label %12

12:                                               ; preds = %.lr.ph
  %13 = icmp eq i32 %10, %1
  br i1 %13, label %14, label %34

14:                                               ; preds = %12
  %15 = load i32, ptr %8, align 4, !tbaa !15
  %16 = icmp ugt i32 %15, %0
  br i1 %16, label %17, label %34

17:                                               ; preds = %14, %.lr.ph
  %18 = getelementptr inbounds i8, ptr %8, i64 4
  %19 = trunc nuw i64 %indvars.iv to i32
  %20 = icmp ugt i32 %7, %19
  br i1 %20, label %.lr.ph51.preheader, label %._crit_edge

.lr.ph51.preheader:                               ; preds = %17
  %21 = and i64 %indvars.iv, 4294967295
  %22 = sub nsw i64 %wide.trip.count, %indvars.iv
  %min.iters.check = icmp ult i64 %22, 4
  br i1 %min.iters.check, label %.lr.ph51.preheader78, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph51.preheader
  %n.vec = and i64 %22, -4
  %ind.end = sub i64 %wide.trip.count, %n.vec
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = sub i64 %wide.trip.count, %index
  %23 = getelementptr inbounds %struct.SCollisionPoint, ptr %5, i64 %offset.idx
  %24 = getelementptr %struct.SCollisionPoint, ptr %5, i64 %offset.idx
  %25 = getelementptr i8, ptr %24, i64 -16
  %26 = getelementptr i8, ptr %24, i64 -32
  %wide.load = load <2 x i64>, ptr %25, align 4
  %wide.load74 = load <2 x i64>, ptr %26, align 4
  %27 = getelementptr inbounds i8, ptr %23, i64 -8
  %28 = getelementptr inbounds i8, ptr %23, i64 -24
  store <2 x i64> %wide.load, ptr %27, align 4
  store <2 x i64> %wide.load74, ptr %28, align 4
  %index.next = add nuw i64 %index, 4
  %29 = icmp eq i64 %index.next, %n.vec
  br i1 %29, label %middle.block, label %vector.body, !llvm.loop !16

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %22, %n.vec
  br i1 %cmp.n, label %._crit_edge.loopexit, label %.lr.ph51.preheader78

.lr.ph51.preheader78:                             ; preds = %middle.block, %.lr.ph51.preheader
  %indvars.iv59.ph = phi i64 [ %wide.trip.count, %.lr.ph51.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph51

.lr.ph51:                                         ; preds = %.lr.ph51.preheader78, %.lr.ph51
  %indvars.iv59 = phi i64 [ %31, %.lr.ph51 ], [ %indvars.iv59.ph, %.lr.ph51.preheader78 ]
  %30 = getelementptr inbounds %struct.SCollisionPoint, ptr %5, i64 %indvars.iv59
  %31 = add nsw i64 %indvars.iv59, -1
  %32 = getelementptr inbounds %struct.SCollisionPoint, ptr %5, i64 %31
  %33 = load i64, ptr %32, align 4
  store i64 %33, ptr %30, align 4
  %.wide = icmp ugt i64 %31, %21
  br i1 %.wide, label %.lr.ph51, label %._crit_edge.loopexit, !llvm.loop !20

34:                                               ; preds = %12, %14
  %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 %.thread, label %.lr.ph, !llvm.loop !21

._crit_edge.loopexit:                             ; preds = %.lr.ph51, %middle.block
  %.pre = load i32, ptr %6, align 8, !tbaa !12
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %17
  %35 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %7, %17 ]
  %36 = add i32 %35, 1
  store i32 %36, ptr %6, align 8, !tbaa !12
  store i32 %1, ptr %18, align 4, !tbaa !13
  store i32 %0, ptr %8, align 4, !tbaa !15
  br label %40

.thread:                                          ; preds = %34, %3
  %.pre-phi = phi i64 [ 0, %3 ], [ %wide.trip.count, %34 ]
  %37 = getelementptr inbounds %struct.SCollisionPoint, ptr %5, i64 %.pre-phi
  %38 = getelementptr inbounds i8, ptr %37, i64 4
  store i32 %1, ptr %38, align 4, !tbaa !13
  store i32 %0, ptr %37, align 4, !tbaa !15
  %39 = add i32 %7, 1
  store i32 %39, ptr %6, align 8, !tbaa !12
  br label %40

40:                                               ; preds = %._crit_edge, %.thread
  %.03844 = phi i8 [ 0, %.thread ], [ 1, %._crit_edge ]
  ret i8 %.03844
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !11, i64 40}
!6 = !{!"SHoughWorkspace", !7, i64 0, !7, i64 4, !10, i64 8, !7, i64 16, !7, i64 20, !11, i64 24, !7, i64 32, !7, i64 36, !11, i64 40, !7, i64 48, !11, i64 56, !11, i64 64}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 48}
!13 = !{!14, !7, i64 4}
!14 = !{!"SCollisionPoint", !7, i64 0, !7, i64 4}
!15 = !{!14, !7, i64 0}
!16 = distinct !{!16, !17, !18, !19}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.isvectorized", i32 1}
!19 = !{!"llvm.loop.unroll.runtime.disable"}
!20 = distinct !{!20, !17, !19, !18}
!21 = distinct !{!21, !17}


; Effective O3 passes: ADCEPass,ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass