; LLVM IR from mbrenman/TetrisPlayground :: game/Piece.ll (ZN5Piece6rotateE8Rotation)

; 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.Piece = type { [4 x [4 x i8]], i32 }

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5Piece6rotateE8Rotation(ptr noundef nonnull align 4 dereferenceable(20) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca [4 x [4 x i8]], align 16
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %13 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #4
  %14 = getelementptr inbounds [4 x [4 x i8]], ptr %5, i64 0, i64 0
  call void @_ZN5Piece9copyPieceEPA4_b(ptr noundef nonnull align 4 dereferenceable(20) %13, ptr noundef %14)
  %15 = load i32, ptr %4, align 4, !tbaa !9
  switch i32 %15, label %129 [
    i32 0, label %130
    i32 1, label %16
    i32 2, label %53
    i32 3, label %90
  ]

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %17

17:                                               ; preds = %49, %16
  %18 = load i32, ptr %6, align 4, !tbaa !11
  %19 = icmp slt i32 %18, 4
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  store i32 3, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %52

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %22

22:                                               ; preds = %45, %21
  %23 = load i32, ptr %8, align 4, !tbaa !11
  %24 = icmp slt i32 %23, 4
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  store i32 6, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %48

26:                                               ; preds = %22
  %27 = getelementptr inbounds %class.Piece, ptr %13, i32 0, i32 0
  %28 = load i32, ptr %6, align 4, !tbaa !11
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [4 x [4 x i8]], ptr %27, i64 0, i64 %29
  %31 = load i32, ptr %8, align 4, !tbaa !11
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [4 x i8], ptr %30, i64 0, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !13, !range !15, !noundef !16
  %35 = trunc i8 %34 to i1
  %36 = load i32, ptr %8, align 4, !tbaa !11
  %37 = sub nsw i32 4, %36
  %38 = sub nsw i32 %37, 1
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [4 x [4 x i8]], ptr %5, i64 0, i64 %39
  %41 = load i32, ptr %6, align 4, !tbaa !11
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [4 x i8], ptr %40, i64 0, i64 %42
  %44 = zext i1 %35 to i8
  store i8 %44, ptr %43, align 1, !tbaa !13
  br label %45

45:                                               ; preds = %26
  %46 = load i32, ptr %8, align 4, !tbaa !11
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %8, align 4, !tbaa !11
  br label %22, !llvm.loop !17

48:                                               ; preds = %25
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %6, align 4, !tbaa !11
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %6, align 4, !tbaa !11
  br label %17, !llvm.loop !19

52:                                               ; preds = %20
  br label %130

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

54:                                               ; preds = %86, %53
  %55 = load i32, ptr %9, align 4, !tbaa !11
  %56 = icmp slt i32 %55, 4
  br i1 %56, label %58, label %57

57:                                               ; preds = %54
  store i32 9, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %89

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

59:                                               ; preds = %82, %58
  %60 = load i32, ptr %10, align 4, !tbaa !11
  %61 = icmp slt i32 %60, 4
  br i1 %61, label %63, label %62

62:                                               ; preds = %59
  store i32 12, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %85

63:                                               ; preds = %59
  %64 = getelementptr inbounds %class.Piece, ptr %13, i32 0, i32 0
  %65 = load i32, ptr %9, align 4, !tbaa !11
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [4 x [4 x i8]], ptr %64, i64 0, i64 %66
  %68 = load i32, ptr %10, align 4, !tbaa !11
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [4 x i8], ptr %67, i64 0, i64 %69
  %71 = load i8, ptr %70, align 1, !tbaa !13, !range !15, !noundef !16
  %72 = trunc i8 %71 to i1
  %73 = load i32, ptr %10, align 4, !tbaa !11
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [4 x [4 x i8]], ptr %5, i64 0, i64 %74
  %76 = load i32, ptr %9, align 4, !tbaa !11
  %77 = sub nsw i32 4, %76
  %78 = sub nsw i32 %77, 1
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [4 x i8], ptr %75, i64 0, i64 %79
  %81 = zext i1 %72 to i8
  store i8 %81, ptr %80, align 1, !tbaa !13
  br label %82

82:                                               ; preds = %63
  %83 = load i32, ptr %10, align 4, !tbaa !11
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %10, align 4, !tbaa !11
  br label %59, !llvm.loop !20

85:                                               ; preds = %62
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %9, align 4, !tbaa !11
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %9, align 4, !tbaa !11
  br label %54, !llvm.loop !21

89:                                               ; preds = %57
  br label %130

90:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %91

91:                                               ; preds = %125, %90
  %92 = load i32, ptr %11, align 4, !tbaa !11
  %93 = icmp slt i32 %92, 4
  br i1 %93, label %95, label %94

94:                                               ; preds = %91
  store i32 15, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %128

95:                                               ; preds = %91
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %96

96:                                               ; preds = %121, %95
  %97 = load i32, ptr %12, align 4, !tbaa !11
  %98 = icmp slt i32 %97, 4
  br i1 %98, label %100, label %99

99:                                               ; preds = %96
  store i32 18, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %124

100:                                              ; preds = %96
  %101 = getelementptr inbounds %class.Piece, ptr %13, i32 0, i32 0
  %102 = load i32, ptr %11, align 4, !tbaa !11
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [4 x [4 x i8]], ptr %101, i64 0, i64 %103
  %105 = load i32, ptr %12, align 4, !tbaa !11
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [4 x i8], ptr %104, i64 0, i64 %106
  %108 = load i8, ptr %107, align 1, !tbaa !13, !range !15, !noundef !16
  %109 = trunc i8 %108 to i1
  %110 = load i32, ptr %11, align 4, !tbaa !11
  %111 = sub nsw i32 4, %110
  %112 = sub nsw i32 %111, 1
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [4 x [4 x i8]], ptr %5, i64 0, i64 %113
  %115 = load i32, ptr %12, align 4, !tbaa !11
  %116 = sub nsw i32 4, %115
  %117 = sub nsw i32 %116, 1
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds [4 x i8], ptr %114, i64 0, i64 %118
  %120 = zext i1 %109 to i8
  store i8 %120, ptr %119, align 1, !tbaa !13
  br label %121

121:                                              ; preds = %100
  %122 = load i32, ptr %12, align 4, !tbaa !11
  %123 = add nsw i32 %122, 1
  store i32 %123, ptr %12, align 4, !tbaa !11
  br label %96, !llvm.loop !22

124:                                              ; preds = %99
  br label %125

125:                                              ; preds = %124
  %126 = load i32, ptr %11, align 4, !tbaa !11
  %127 = add nsw i32 %126, 1
  store i32 %127, ptr %11, align 4, !tbaa !11
  br label %91, !llvm.loop !23

128:                                              ; preds = %94
  br label %130

129:                                              ; preds = %2
  call void @exit(i32 noundef 1) #5
  unreachable

130:                                              ; preds = %128, %89, %52, %2
  %131 = getelementptr inbounds [4 x [4 x i8]], ptr %5, i64 0, i64 0
  call void @_ZN5Piece12replacePieceEPA4_b(ptr noundef nonnull align 4 dereferenceable(20) %13, ptr noundef %131)
  call void @_ZN5Piece8pullLeftEv(ptr noundef nonnull align 4 dereferenceable(20) %13)
  call void @_ZN5Piece8pullDownEv(ptr noundef nonnull align 4 dereferenceable(20) %13)
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #4
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Piece9copyPieceEPA4_b(ptr noundef nonnull align 4 dereferenceable(20), ptr noundef) #3 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Piece12replacePieceEPA4_b(ptr noundef nonnull align 4 dereferenceable(20), ptr noundef) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5Piece8pullLeftEv(ptr noundef nonnull align 4 dereferenceable(20)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5Piece8pullDownEv(ptr noundef nonnull align 4 dereferenceable(20)) #1 align 2

attributes #0 = { noreturn 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nounwind 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 = { nounwind }
attributes #5 = { noreturn 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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = distinct !{!20, !18}
!21 = distinct !{!21, !18}
!22 = distinct !{!22, !18}
!23 = distinct !{!23, !18}


; 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: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5Piece6rotateE8Rotation(ptr noundef nonnull align 4 dereferenceable(20) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = alloca [4 x [4 x i8]], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  call void @_ZN5Piece9copyPieceEPA4_b(ptr noundef nonnull align 4 dereferenceable(20) %0, ptr noundef nonnull %3)
  switch i32 %1, label %10 [
    i32 0, label %.loopexit
    i32 1, label %.preheader.preheader
    i32 2, label %.preheader31.preheader
    i32 3, label %.preheader34.preheader
  ]

.preheader34.preheader:                           ; preds = %2
  %4 = load <16 x i8>, ptr %0, align 4, !tbaa !5
  %5 = shufflevector <16 x i8> %4, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
  store <16 x i8> %5, ptr %3, align 16, !tbaa !5
  br label %.loopexit

.preheader31.preheader:                           ; preds = %2
  %6 = load <16 x i8>, ptr %0, align 4, !tbaa !5
  %7 = shufflevector <16 x i8> %6, <16 x i8> poison, <16 x i32> <i32 12, i32 8, i32 4, i32 0, i32 13, i32 9, i32 5, i32 1, i32 14, i32 10, i32 6, i32 2, i32 15, i32 11, i32 7, i32 3>
  store <16 x i8> %7, ptr %3, align 16, !tbaa !5
  br label %.loopexit

.preheader.preheader:                             ; preds = %2
  %8 = load <16 x i8>, ptr %0, align 4, !tbaa !5
  %9 = shufflevector <16 x i8> %8, <16 x i8> poison, <16 x i32> <i32 3, i32 7, i32 11, i32 15, i32 2, i32 6, i32 10, i32 14, i32 1, i32 5, i32 9, i32 13, i32 0, i32 4, i32 8, i32 12>
  store <16 x i8> %9, ptr %3, align 16, !tbaa !5
  br label %.loopexit

10:                                               ; preds = %2
  call void @exit(i32 noundef 1) #5
  unreachable

.loopexit:                                        ; preds = %.preheader34.preheader, %.preheader31.preheader, %.preheader.preheader, %2
  call void @_ZN5Piece12replacePieceEPA4_b(ptr noundef nonnull align 4 dereferenceable(20) %0, ptr noundef nonnull %3)
  call void @_ZN5Piece8pullLeftEv(ptr noundef nonnull align 4 dereferenceable(20) %0)
  call void @_ZN5Piece8pullDownEv(ptr noundef nonnull align 4 dereferenceable(20) %0)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Piece9copyPieceEPA4_b(ptr noundef nonnull align 4 dereferenceable(20), ptr noundef) local_unnamed_addr #3 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Piece12replacePieceEPA4_b(ptr noundef nonnull align 4 dereferenceable(20), ptr noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5Piece8pullLeftEv(ptr noundef nonnull align 4 dereferenceable(20)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5Piece8pullDownEv(ptr noundef nonnull align 4 dereferenceable(20)) local_unnamed_addr #1 align 2

attributes #0 = { noreturn 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 #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nounwind 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 = { nounwind }
attributes #5 = { noreturn 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass