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

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

declare noundef i32 @_ZN3API9mazeWidthEv() #0

declare noundef i32 @_ZN3API10mazeHeightEv() #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7setWallPPiiii(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %9 = load i32, ptr %6, align 4, !tbaa !9
  %10 = icmp sge i32 %9, 0
  br i1 %10, label %11, label %34

11:                                               ; preds = %4
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = icmp sge i32 %12, 0
  br i1 %13, label %14, label %34

14:                                               ; preds = %11
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = call noundef i32 @_ZN3API9mazeWidthEv()
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %18, label %34

18:                                               ; preds = %14
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = call noundef i32 @_ZN3API10mazeHeightEv()
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %22, label %34

22:                                               ; preds = %18
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds ptr, ptr %24, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr %28, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = or i32 %32, %23
  store i32 %33, ptr %31, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %22, %18, %14, %11, %4
  %35 = load i32, ptr %8, align 4, !tbaa !9
  switch i32 %35, label %48 [
    i32 1, label %36
    i32 4, label %39
    i32 2, label %42
    i32 8, label %45
  ]

36:                                               ; preds = %34
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = load i32, ptr %7, align 4, !tbaa !9
  call void @_ZN3API7setWallEiic(i32 noundef %37, i32 noundef %38, i8 noundef signext 119)
  br label %49

39:                                               ; preds = %34
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = load i32, ptr %7, align 4, !tbaa !9
  call void @_ZN3API7setWallEiic(i32 noundef %40, i32 noundef %41, i8 noundef signext 101)
  br label %49

42:                                               ; preds = %34
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = load i32, ptr %7, align 4, !tbaa !9
  call void @_ZN3API7setWallEiic(i32 noundef %43, i32 noundef %44, i8 noundef signext 110)
  br label %49

45:                                               ; preds = %34
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = load i32, ptr %7, align 4, !tbaa !9
  call void @_ZN3API7setWallEiic(i32 noundef %46, i32 noundef %47, i8 noundef signext 115)
  br label %49

48:                                               ; preds = %34
  br label %49

49:                                               ; preds = %48, %45, %42, %39, %36
  ret void
}

declare void @_ZN3API7setWallEiic(i32 noundef, i32 noundef, i8 noundef signext) #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, !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}


; 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 i32 @_ZN3API9mazeWidthEv() local_unnamed_addr #0

declare noundef i32 @_ZN3API10mazeHeightEv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7setWallPPiiii(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = or i32 %2, %1
  %or.cond = icmp sgt i32 %5, -1
  br i1 %or.cond, label %6, label %20

6:                                                ; preds = %4
  %7 = tail call noundef i32 @_ZN3API9mazeWidthEv()
  %8 = icmp sgt i32 %7, %1
  br i1 %8, label %9, label %20

9:                                                ; preds = %6
  %10 = tail call noundef i32 @_ZN3API10mazeHeightEv()
  %11 = icmp sgt i32 %10, %2
  br i1 %11, label %12, label %20

12:                                               ; preds = %9
  %13 = zext nneg i32 %1 to i64
  %14 = getelementptr inbounds ptr, ptr %0, i64 %13
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = zext nneg i32 %2 to i64
  %17 = getelementptr inbounds i32, ptr %15, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = or i32 %18, %3
  store i32 %19, ptr %17, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %12, %9, %6, %4
  %switch.tableidx = add i32 %3, -1
  %21 = icmp ult i32 %switch.tableidx, 8
  br i1 %21, label %switch.hole_check, label %23

switch.hole_check:                                ; preds = %20
  %switch.maskindex = trunc nuw i32 %switch.tableidx to i8
  %switch.shifted = lshr i8 -117, %switch.maskindex
  %switch.lobit = trunc i8 %switch.shifted to i1
  br i1 %switch.lobit, label %switch.lookup, label %23

switch.lookup:                                    ; preds = %switch.hole_check
  %22 = shl nuw nsw i32 %switch.tableidx, 3
  %switch.shiftamt = zext nneg i32 %22 to i64
  %switch.downshift = lshr i64 8320250191277420151, %switch.shiftamt
  %switch.masked = trunc i64 %switch.downshift to i8
  tail call void @_ZN3API7setWallEiic(i32 noundef %1, i32 noundef %2, i8 noundef signext %switch.masked)
  br label %23

23:                                               ; preds = %switch.hole_check, %20, %switch.lookup
  ret void
}

declare void @_ZN3API7setWallEiic(i32 noundef, i32 noundef, i8 noundef signext) 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, !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}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass