; LLVM IR from chromia/lichtenberg :: src/simulator.ll (ZN11lichtenberg9Simulator9check_dirEii)

; 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.lichtenberg::Simulator" = type { %"class.std::shared_ptr", i8, i8, i8, i8, %"class.std::function", %"class.lichtenberg::CellList2D" }
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }
%"class.std::function" = type { %"class.std::_Function_base", ptr }
%"class.std::_Function_base" = type { %"union.std::_Any_data", ptr }
%"union.std::_Any_data" = type { %"union.std::_Nocopy_types" }
%"union.std::_Nocopy_types" = type { { i64, i64 } }
%"class.lichtenberg::CellList2D" = type { ptr, i32, i32 }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN11lichtenberg9Simulator9check_dirEii(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %1, i32 noundef %2) #0 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %29

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %17 = getelementptr inbounds %"class.lichtenberg::Simulator", ptr %13, i32 0, i32 6
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = sub nsw i32 %18, 1
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = call noundef i32 @_ZNK11lichtenberg10CellList2D7get_dirEii(ptr noundef nonnull align 8 dereferenceable(16) %17, i32 noundef %19, i32 noundef %20)
  store i32 %21, ptr %8, align 4, !tbaa !11
  %22 = load i32, ptr %8, align 4, !tbaa !11
  %23 = icmp eq i32 %22, 4
  br i1 %23, label %24, label %25

24:                                               ; preds = %16
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %26

25:                                               ; preds = %16
  store i32 0, ptr %9, align 4
  br label %26

26:                                               ; preds = %25, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %27 = load i32, ptr %9, align 4
  switch i32 %27, label %88 [
    i32 0, label %28
    i32 1, label %86
  ]

28:                                               ; preds = %26
  br label %29

29:                                               ; preds = %28, %3
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = getelementptr inbounds %"class.lichtenberg::Simulator", ptr %13, i32 0, i32 6
  %32 = getelementptr inbounds %"class.lichtenberg::CellList2D", ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !13
  %34 = sub nsw i32 %33, 1
  %35 = icmp ne i32 %30, %34
  br i1 %35, label %36, label %49

36:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %37 = getelementptr inbounds %"class.lichtenberg::Simulator", ptr %13, i32 0, i32 6
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = call noundef i32 @_ZNK11lichtenberg10CellList2D7get_dirEii(ptr noundef nonnull align 8 dereferenceable(16) %37, i32 noundef %39, i32 noundef %40)
  store i32 %41, ptr %10, align 4, !tbaa !11
  %42 = load i32, ptr %10, align 4, !tbaa !11
  %43 = icmp eq i32 %42, 2
  br i1 %43, label %44, label %45

44:                                               ; preds = %36
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %46

45:                                               ; preds = %36
  store i32 0, ptr %9, align 4
  br label %46

46:                                               ; preds = %45, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %47 = load i32, ptr %9, align 4
  switch i32 %47, label %88 [
    i32 0, label %48
    i32 1, label %86
  ]

48:                                               ; preds = %46
  br label %49

49:                                               ; preds = %48, %29
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %65

52:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %53 = getelementptr inbounds %"class.lichtenberg::Simulator", ptr %13, i32 0, i32 6
  %54 = load i32, ptr %6, align 4, !tbaa !9
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = sub nsw i32 %55, 1
  %57 = call noundef i32 @_ZNK11lichtenberg10CellList2D7get_dirEii(ptr noundef nonnull align 8 dereferenceable(16) %53, i32 noundef %54, i32 noundef %56)
  store i32 %57, ptr %11, align 4, !tbaa !11
  %58 = load i32, ptr %11, align 4, !tbaa !11
  %59 = icmp eq i32 %58, 3
  br i1 %59, label %60, label %61

60:                                               ; preds = %52
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %62

61:                                               ; preds = %52
  store i32 0, ptr %9, align 4
  br label %62

62:                                               ; preds = %61, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %63 = load i32, ptr %9, align 4
  switch i32 %63, label %88 [
    i32 0, label %64
    i32 1, label %86
  ]

64:                                               ; preds = %62
  br label %65

65:                                               ; preds = %64, %49
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = getelementptr inbounds %"class.lichtenberg::Simulator", ptr %13, i32 0, i32 6
  %68 = getelementptr inbounds %"class.lichtenberg::CellList2D", ptr %67, i32 0, i32 2
  %69 = load i32, ptr %68, align 4, !tbaa !22
  %70 = sub nsw i32 %69, 1
  %71 = icmp ne i32 %66, %70
  br i1 %71, label %72, label %85

72:                                               ; preds = %65
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %73 = getelementptr inbounds %"class.lichtenberg::Simulator", ptr %13, i32 0, i32 6
  %74 = load i32, ptr %6, align 4, !tbaa !9
  %75 = load i32, ptr %7, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  %77 = call noundef i32 @_ZNK11lichtenberg10CellList2D7get_dirEii(ptr noundef nonnull align 8 dereferenceable(16) %73, i32 noundef %74, i32 noundef %76)
  store i32 %77, ptr %12, align 4, !tbaa !11
  %78 = load i32, ptr %12, align 4, !tbaa !11
  %79 = icmp eq i32 %78, 1
  br i1 %79, label %80, label %81

80:                                               ; preds = %72
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %82

81:                                               ; preds = %72
  store i32 0, ptr %9, align 4
  br label %82

82:                                               ; preds = %81, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %83 = load i32, ptr %9, align 4
  switch i32 %83, label %88 [
    i32 0, label %84
    i32 1, label %86
  ]

84:                                               ; preds = %82
  br label %85

85:                                               ; preds = %84, %65
  store i1 false, ptr %4, align 1
  br label %86

86:                                               ; preds = %85, %82, %62, %46, %26
  %87 = load i1, ptr %4, align 1
  ret i1 %87

88:                                               ; preds = %82, %62, %46, %26
  unreachable
}

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

declare noundef i32 @_ZNK11lichtenberg10CellList2D7get_dirEii(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef) #2

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

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

!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, !12, i64 0}
!12 = !{!"_ZTSN11lichtenberg9DirectionE", !7, i64 0}
!13 = !{!14, !10, i64 64}
!14 = !{!"_ZTSN11lichtenberg9SimulatorE", !15, i64 0, !18, i64 16, !18, i64 17, !18, i64 18, !18, i64 19, !19, i64 24, !21, i64 56}
!15 = !{!"_ZTSSt10shared_ptrIN11lichtenberg5model10BreakModelEE", !16, i64 0}
!16 = !{!"_ZTSSt12__shared_ptrIN11lichtenberg5model10BreakModelELN9__gnu_cxx12_Lock_policyE2EE", !6, i64 0, !17, i64 8}
!17 = !{!"_ZTSSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EE", !6, i64 0}
!18 = !{!"bool", !7, i64 0}
!19 = !{!"_ZTSSt8functionIFbiiEE", !20, i64 0, !6, i64 24}
!20 = !{!"_ZTSSt14_Function_base", !7, i64 0, !6, i64 16}
!21 = !{!"_ZTSN11lichtenberg10CellList2DE", !6, i64 0, !10, i64 8, !10, i64 12}
!22 = !{!14, !10, i64 68}


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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN11lichtenberg9Simulator9check_dirEii(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %8, label %4

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 56
  %6 = add nsw i32 %1, -1
  %7 = tail call noundef i32 @_ZNK11lichtenberg10CellList2D7get_dirEii(ptr noundef nonnull align 8 dereferenceable(16) %5, i32 noundef %6, i32 noundef %2)
  %.not36 = icmp eq i32 %7, 4
  br i1 %.not36, label %28, label %8

8:                                                ; preds = %4, %3
  %9 = getelementptr inbounds i8, ptr %0, i64 56
  %10 = getelementptr inbounds i8, ptr %0, i64 64
  %11 = load i32, ptr %10, align 8, !tbaa !5
  %12 = add nsw i32 %11, -1
  %.not27 = icmp eq i32 %12, %1
  br i1 %.not27, label %16, label %13

13:                                               ; preds = %8
  %14 = add nsw i32 %1, 1
  %15 = tail call noundef i32 @_ZNK11lichtenberg10CellList2D7get_dirEii(ptr noundef nonnull align 8 dereferenceable(16) %9, i32 noundef %14, i32 noundef %2)
  %.not37 = icmp eq i32 %15, 2
  br i1 %.not37, label %28, label %16

16:                                               ; preds = %13, %8
  %.not28 = icmp eq i32 %2, 0
  br i1 %.not28, label %20, label %17

17:                                               ; preds = %16
  %18 = add nsw i32 %2, -1
  %19 = tail call noundef i32 @_ZNK11lichtenberg10CellList2D7get_dirEii(ptr noundef nonnull align 8 dereferenceable(16) %9, i32 noundef %1, i32 noundef %18)
  %.not38 = icmp eq i32 %19, 3
  br i1 %.not38, label %28, label %20

20:                                               ; preds = %17, %16
  %21 = getelementptr inbounds i8, ptr %0, i64 68
  %22 = load i32, ptr %21, align 4, !tbaa !18
  %23 = add nsw i32 %22, -1
  %.not29 = icmp eq i32 %23, %2
  br i1 %.not29, label %27, label %24

24:                                               ; preds = %20
  %25 = add nsw i32 %2, 1
  %26 = tail call noundef i32 @_ZNK11lichtenberg10CellList2D7get_dirEii(ptr noundef nonnull align 8 dereferenceable(16) %9, i32 noundef %1, i32 noundef %25)
  %.not39 = icmp eq i32 %26, 1
  br i1 %.not39, label %28, label %27

27:                                               ; preds = %24, %20
  br label %28

28:                                               ; preds = %24, %17, %13, %4, %27
  %.7 = phi i1 [ true, %4 ], [ true, %13 ], [ true, %17 ], [ true, %24 ], [ false, %27 ]
  ret i1 %.7
}

declare noundef i32 @_ZNK11lichtenberg10CellList2D7get_dirEii(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 #1 = { "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, !17, i64 64}
!6 = !{!"_ZTSN11lichtenberg9SimulatorE", !7, i64 0, !13, i64 16, !13, i64 17, !13, i64 18, !13, i64 19, !14, i64 24, !16, i64 56}
!7 = !{!"_ZTSSt10shared_ptrIN11lichtenberg5model10BreakModelEE", !8, i64 0}
!8 = !{!"_ZTSSt12__shared_ptrIN11lichtenberg5model10BreakModelELN9__gnu_cxx12_Lock_policyE2EE", !9, i64 0, !12, i64 8}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"_ZTSSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EE", !9, i64 0}
!13 = !{!"bool", !10, i64 0}
!14 = !{!"_ZTSSt8functionIFbiiEE", !15, i64 0, !9, i64 24}
!15 = !{!"_ZTSSt14_Function_base", !10, i64 0, !9, i64 16}
!16 = !{!"_ZTSN11lichtenberg10CellList2DE", !9, i64 0, !17, i64 8, !17, i64 12}
!17 = !{!"int", !10, i64 0}
!18 = !{!6, !17, i64 68}


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