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

; 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
define dso_local noundef zeroext i8 @_ZN11mackAlgoTwo11MackAlgoTwo25getClosestDestinationCellEv(ptr noundef nonnull align 8 dereferenceable(21) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  %9 = call noundef zeroext i8 @_ZN11mackAlgoTwo4Maze7getCellEhh(i8 noundef zeroext 7, i8 noundef zeroext 7)
  store i8 %9, ptr %3, align 1, !tbaa !9
  %10 = getelementptr inbounds %"class.mackAlgoTwo::MackAlgoTwo", ptr %8, i32 0, i32 5
  %11 = load i8, ptr %10, align 1, !tbaa !10
  %12 = zext i8 %11 to i32
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %50

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

15:                                               ; preds = %44, %14
  %16 = load i8, ptr %4, align 1, !tbaa !9
  %17 = zext i8 %16 to i32
  %18 = icmp sle i32 %17, 8
  br i1 %18, label %20, label %19

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

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

21:                                               ; preds = %38, %20
  %22 = load i8, ptr %6, align 1, !tbaa !9
  %23 = zext i8 %22 to i32
  %24 = icmp sle i32 %23, 8
  br i1 %24, label %26, label %25

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

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  %27 = load i8, ptr %4, align 1, !tbaa !9
  %28 = load i8, ptr %6, align 1, !tbaa !9
  %29 = call noundef zeroext i8 @_ZN11mackAlgoTwo4Maze7getCellEhh(i8 noundef zeroext %27, i8 noundef zeroext %28)
  store i8 %29, ptr %7, align 1, !tbaa !9
  %30 = load i8, ptr %7, align 1, !tbaa !9
  %31 = call noundef i32 @_ZN11mackAlgoTwo4Maze11getDistanceEh(i8 noundef zeroext %30)
  %32 = load i8, ptr %3, align 1, !tbaa !9
  %33 = call noundef i32 @_ZN11mackAlgoTwo4Maze11getDistanceEh(i8 noundef zeroext %32)
  %34 = icmp ult i32 %31, %33
  br i1 %34, label %35, label %37

35:                                               ; preds = %26
  %36 = load i8, ptr %7, align 1, !tbaa !9
  store i8 %36, ptr %3, align 1, !tbaa !9
  br label %37

37:                                               ; preds = %35, %26
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  br label %38

38:                                               ; preds = %37
  %39 = load i8, ptr %6, align 1, !tbaa !9
  %40 = zext i8 %39 to i32
  %41 = add nsw i32 %40, 1
  %42 = trunc i32 %41 to i8
  store i8 %42, ptr %6, align 1, !tbaa !9
  br label %21, !llvm.loop !13

43:                                               ; preds = %25
  br label %44

44:                                               ; preds = %43
  %45 = load i8, ptr %4, align 1, !tbaa !9
  %46 = zext i8 %45 to i32
  %47 = add nsw i32 %46, 1
  %48 = trunc i32 %47 to i8
  store i8 %48, ptr %4, align 1, !tbaa !9
  br label %15, !llvm.loop !15

49:                                               ; preds = %19
  br label %52

50:                                               ; preds = %1
  %51 = call noundef zeroext i8 @_ZN11mackAlgoTwo4Maze7getCellEhh(i8 noundef zeroext 0, i8 noundef zeroext 0)
  store i8 %51, ptr %3, align 1, !tbaa !9
  br label %52

52:                                               ; preds = %50, %49
  %53 = load i8, ptr %3, align 1, !tbaa !9
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  ret i8 %53
}

declare noundef i32 @_ZN11mackAlgoTwo4Maze11getDistanceEh(i8 noundef zeroext) #1

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 = !{!7, !7, i64 0}
!10 = !{!11, !7, i64 19}
!11 = !{!"_ZTSN11mackAlgoTwo11MackAlgoTwoE", !12, i64 0, !6, i64 8, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 19, !7, i64 20}
!12 = !{!"_ZTS15IMouseAlgorithm"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 noundef zeroext i8 @_ZN11mackAlgoTwo4Maze7getCellEhh(i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i8 @_ZN11mackAlgoTwo11MackAlgoTwo25getClosestDestinationCellEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(21) %0) local_unnamed_addr #1 align 2 {
  %2 = tail call noundef zeroext i8 @_ZN11mackAlgoTwo4Maze7getCellEhh(i8 noundef zeroext 7, i8 noundef zeroext 7)
  %3 = getelementptr inbounds i8, ptr %0, i64 19
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %5 = icmp eq i8 %4, 0
  br i1 %5, label %.preheader.preheader, label %22

.preheader.preheader:                             ; preds = %1
  %6 = tail call noundef zeroext i8 @_ZN11mackAlgoTwo4Maze7getCellEhh(i8 noundef zeroext 7, i8 noundef zeroext 7)
  %7 = tail call noundef i32 @_ZN11mackAlgoTwo4Maze11getDistanceEh(i8 noundef zeroext %6)
  %8 = tail call noundef i32 @_ZN11mackAlgoTwo4Maze11getDistanceEh(i8 noundef zeroext %2)
  %9 = icmp ult i32 %7, %8
  %spec.select = select i1 %9, i8 %6, i8 %2
  %10 = tail call noundef zeroext i8 @_ZN11mackAlgoTwo4Maze7getCellEhh(i8 noundef zeroext 7, i8 noundef zeroext 8)
  %11 = tail call noundef i32 @_ZN11mackAlgoTwo4Maze11getDistanceEh(i8 noundef zeroext %10)
  %12 = tail call noundef i32 @_ZN11mackAlgoTwo4Maze11getDistanceEh(i8 noundef zeroext %spec.select)
  %13 = icmp ult i32 %11, %12
  %spec.select.1 = select i1 %13, i8 %10, i8 %spec.select
  %14 = tail call noundef zeroext i8 @_ZN11mackAlgoTwo4Maze7getCellEhh(i8 noundef zeroext 8, i8 noundef zeroext 7)
  %15 = tail call noundef i32 @_ZN11mackAlgoTwo4Maze11getDistanceEh(i8 noundef zeroext %14)
  %16 = tail call noundef i32 @_ZN11mackAlgoTwo4Maze11getDistanceEh(i8 noundef zeroext %spec.select.1)
  %17 = icmp ult i32 %15, %16
  %spec.select.120 = select i1 %17, i8 %14, i8 %spec.select.1
  %18 = tail call noundef zeroext i8 @_ZN11mackAlgoTwo4Maze7getCellEhh(i8 noundef zeroext 8, i8 noundef zeroext 8)
  %19 = tail call noundef i32 @_ZN11mackAlgoTwo4Maze11getDistanceEh(i8 noundef zeroext %18)
  %20 = tail call noundef i32 @_ZN11mackAlgoTwo4Maze11getDistanceEh(i8 noundef zeroext %spec.select.120)
  %21 = icmp ult i32 %19, %20
  %spec.select.1.1 = select i1 %21, i8 %18, i8 %spec.select.120
  br label %.loopexit

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

.loopexit:                                        ; preds = %.preheader.preheader, %22
  %.3 = phi i8 [ %23, %22 ], [ %spec.select.1.1, %.preheader.preheader ]
  ret i8 %.3
}

declare noundef i32 @_ZN11mackAlgoTwo4Maze11getDistanceEh(i8 noundef zeroext) 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, !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"}


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