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

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

@spCannyWorkspace = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @init_canny(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %5 = load ptr, ptr @spCannyWorkspace, align 8, !tbaa !9
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %11

7:                                                ; preds = %2
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = call ptr @create_workspace_canny(i32 noundef %8, i32 noundef %9)
  store ptr %10, ptr @spCannyWorkspace, align 8, !tbaa !9
  br label %29

11:                                               ; preds = %2
  %12 = load ptr, ptr @spCannyWorkspace, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.SCannyWorkspace, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp ne i32 %14, %15
  br i1 %16, label %23, label %17

17:                                               ; preds = %11
  %18 = load ptr, ptr @spCannyWorkspace, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.SCannyWorkspace, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = icmp ne i32 %20, %21
  br i1 %22, label %23, label %28

23:                                               ; preds = %17, %11
  %24 = load ptr, ptr @spCannyWorkspace, align 8, !tbaa !9
  call void @release_workspace_canny(ptr noundef %24)
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = call ptr @create_workspace_canny(i32 noundef %25, i32 noundef %26)
  store ptr %27, ptr @spCannyWorkspace, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %23, %17
  br label %29

29:                                               ; preds = %28, %7
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @create_workspace_canny(i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @release_workspace_canny(ptr noundef) #0

attributes #0 = { 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" }

!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 = !{!12, !6, i64 0}
!12 = !{!"SCannyWorkspace", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!13 = !{!12, !6, i64 4}


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

@spCannyWorkspace = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @init_canny(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @spCannyWorkspace, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %.sink.split, label %5

5:                                                ; preds = %2
  %6 = load i32, ptr %3, align 8, !tbaa !9
  %.not = icmp eq i32 %6, %0
  br i1 %.not, label %7, label %10

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %3, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !12
  %.not6 = icmp eq i32 %9, %1
  br i1 %.not6, label %12, label %10

10:                                               ; preds = %7, %5
  tail call void @release_workspace_canny(ptr noundef nonnull %3)
  br label %.sink.split

.sink.split:                                      ; preds = %2, %10
  %11 = tail call ptr @create_workspace_canny(i32 noundef %0, i32 noundef %1)
  store ptr %11, ptr @spCannyWorkspace, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %.sink.split, %7
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @create_workspace_canny(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @release_workspace_canny(ptr noundef) local_unnamed_addr #0

attributes #0 = { 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" }

!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 0}
!10 = !{!"SCannyWorkspace", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass