; LLVM IR from askforalfred/alfred :: gen/ff_planner (inst_easy)

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

@gnum_types = external global i32, align 4
@gintersected_types = external global [50 x [10 x i32]], align 16
@gnum_intersected_types = external global [50 x i32], align 16

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

9:                                                ; preds = %59, %2
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = load i32, ptr @gnum_types, align 4, !tbaa !9
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %13, label %62

13:                                               ; preds = %9
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [50 x i32], ptr @gnum_intersected_types, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = icmp eq i32 %17, -1
  br i1 %18, label %19, label %20

19:                                               ; preds = %13
  br label %59

20:                                               ; preds = %13
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [50 x i32], ptr @gnum_intersected_types, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = icmp ne i32 %24, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %20
  br label %59

28:                                               ; preds = %20
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %49, %28
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %33, label %52

33:                                               ; preds = %29
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i32, ptr %34, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [50 x [10 x i32]], ptr @gintersected_types, i64 0, i64 %40
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [10 x i32], ptr %41, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = icmp ne i32 %38, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %33
  br label %52

48:                                               ; preds = %33
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %7, align 4, !tbaa !9
  br label %29, !llvm.loop !11

52:                                               ; preds = %47, %29
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = icmp slt i32 %53, %54
  br i1 %55, label %56, label %57

56:                                               ; preds = %52
  br label %59

57:                                               ; preds = %52
  %58 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %58, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %63

59:                                               ; preds = %56, %27, %19
  %60 = load i32, ptr %6, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %6, align 4, !tbaa !9
  br label %9, !llvm.loop !13

62:                                               ; preds = %9
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %63

63:                                               ; preds = %62, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %64 = load i32, ptr %3, align 4
  ret i32 %64
}

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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@gnum_types = external local_unnamed_addr global i32, align 4
@gintersected_types = external local_unnamed_addr global [50 x [10 x i32]], align 16
@gnum_intersected_types = external local_unnamed_addr global [50 x i32], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local i32 @find_intersected_type(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @gnum_types, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph25, label %.critedge

.lr.ph25:                                         ; preds = %2
  %5 = icmp sgt i32 %1, 0
  %wide.trip.count39 = zext nneg i32 %3 to i64
  br i1 %5, label %.lr.ph25.split.us.preheader, label %.lr.ph25.split

.lr.ph25.split.us.preheader:                      ; preds = %.lr.ph25
  %wide.trip.count34 = zext nneg i32 %1 to i64
  br label %.lr.ph25.split.us

.lr.ph25.split.us:                                ; preds = %.lr.ph25.split.us.preheader, %.loopexit.us
  %indvars.iv36 = phi i64 [ 0, %.lr.ph25.split.us.preheader ], [ %indvars.iv.next37, %.loopexit.us ]
  %6 = getelementptr inbounds [50 x i32], ptr @gnum_intersected_types, i64 0, i64 %indvars.iv36
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp ne i32 %7, -1
  %.not.us = icmp eq i32 %7, %1
  %or.cond.us = and i1 %8, %.not.us
  br i1 %or.cond.us, label %.preheader.us, label %.loopexit.us

9:                                                ; preds = %.preheader.us
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %exitcond35.not = icmp eq i64 %indvars.iv.next32, %wide.trip.count34
  br i1 %exitcond35.not, label %.critedge.loopexit, label %.preheader.us, !llvm.loop !9

.preheader.us:                                    ; preds = %.lr.ph25.split.us, %9
  %indvars.iv31 = phi i64 [ %indvars.iv.next32, %9 ], [ 0, %.lr.ph25.split.us ]
  %10 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv31
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = getelementptr inbounds [50 x [10 x i32]], ptr @gintersected_types, i64 0, i64 %indvars.iv36, i64 %indvars.iv31
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %.not19.us = icmp eq i32 %11, %13
  br i1 %.not19.us, label %9, label %.loopexit.us

.loopexit.us:                                     ; preds = %.preheader.us, %.lr.ph25.split.us
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %exitcond40.not = icmp eq i64 %indvars.iv.next37, %wide.trip.count39
  br i1 %exitcond40.not, label %.critedge, label %.lr.ph25.split.us, !llvm.loop !11

.lr.ph25.split:                                   ; preds = %.lr.ph25, %17
  %indvars.iv = phi i64 [ %indvars.iv.next, %17 ], [ 0, %.lr.ph25 ]
  %14 = getelementptr inbounds [50 x i32], ptr @gnum_intersected_types, i64 0, i64 %indvars.iv
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp ne i32 %15, -1
  %.not = icmp eq i32 %15, %1
  %or.cond = and i1 %16, %.not
  br i1 %or.cond, label %.critedge.loopexit42.split.loop.exit, label %17

17:                                               ; preds = %.lr.ph25.split
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count39
  br i1 %exitcond.not, label %.critedge, label %.lr.ph25.split, !llvm.loop !11

.critedge.loopexit:                               ; preds = %9
  %18 = trunc nuw nsw i64 %indvars.iv36 to i32
  br label %.critedge

.critedge.loopexit42.split.loop.exit:             ; preds = %.lr.ph25.split
  %19 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.critedge

.critedge:                                        ; preds = %17, %.loopexit.us, %.critedge.loopexit42.split.loop.exit, %.critedge.loopexit, %2
  %.016 = phi i32 [ -1, %2 ], [ %18, %.critedge.loopexit ], [ %19, %.critedge.loopexit42.split.loop.exit ], [ -1, %.loopexit.us ], [ -1, %17 ]
  ret i32 %.016
}

attributes #0 = { nofree norecurse nosync nounwind 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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass