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

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

declare void @_ZN11lichtenberg10CellList2D10set_brokenEii(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef) #0

declare void @_ZN11lichtenberg10CellList2D7set_dirEiiNS_9DirectionE(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11lichtenberg9Simulator13insulate_cellEii(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %7 = load ptr, ptr %4, align 8
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = icmp slt i32 %8, 0
  br i1 %9, label %25, label %10

10:                                               ; preds = %3
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = getelementptr inbounds %"class.lichtenberg::Simulator", ptr %7, i32 0, i32 6
  %13 = getelementptr inbounds %"class.lichtenberg::CellList2D", ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = icmp sge i32 %11, %14
  br i1 %15, label %25, label %16

16:                                               ; preds = %10
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = icmp slt i32 %17, 0
  br i1 %18, label %25, label %19

19:                                               ; preds = %16
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = getelementptr inbounds %"class.lichtenberg::Simulator", ptr %7, i32 0, i32 6
  %22 = getelementptr inbounds %"class.lichtenberg::CellList2D", ptr %21, i32 0, i32 2
  %23 = load i32, ptr %22, align 4, !tbaa !20
  %24 = icmp sge i32 %20, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %19, %16, %10, %3
  br label %36

26:                                               ; preds = %19
  %27 = getelementptr inbounds %"class.lichtenberg::Simulator", ptr %7, i32 0, i32 6
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN11lichtenberg10CellList2D13set_insulatedEii(ptr noundef nonnull align 8 dereferenceable(16) %27, i32 noundef %28, i32 noundef %29)
  %30 = getelementptr inbounds %"class.lichtenberg::Simulator", ptr %7, i32 0, i32 6
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN11lichtenberg10CellList2D10set_brokenEii(ptr noundef nonnull align 8 dereferenceable(16) %30, i32 noundef %31, i32 noundef %32)
  %33 = getelementptr inbounds %"class.lichtenberg::Simulator", ptr %7, i32 0, i32 6
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN11lichtenberg10CellList2D7set_dirEiiNS_9DirectionE(ptr noundef nonnull align 8 dereferenceable(16) %33, i32 noundef %34, i32 noundef %35, i32 noundef 0)
  br label %36

36:                                               ; preds = %26, %25
  ret void
}

declare void @_ZN11lichtenberg10CellList2D13set_insulatedEii(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef) #0

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

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

declare void @_ZN11lichtenberg10CellList2D10set_brokenEii(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef) local_unnamed_addr #0

declare void @_ZN11lichtenberg10CellList2D7set_dirEiiNS_9DirectionE(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11lichtenberg9Simulator13insulate_cellEii(ptr noundef nonnull align 8 dereferenceable(72) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = icmp slt i32 %1, 0
  br i1 %4, label %14, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 64
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = icmp sgt i32 %7, %1
  %9 = icmp sgt i32 %2, -1
  %or.cond.not16 = and i1 %9, %8
  %10 = getelementptr inbounds i8, ptr %0, i64 68
  %11 = load i32, ptr %10, align 4
  %.not = icmp sgt i32 %11, %2
  %or.cond13 = select i1 %or.cond.not16, i1 %.not, i1 false
  br i1 %or.cond13, label %12, label %14

12:                                               ; preds = %5
  %13 = getelementptr inbounds i8, ptr %0, i64 56
  tail call void @_ZN11lichtenberg10CellList2D13set_insulatedEii(ptr noundef nonnull align 8 dereferenceable(16) %13, i32 noundef %1, i32 noundef %2)
  tail call void @_ZN11lichtenberg10CellList2D10set_brokenEii(ptr noundef nonnull align 8 dereferenceable(16) %13, i32 noundef %1, i32 noundef %2)
  tail call void @_ZN11lichtenberg10CellList2D7set_dirEiiNS_9DirectionE(ptr noundef nonnull align 8 dereferenceable(16) %13, i32 noundef %1, i32 noundef %2, i32 noundef 0)
  br label %14

14:                                               ; preds = %3, %5, %12
  ret void
}

declare void @_ZN11lichtenberg10CellList2D13set_insulatedEii(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef, i32 noundef) local_unnamed_addr #0

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

!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}


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