; LLVM IR from mackorone/mms :: old/v2/src/mouse/mackAlgoTwo (MackAlgoTwo)

; 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.mackAlgoTwo::MackAlgoTwo" = type <{ %class.IMouseAlgorithm, ptr, i8, i8, i8, i8, i8, [3 x i8] }>
%class.IMouseAlgorithm = type { ptr }

@_ZZN11mackAlgoTwo11MackAlgoTwo29resetDestinationCellDistancesEvE11maxDistance = external hidden 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

declare noundef zeroext i8 @_ZN11mackAlgoTwo4Maze7getCellEhh(i8 noundef zeroext, i8 noundef zeroext) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11mackAlgoTwo11MackAlgoTwo15setCellDistanceEhj(ptr noundef nonnull align 8 dereferenceable(21), i8 noundef zeroext, i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11mackAlgoTwo11MackAlgoTwo29resetDestinationCellDistancesEv(ptr noundef nonnull align 8 dereferenceable(21) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  %7 = getelementptr inbounds %"class.mackAlgoTwo::MackAlgoTwo", ptr %6, i32 0, i32 5
  %8 = load i8, ptr %7, align 1, !tbaa !9
  %9 = zext i8 %8 to i32
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %40

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  store i8 7, ptr %3, align 1, !tbaa !12
  br label %12

12:                                               ; preds = %34, %11
  %13 = load i8, ptr %3, align 1, !tbaa !12
  %14 = zext i8 %13 to i32
  %15 = icmp sle i32 %14, 8
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  br label %39

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  store i8 7, ptr %5, align 1, !tbaa !12
  br label %18

18:                                               ; preds = %28, %17
  %19 = load i8, ptr %5, align 1, !tbaa !12
  %20 = zext i8 %19 to i32
  %21 = icmp sle i32 %20, 8
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  br label %33

23:                                               ; preds = %18
  %24 = load i8, ptr %3, align 1, !tbaa !12
  %25 = load i8, ptr %5, align 1, !tbaa !12
  %26 = call noundef zeroext i8 @_ZN11mackAlgoTwo4Maze7getCellEhh(i8 noundef zeroext %24, i8 noundef zeroext %25)
  %27 = load i32, ptr @_ZZN11mackAlgoTwo11MackAlgoTwo29resetDestinationCellDistancesEvE11maxDistance, align 4, !tbaa !13
  call void @_ZN11mackAlgoTwo11MackAlgoTwo15setCellDistanceEhj(ptr noundef nonnull align 8 dereferenceable(21) %6, i8 noundef zeroext %26, i32 noundef %27)
  br label %28

28:                                               ; preds = %23
  %29 = load i8, ptr %5, align 1, !tbaa !12
  %30 = zext i8 %29 to i32
  %31 = add nsw i32 %30, 1
  %32 = trunc i32 %31 to i8
  store i8 %32, ptr %5, align 1, !tbaa !12
  br label %18, !llvm.loop !15

33:                                               ; preds = %22
  br label %34

34:                                               ; preds = %33
  %35 = load i8, ptr %3, align 1, !tbaa !12
  %36 = zext i8 %35 to i32
  %37 = add nsw i32 %36, 1
  %38 = trunc i32 %37 to i8
  store i8 %38, ptr %3, align 1, !tbaa !12
  br label %12, !llvm.loop !17

39:                                               ; preds = %16
  br label %43

40:                                               ; preds = %1
  %41 = call noundef zeroext i8 @_ZN11mackAlgoTwo4Maze7getCellEhh(i8 noundef zeroext 0, i8 noundef zeroext 0)
  %42 = load i32, ptr @_ZZN11mackAlgoTwo11MackAlgoTwo29resetDestinationCellDistancesEvE11maxDistance, align 4, !tbaa !13
  call void @_ZN11mackAlgoTwo11MackAlgoTwo15setCellDistanceEhj(ptr noundef nonnull align 8 dereferenceable(21) %6, i8 noundef zeroext %41, i32 noundef %42)
  br label %43

43:                                               ; preds = %40, %39
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 #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, !7, i64 19}
!10 = !{!"_ZTSN11mackAlgoTwo11MackAlgoTwoE", !11, i64 0, !6, i64 8, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 19, !7, i64 20}
!11 = !{!"_ZTS15IMouseAlgorithm"}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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

@_ZZN11mackAlgoTwo11MackAlgoTwo29resetDestinationCellDistancesEvE11maxDistance = external hidden local_unnamed_addr global i32, align 4

declare noundef zeroext i8 @_ZN11mackAlgoTwo4Maze7getCellEhh(i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11mackAlgoTwo11MackAlgoTwo15setCellDistanceEhj(ptr noundef nonnull align 8 dereferenceable(21), i8 noundef zeroext, i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11mackAlgoTwo11MackAlgoTwo29resetDestinationCellDistancesEv(ptr noundef nonnull align 8 dereferenceable(21) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 19
  %3 = load i8, ptr %2, align 1, !tbaa !5
  %4 = icmp eq i8 %3, 0
  br i1 %4, label %.preheader.preheader, label %12

.preheader.preheader:                             ; preds = %1
  %5 = tail call noundef zeroext i8 @_ZN11mackAlgoTwo4Maze7getCellEhh(i8 noundef zeroext 7, i8 noundef zeroext 7)
  %6 = load i32, ptr @_ZZN11mackAlgoTwo11MackAlgoTwo29resetDestinationCellDistancesEvE11maxDistance, align 4, !tbaa !11
  tail call void @_ZN11mackAlgoTwo11MackAlgoTwo15setCellDistanceEhj(ptr noundef nonnull align 8 dereferenceable(21) %0, i8 noundef zeroext %5, i32 noundef %6)
  %7 = tail call noundef zeroext i8 @_ZN11mackAlgoTwo4Maze7getCellEhh(i8 noundef zeroext 7, i8 noundef zeroext 8)
  %8 = load i32, ptr @_ZZN11mackAlgoTwo11MackAlgoTwo29resetDestinationCellDistancesEvE11maxDistance, align 4, !tbaa !11
  tail call void @_ZN11mackAlgoTwo11MackAlgoTwo15setCellDistanceEhj(ptr noundef nonnull align 8 dereferenceable(21) %0, i8 noundef zeroext %7, i32 noundef %8)
  %9 = tail call noundef zeroext i8 @_ZN11mackAlgoTwo4Maze7getCellEhh(i8 noundef zeroext 8, i8 noundef zeroext 7)
  %10 = load i32, ptr @_ZZN11mackAlgoTwo11MackAlgoTwo29resetDestinationCellDistancesEvE11maxDistance, align 4, !tbaa !11
  tail call void @_ZN11mackAlgoTwo11MackAlgoTwo15setCellDistanceEhj(ptr noundef nonnull align 8 dereferenceable(21) %0, i8 noundef zeroext %9, i32 noundef %10)
  %11 = tail call noundef zeroext i8 @_ZN11mackAlgoTwo4Maze7getCellEhh(i8 noundef zeroext 8, i8 noundef zeroext 8)
  br label %.loopexit

12:                                               ; preds = %1
  %13 = tail call noundef zeroext i8 @_ZN11mackAlgoTwo4Maze7getCellEhh(i8 noundef zeroext 0, i8 noundef zeroext 0)
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader.preheader, %12
  %.sink = phi i8 [ %11, %.preheader.preheader ], [ %13, %12 ]
  %14 = load i32, ptr @_ZZN11mackAlgoTwo11MackAlgoTwo29resetDestinationCellDistancesEvE11maxDistance, align 4, !tbaa !11
  tail call void @_ZN11mackAlgoTwo11MackAlgoTwo15setCellDistanceEhj(ptr noundef nonnull align 8 dereferenceable(21) %0, i8 noundef zeroext %.sink, i32 noundef %14)
  ret void
}

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, !9, i64 19}
!6 = !{!"_ZTSN11mackAlgoTwo11MackAlgoTwoE", !7, i64 0, !8, i64 8, !9, i64 16, !9, i64 17, !9, i64 18, !9, i64 19, !9, i64 20}
!7 = !{!"_ZTS15IMouseAlgorithm"}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !9, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass