; LLVM IR from yuikns/panther :: ann/ann2fig/ann2fig.ll (Z7overlapRK11ANNorthRect)

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

%class.ANNorthRect = type { ptr, ptr }

@dim_x = external dso_local global i32, align 4
@dim_y = external dso_local global i32, align 4
@slice_val = external dso_local global [1000 x double], align 16
@dim = external dso_local global i32, align 4

; 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: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z7overlapRK11ANNorthRect(ptr noundef nonnull align 8 dereferenceable(16) %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %47, %1
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = load i32, ptr @dim, align 4, !tbaa !9
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  store i32 2, ptr %5, align 4
  br label %50

11:                                               ; preds = %6
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = load i32, ptr @dim_x, align 4, !tbaa !9
  %14 = icmp ne i32 %12, %13
  br i1 %14, label %15, label %46

15:                                               ; preds = %11
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = load i32, ptr @dim_y, align 4, !tbaa !9
  %18 = icmp ne i32 %16, %17
  br i1 %18, label %19, label %46

19:                                               ; preds = %15
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %class.ANNorthRect, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds double, ptr %22, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !13
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [1000 x double], ptr @slice_val, i64 0, i64 %28
  %30 = load double, ptr %29, align 8, !tbaa !13
  %31 = fcmp ogt double %26, %30
  br i1 %31, label %45, label %32

32:                                               ; preds = %19
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %class.ANNorthRect, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  %36 = load i32, ptr %4, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds double, ptr %35, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !13
  %40 = load i32, ptr %4, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1000 x double], ptr @slice_val, i64 0, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !13
  %44 = fcmp olt double %39, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %32, %19
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %50

46:                                               ; preds = %32, %15, %11
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %4, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %4, align 4, !tbaa !9
  br label %6, !llvm.loop !16

50:                                               ; preds = %45, %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %51 = load i32, ptr %5, align 4
  switch i32 %51, label %55 [
    i32 2, label %52
    i32 1, label %53
  ]

52:                                               ; preds = %50
  store i32 1, ptr %2, align 4
  br label %53

53:                                               ; preds = %52, %50
  %54 = load i32, ptr %2, align 4
  ret i32 %54

55:                                               ; preds = %50
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS11ANNorthRect", !6, i64 0, !6, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!12, !6, i64 8}
!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"

@dim_x = external dso_local local_unnamed_addr global i32, align 4
@dim_y = external dso_local local_unnamed_addr global i32, align 4
@slice_val = external dso_local local_unnamed_addr global [1000 x double], align 16
@dim = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef range(i32 0, 2) i32 @_Z7overlapRK11ANNorthRect(ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @dim, align 4, !tbaa !5
  %.not1516 = icmp slt i32 %2, 1
  br i1 %.not1516, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr @dim_x, align 4, !tbaa !5
  %5 = load i32, ptr @dim_y, align 4
  %6 = load ptr, ptr %0, align 8
  %7 = load ptr, ptr %3, align 8
  %8 = zext i32 %5 to i64
  %9 = zext i32 %4 to i64
  %10 = zext nneg i32 %2 to i64
  %wide.trip.count = zext nneg i32 %2 to i64
  br label %11

11:                                               ; preds = %.lr.ph, %22
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %22 ]
  %.not1518 = phi i1 [ false, %.lr.ph ], [ %.not15, %22 ]
  %.not = icmp eq i64 %indvars.iv, %9
  %.not14 = icmp eq i64 %indvars.iv, %8
  %or.cond = select i1 %.not, i1 true, i1 %.not14
  br i1 %or.cond, label %22, label %12

12:                                               ; preds = %11
  %13 = getelementptr inbounds double, ptr %6, i64 %indvars.iv
  %14 = load double, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds [1000 x double], ptr @slice_val, i64 0, i64 %indvars.iv
  %16 = load double, ptr %15, align 8, !tbaa !9
  %17 = fcmp ogt double %14, %16
  br i1 %17, label %._crit_edge.loopexit, label %18

18:                                               ; preds = %12
  %19 = getelementptr inbounds double, ptr %7, i64 %indvars.iv
  %20 = load double, ptr %19, align 8, !tbaa !9
  %21 = fcmp olt double %20, %16
  br i1 %21, label %._crit_edge.loopexit, label %22

22:                                               ; preds = %11, %18
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.not15 = icmp uge i64 %indvars.iv.next, %10
  %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond, label %._crit_edge.loopexit, label %11, !llvm.loop !11

._crit_edge.loopexit:                             ; preds = %12, %18, %22
  %.not15.lcssa.ph = phi i1 [ %.not15, %22 ], [ %.not1518, %18 ], [ %.not1518, %12 ]
  %23 = zext i1 %.not15.lcssa.ph to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.not15.lcssa = phi i32 [ 1, %1 ], [ %23, %._crit_edge.loopexit ]
  ret i32 %.not15.lcssa
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass