; LLVM IR from mbrenman/TetrisPlayground :: game/Tetris.ll (ZN6Tetris22highestValidColWithRotE8Rotation)

; 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.Tetris = type { [10 x [20 x i32]], i32, i8, i8, ptr, ptr }

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #1

declare void @_ZN5PieceC1Ei(ptr noundef nonnull align 4 dereferenceable(20), i32 noundef) unnamed_addr #2

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

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

declare noundef i32 @_ZN5Piece10pieceWidthEv(ptr noundef nonnull align 4 dereferenceable(20)) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6Tetris22highestValidColWithRotE8Rotation(ptr noundef nonnull align 8 dereferenceable(824) %0, i32 noundef %1) #4 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %10 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 20) #6
  %11 = getelementptr inbounds %class.Tetris, ptr %9, i32 0, i32 4
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = invoke noundef i32 @_ZN5Piece10getPieceIDEv(ptr noundef nonnull align 4 dereferenceable(20) %12)
          to label %14 unwind label %27

14:                                               ; preds = %2
  invoke void @_ZN5PieceC1Ei(ptr noundef nonnull align 4 dereferenceable(20) %10, i32 noundef %13)
          to label %15 unwind label %27

15:                                               ; preds = %14
  store ptr %10, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load i32, ptr %4, align 4, !tbaa !9
  call void @_ZN5Piece6rotateE8Rotation(ptr noundef nonnull align 4 dereferenceable(20) %16, i32 noundef %17)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call noundef i32 @_ZN5Piece10pieceWidthEv(ptr noundef nonnull align 4 dereferenceable(20) %18)
  store i32 %19, ptr %8, align 4, !tbaa !15
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %23, label %22

22:                                               ; preds = %15
  call void @_ZdlPvm(ptr noundef %20, i64 noundef 20) #7
  br label %23

23:                                               ; preds = %22, %15
  %24 = load i32, ptr %8, align 4, !tbaa !15
  %25 = sub nsw i32 10, %24
  %26 = sub nsw i32 %25, 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret i32 %26

27:                                               ; preds = %14, %2
  %28 = landingpad { ptr, i32 }
          cleanup
  %29 = extractvalue { ptr, i32 } %28, 0
  store ptr %29, ptr %6, align 8
  %30 = extractvalue { ptr, i32 } %28, 1
  store i32 %30, ptr %7, align 4
  call void @_ZdlPvm(ptr noundef %10, i64 noundef 20) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %31

31:                                               ; preds = %27
  %32 = load ptr, ptr %6, align 8
  %33 = load i32, ptr %7, align 4
  %34 = insertvalue { ptr, i32 } poison, ptr %32, 0
  %35 = insertvalue { ptr, i32 } %34, i32 %33, 1
  resume { ptr, i32 } %35
}

declare noundef i32 @_ZN5Piece10getPieceIDEv(ptr noundef nonnull align 4 dereferenceable(20)) #2

declare void @_ZN5Piece6rotateE8Rotation(ptr noundef nonnull align 4 dereferenceable(20), i32 noundef) #2

attributes #0 = { 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 #1 = { nobuiltin nounwind "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 willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }
attributes #7 = { builtin 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 = !{!"_ZTS8Rotation", !7, i64 0}
!11 = !{!12, !6, i64 808}
!12 = !{!"_ZTS6Tetris", !7, i64 0, !13, i64 800, !14, i64 804, !14, i64 805, !6, i64 808, !6, i64 816}
!13 = !{!"int", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!13, !13, 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"

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #1

declare void @_ZN5PieceC1Ei(ptr noundef nonnull align 4 dereferenceable(20), i32 noundef) unnamed_addr #2

declare noundef i32 @_ZN5Piece10pieceWidthEv(ptr noundef nonnull align 4 dereferenceable(20)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -2147483638, 2147483647) i32 @_ZN6Tetris22highestValidColWithRotE8Rotation(ptr nocapture noundef nonnull readonly align 8 dereferenceable(824) %0, i32 noundef %1) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %3 = tail call noalias noundef nonnull dereferenceable(20) ptr @_Znwm(i64 noundef 20) #4
  %4 = getelementptr inbounds i8, ptr %0, i64 808
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = invoke noundef i32 @_ZN5Piece10getPieceIDEv(ptr noundef nonnull align 4 dereferenceable(20) %5)
          to label %7 unwind label %11

7:                                                ; preds = %2
  invoke void @_ZN5PieceC1Ei(ptr noundef nonnull align 4 dereferenceable(20) %3, i32 noundef %6)
          to label %8 unwind label %11

8:                                                ; preds = %7
  tail call void @_ZN5Piece6rotateE8Rotation(ptr noundef nonnull align 4 dereferenceable(20) %3, i32 noundef %1)
  %9 = tail call noundef i32 @_ZN5Piece10pieceWidthEv(ptr noundef nonnull align 4 dereferenceable(20) %3)
  tail call void @_ZdlPvm(ptr noundef nonnull %3, i64 noundef 20) #5
  %10 = sub i32 9, %9
  ret i32 %10

11:                                               ; preds = %7, %2
  %12 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdlPvm(ptr noundef nonnull %3, i64 noundef 20) #5
  resume { ptr, i32 } %12
}

declare noundef i32 @_ZN5Piece10getPieceIDEv(ptr noundef nonnull align 4 dereferenceable(20)) local_unnamed_addr #2

declare void @_ZN5Piece6rotateE8Rotation(ptr noundef nonnull align 4 dereferenceable(20), i32 noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { nobuiltin nounwind "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 = { 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 #4 = { builtin allocsize(0) }
attributes #5 = { builtin 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, !11, i64 808}
!6 = !{!"_ZTS6Tetris", !7, i64 0, !9, i64 800, !10, i64 804, !10, i64 805, !11, i64 808, !11, i64 816}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass