; LLVM IR from TharushaDinujaya/MicroMouse :: test/mms-cpp/Main.ll (Z15reset_flood_mapPPi)

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

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

8:                                                ; preds = %32, %1
  %9 = load i32, ptr %3, align 4, !tbaa !9
  %10 = call noundef i32 @_ZN3API9mazeWidthEv()
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %28, %13
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = call noundef i32 @_ZN3API10mazeHeightEv()
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

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

19:                                               ; preds = %14
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds ptr, ptr %20, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i32, ptr %24, i64 %26
  store i32 99999, ptr %27, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %19
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %5, align 4, !tbaa !9
  br label %14, !llvm.loop !11

31:                                               ; preds = %18
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %3, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %3, align 4, !tbaa !9
  br label %8, !llvm.loop !13

35:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %36 = call noundef i32 @_ZN3API9mazeWidthEv()
  %37 = sdiv i32 %36, 2
  store i32 %37, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %38 = call noundef i32 @_ZN3API10mazeHeightEv()
  %39 = sdiv i32 %38, 2
  store i32 %39, ptr %7, align 4, !tbaa !9
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds ptr, ptr %40, i64 7
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  %43 = getelementptr inbounds i32, ptr %42, i64 7
  store i32 0, ptr %43, align 4, !tbaa !9
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds ptr, ptr %44, i64 8
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  %47 = getelementptr inbounds i32, ptr %46, i64 7
  store i32 0, ptr %47, align 4, !tbaa !9
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds ptr, ptr %48, i64 7
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = getelementptr inbounds i32, ptr %50, i64 8
  store i32 0, ptr %51, align 4, !tbaa !9
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds ptr, ptr %52, i64 8
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  %55 = getelementptr inbounds i32, ptr %54, i64 8
  store i32 0, ptr %55, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  ret void
}

declare noundef i32 @_ZN3API9mazeWidthEv() #2

declare noundef i32 @_ZN3API10mazeHeightEv() #2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z15reset_flood_mapPPi(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = tail call noundef i32 @_ZN3API9mazeWidthEv()
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.preheader, label %._crit_edge13

.preheader:                                       ; preds = %1, %._crit_edge
  %indvars.iv15 = phi i64 [ %indvars.iv.next16, %._crit_edge ], [ 0, %1 ]
  %4 = tail call noundef i32 @_ZN3API10mazeHeightEv()
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %6 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv15
  br label %20

._crit_edge13:                                    ; preds = %._crit_edge, %1
  %7 = tail call noundef i32 @_ZN3API9mazeWidthEv()
  %8 = tail call noundef i32 @_ZN3API10mazeHeightEv()
  %9 = getelementptr inbounds i8, ptr %0, i64 56
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 28
  store i32 0, ptr %11, align 4, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %0, i64 64
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 28
  store i32 0, ptr %14, align 4, !tbaa !9
  %15 = getelementptr inbounds i8, ptr %10, i64 32
  store i32 0, ptr %15, align 4, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %13, i64 32
  store i32 0, ptr %16, align 4, !tbaa !9
  ret void

._crit_edge:                                      ; preds = %20, %.preheader
  %indvars.iv.next16 = add nuw nsw i64 %indvars.iv15, 1
  %17 = tail call noundef i32 @_ZN3API9mazeWidthEv()
  %18 = sext i32 %17 to i64
  %19 = icmp slt i64 %indvars.iv.next16, %18
  br i1 %19, label %.preheader, label %._crit_edge13, !llvm.loop !11

20:                                               ; preds = %.lr.ph, %20
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %20 ]
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds i32, ptr %21, i64 %indvars.iv
  store i32 99999, ptr %22, align 4, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = tail call noundef i32 @_ZN3API10mazeHeightEv()
  %24 = sext i32 %23 to i64
  %25 = icmp slt i64 %indvars.iv.next, %24
  br i1 %25, label %20, label %._crit_edge, !llvm.loop !13
}

declare noundef i32 @_ZN3API9mazeWidthEv() local_unnamed_addr #1

declare noundef i32 @_ZN3API10mazeHeightEv() 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, !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass