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

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

@_ZL8colorMap = external hidden global <{ <{ i8, [15 x i8] }>, [15 x <{ i8, [15 x i8] }>] }>, align 16

; 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 @_Z14renderColorMapv() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %29, %0
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = call noundef i32 @_ZN3API9mazeWidthEv()
  %7 = icmp slt i32 %5, %6
  br i1 %7, label %9, label %8

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

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

10:                                               ; preds = %25, %9
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = call noundef i32 @_ZN3API10mazeHeightEv()
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %10
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [16 x [16 x i8]], ptr @_ZL8colorMap, i64 0, i64 %19
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [16 x i8], ptr %20, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !9
  call void @_ZN3API8setColorEiic(i32 noundef %16, i32 noundef %17, i8 noundef signext %24)
  br label %25

25:                                               ; preds = %15
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %3, align 4, !tbaa !5
  br label %10, !llvm.loop !10

28:                                               ; preds = %14
  br label %29

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

32:                                               ; preds = %8
  ret void
}

declare noundef i32 @_ZN3API9mazeWidthEv() #2

declare noundef i32 @_ZN3API10mazeHeightEv() #2

declare void @_ZN3API8setColorEiic(i32 noundef, i32 noundef, i8 noundef signext) #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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

@_ZL8colorMap = external hidden local_unnamed_addr global <{ <{ i8, [15 x i8] }>, [15 x <{ i8, [15 x i8] }>] }>, align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z14renderColorMapv() local_unnamed_addr #0 {
  %1 = tail call noundef i32 @_ZN3API9mazeWidthEv()
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.preheader, label %._crit_edge11

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

.lr.ph:                                           ; preds = %.preheader
  %5 = trunc nuw nsw i64 %indvars.iv13 to i32
  br label %9

._crit_edge11:                                    ; preds = %._crit_edge, %0
  ret void

._crit_edge:                                      ; preds = %9, %.preheader
  %indvars.iv.next14 = add nuw nsw i64 %indvars.iv13, 1
  %6 = tail call noundef i32 @_ZN3API9mazeWidthEv()
  %7 = sext i32 %6 to i64
  %8 = icmp slt i64 %indvars.iv.next14, %7
  br i1 %8, label %.preheader, label %._crit_edge11, !llvm.loop !5

9:                                                ; preds = %.lr.ph, %9
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %9 ]
  %10 = getelementptr inbounds [16 x [16 x i8]], ptr @_ZL8colorMap, i64 0, i64 %indvars.iv13, i64 %indvars.iv
  %11 = load i8, ptr %10, align 1, !tbaa !7
  %12 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @_ZN3API8setColorEiic(i32 noundef %5, i32 noundef %12, i8 noundef signext %11)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = tail call noundef i32 @_ZN3API10mazeHeightEv()
  %14 = sext i32 %13 to i64
  %15 = icmp slt i64 %indvars.iv.next, %14
  br i1 %15, label %9, label %._crit_edge, !llvm.loop !10
}

declare noundef i32 @_ZN3API9mazeWidthEv() local_unnamed_addr #1

declare noundef i32 @_ZN3API10mazeHeightEv() local_unnamed_addr #1

declare void @_ZN3API8setColorEiic(i32 noundef, i32 noundef, i8 noundef signext) 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = distinct !{!10, !6}


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