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

; 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: mustprogress uwtable
define dso_local noundef ptr @_Z17initializeWallMapv() #1 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %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
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #5
  %8 = call noundef i32 @_ZN3API9mazeWidthEv()
  %9 = sext i32 %8 to i64
  %10 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %9, i64 8)
  %11 = extractvalue { i64, i1 } %10, 1
  %12 = extractvalue { i64, i1 } %10, 0
  %13 = select i1 %11, i64 -1, i64 %12
  %14 = call noalias noundef nonnull ptr @_Znam(i64 noundef %13) #6
  store ptr %14, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %32, %0
  %16 = load i32, ptr %2, align 4, !tbaa !9
  %17 = call noundef i32 @_ZN3API9mazeWidthEv()
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %35

20:                                               ; preds = %15
  %21 = call noundef i32 @_ZN3API10mazeHeightEv()
  %22 = sext i32 %21 to i64
  %23 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %22, i64 4)
  %24 = extractvalue { i64, i1 } %23, 1
  %25 = extractvalue { i64, i1 } %23, 0
  %26 = select i1 %24, i64 -1, i64 %25
  %27 = call noalias noundef nonnull ptr @_Znam(i64 noundef %26) #6
  %28 = load ptr, ptr %1, align 8, !tbaa !5
  %29 = load i32, ptr %2, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds ptr, ptr %28, i64 %30
  store ptr %27, ptr %31, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %20
  %33 = load i32, ptr %2, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %2, align 4, !tbaa !9
  br label %15, !llvm.loop !11

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

36:                                               ; preds = %60, %35
  %37 = load i32, ptr %3, align 4, !tbaa !9
  %38 = call noundef i32 @_ZN3API9mazeWidthEv()
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %41, label %40

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

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

42:                                               ; preds = %56, %41
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = call noundef i32 @_ZN3API10mazeHeightEv()
  %45 = icmp slt i32 %43, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %42
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %59

47:                                               ; preds = %42
  %48 = load ptr, ptr %1, align 8, !tbaa !5
  %49 = load i32, ptr %3, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds ptr, ptr %48, i64 %50
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i32, ptr %52, i64 %54
  store i32 0, ptr %55, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %47
  %57 = load i32, ptr %5, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %5, align 4, !tbaa !9
  br label %42, !llvm.loop !13

59:                                               ; preds = %46
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %3, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %3, align 4, !tbaa !9
  br label %36, !llvm.loop !14

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

64:                                               ; preds = %89, %63
  %65 = load i32, ptr %6, align 4, !tbaa !9
  %66 = call noundef i32 @_ZN3API9mazeWidthEv()
  %67 = icmp slt i32 %65, %66
  br i1 %67, label %69, label %68

68:                                               ; preds = %64
  store i32 11, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %92

69:                                               ; preds = %64
  %70 = load ptr, ptr %1, align 8, !tbaa !5
  %71 = load i32, ptr %6, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds ptr, ptr %70, i64 %72
  %74 = load ptr, ptr %73, align 8, !tbaa !5
  %75 = getelementptr inbounds i32, ptr %74, i64 0
  %76 = load i32, ptr %75, align 4, !tbaa !9
  %77 = or i32 %76, 8
  store i32 %77, ptr %75, align 4, !tbaa !9
  %78 = load ptr, ptr %1, align 8, !tbaa !5
  %79 = load i32, ptr %6, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds ptr, ptr %78, i64 %80
  %82 = load ptr, ptr %81, align 8, !tbaa !5
  %83 = call noundef i32 @_ZN3API10mazeHeightEv()
  %84 = sub nsw i32 %83, 1
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds i32, ptr %82, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !9
  %88 = or i32 %87, 2
  store i32 %88, ptr %86, align 4, !tbaa !9
  br label %89

89:                                               ; preds = %69
  %90 = load i32, ptr %6, align 4, !tbaa !9
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %6, align 4, !tbaa !9
  br label %64, !llvm.loop !15

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

93:                                               ; preds = %118, %92
  %94 = load i32, ptr %7, align 4, !tbaa !9
  %95 = call noundef i32 @_ZN3API10mazeHeightEv()
  %96 = icmp slt i32 %94, %95
  br i1 %96, label %98, label %97

97:                                               ; preds = %93
  store i32 14, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %121

98:                                               ; preds = %93
  %99 = load ptr, ptr %1, align 8, !tbaa !5
  %100 = getelementptr inbounds ptr, ptr %99, i64 0
  %101 = load ptr, ptr %100, align 8, !tbaa !5
  %102 = load i32, ptr %7, align 4, !tbaa !9
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds i32, ptr %101, i64 %103
  %105 = load i32, ptr %104, align 4, !tbaa !9
  %106 = or i32 %105, 1
  store i32 %106, ptr %104, align 4, !tbaa !9
  %107 = load ptr, ptr %1, align 8, !tbaa !5
  %108 = call noundef i32 @_ZN3API9mazeWidthEv()
  %109 = sub nsw i32 %108, 1
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds ptr, ptr %107, i64 %110
  %112 = load ptr, ptr %111, align 8, !tbaa !5
  %113 = load i32, ptr %7, align 4, !tbaa !9
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds i32, ptr %112, i64 %114
  %116 = load i32, ptr %115, align 4, !tbaa !9
  %117 = or i32 %116, 4
  store i32 %117, ptr %115, align 4, !tbaa !9
  br label %118

118:                                              ; preds = %98
  %119 = load i32, ptr %7, align 4, !tbaa !9
  %120 = add nsw i32 %119, 1
  store i32 %120, ptr %7, align 4, !tbaa !9
  br label %93, !llvm.loop !16

121:                                              ; preds = %97
  %122 = load ptr, ptr %1, align 8, !tbaa !5
  store i32 1, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  ret ptr %122
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare noundef i32 @_ZN3API9mazeWidthEv() #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #3

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #4

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nobuiltin allocsize(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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }

!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}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !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 noalias noundef nonnull ptr @_Z17initializeWallMapv() local_unnamed_addr #0 {
  %1 = tail call noundef i32 @_ZN3API9mazeWidthEv()
  %2 = zext nneg i32 %1 to i64
  %3 = icmp slt i32 %1, 0
  %4 = shl nuw nsw i64 %2, 3
  %5 = select i1 %3, i64 -1, i64 %4
  %6 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %5) #3
  %7 = tail call noundef i32 @_ZN3API9mazeWidthEv()
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %.preheader29

.preheader29:                                     ; preds = %.lr.ph, %0
  %9 = tail call noundef i32 @_ZN3API9mazeWidthEv()
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.preheader28, label %.preheader27

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %11 = tail call noundef i32 @_ZN3API10mazeHeightEv()
  %12 = zext nneg i32 %11 to i64
  %13 = icmp slt i32 %11, 0
  %14 = shl nuw nsw i64 %12, 2
  %15 = select i1 %13, i64 -1, i64 %14
  %16 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %15) #3
  %17 = getelementptr inbounds ptr, ptr %6, i64 %indvars.iv
  store ptr %16, ptr %17, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = tail call noundef i32 @_ZN3API9mazeWidthEv()
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next, %19
  br i1 %20, label %.lr.ph, label %.preheader29, !llvm.loop !9

.preheader28:                                     ; preds = %.preheader29, %._crit_edge
  %indvars.iv43 = phi i64 [ %indvars.iv.next44, %._crit_edge ], [ 0, %.preheader29 ]
  %21 = tail call noundef i32 @_ZN3API10mazeHeightEv()
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %.lr.ph32, label %._crit_edge

.lr.ph32:                                         ; preds = %.preheader28
  %23 = getelementptr inbounds ptr, ptr %6, i64 %indvars.iv43
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  br label %30

.preheader27:                                     ; preds = %._crit_edge, %.preheader29
  %25 = tail call noundef i32 @_ZN3API9mazeWidthEv()
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %.lr.ph35, label %.preheader

._crit_edge:                                      ; preds = %30, %.preheader28
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %27 = tail call noundef i32 @_ZN3API9mazeWidthEv()
  %28 = sext i32 %27 to i64
  %29 = icmp slt i64 %indvars.iv.next44, %28
  br i1 %29, label %.preheader28, label %.preheader27, !llvm.loop !11

30:                                               ; preds = %.lr.ph32, %30
  %indvars.iv40 = phi i64 [ 0, %.lr.ph32 ], [ %indvars.iv.next41, %30 ]
  %31 = getelementptr inbounds i32, ptr %24, i64 %indvars.iv40
  store i32 0, ptr %31, align 4, !tbaa !12
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %32 = tail call noundef i32 @_ZN3API10mazeHeightEv()
  %33 = sext i32 %32 to i64
  %34 = icmp slt i64 %indvars.iv.next41, %33
  br i1 %34, label %30, label %._crit_edge, !llvm.loop !14

.preheader:                                       ; preds = %.lr.ph35, %.preheader27
  %invariant.gep = getelementptr i8, ptr %6, i64 -8
  %35 = tail call noundef i32 @_ZN3API10mazeHeightEv()
  %36 = icmp sgt i32 %35, 0
  br i1 %36, label %.lr.ph37, label %._crit_edge38

.lr.ph37:                                         ; preds = %.preheader
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  br label %51

.lr.ph35:                                         ; preds = %.preheader27, %.lr.ph35
  %indvars.iv46 = phi i64 [ %indvars.iv.next47, %.lr.ph35 ], [ 0, %.preheader27 ]
  %38 = getelementptr inbounds ptr, ptr %6, i64 %indvars.iv46
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = load i32, ptr %39, align 4, !tbaa !12
  %41 = or i32 %40, 8
  store i32 %41, ptr %39, align 4, !tbaa !12
  %42 = tail call noundef i32 @_ZN3API10mazeHeightEv()
  %43 = sext i32 %42 to i64
  %44 = getelementptr i32, ptr %39, i64 %43
  %45 = getelementptr i8, ptr %44, i64 -4
  %46 = load i32, ptr %45, align 4, !tbaa !12
  %47 = or i32 %46, 2
  store i32 %47, ptr %45, align 4, !tbaa !12
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %48 = tail call noundef i32 @_ZN3API9mazeWidthEv()
  %49 = sext i32 %48 to i64
  %50 = icmp slt i64 %indvars.iv.next47, %49
  br i1 %50, label %.lr.ph35, label %.preheader, !llvm.loop !15

._crit_edge38:                                    ; preds = %51, %.preheader
  ret ptr %6

51:                                               ; preds = %.lr.ph37, %51
  %indvars.iv49 = phi i64 [ 0, %.lr.ph37 ], [ %indvars.iv.next50, %51 ]
  %52 = getelementptr inbounds i32, ptr %37, i64 %indvars.iv49
  %53 = load i32, ptr %52, align 4, !tbaa !12
  %54 = or i32 %53, 1
  store i32 %54, ptr %52, align 4, !tbaa !12
  %55 = tail call noundef i32 @_ZN3API9mazeWidthEv()
  %56 = sext i32 %55 to i64
  %gep = getelementptr ptr, ptr %invariant.gep, i64 %56
  %57 = load ptr, ptr %gep, align 8, !tbaa !5
  %58 = getelementptr inbounds i32, ptr %57, i64 %indvars.iv49
  %59 = load i32, ptr %58, align 4, !tbaa !12
  %60 = or i32 %59, 4
  store i32 %60, ptr %58, align 4, !tbaa !12
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %61 = tail call noundef i32 @_ZN3API10mazeHeightEv()
  %62 = sext i32 %61 to i64
  %63 = icmp slt i64 %indvars.iv.next50, %62
  br i1 %63, label %51, label %._crit_edge38, !llvm.loop !16
}

declare noundef i32 @_ZN3API9mazeWidthEv() local_unnamed_addr #1

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #2

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" }
attributes #2 = { nobuiltin allocsize(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 = { builtin allocsize(0) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}


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