; LLVM IR from smv1999/CompetitiveProgrammingQuestionBank :: Arrays/left_rotate_by_d_extra_space.ll (Z13leftRotateByDPiii)

; 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: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z13leftRotateByDPiii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = zext i32 %12 to i64
  %14 = call ptr @llvm.stacksave.p0()
  store ptr %14, ptr %7, align 8
  %15 = alloca i32, i64 %13, align 16
  store i64 %13, ptr %8, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %16

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

20:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %33

21:                                               ; preds = %16
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i32, ptr %22, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i32, ptr %15, i64 %28
  store i32 %26, ptr %29, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %21
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %9, align 4, !tbaa !9
  br label %16, !llvm.loop !11

33:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %34 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %34, ptr %10, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %52, %33
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %55

40:                                               ; preds = %35
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i32, ptr %41, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = sub nsw i32 %47, %48
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i32, ptr %46, i64 %50
  store i32 %45, ptr %51, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %40
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %10, align 4, !tbaa !9
  br label %35, !llvm.loop !13

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

56:                                               ; preds = %74, %55
  %57 = load i32, ptr %11, align 4, !tbaa !9
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = icmp slt i32 %57, %58
  br i1 %59, label %61, label %60

60:                                               ; preds = %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %77

61:                                               ; preds = %56
  %62 = load i32, ptr %11, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i32, ptr %15, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !9
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = load i32, ptr %5, align 4, !tbaa !9
  %68 = load i32, ptr %6, align 4, !tbaa !9
  %69 = sub nsw i32 %67, %68
  %70 = load i32, ptr %11, align 4, !tbaa !9
  %71 = add nsw i32 %69, %70
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i32, ptr %66, i64 %72
  store i32 %65, ptr %73, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %61
  %75 = load i32, ptr %11, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %11, align 4, !tbaa !9
  br label %56, !llvm.loop !14

77:                                               ; preds = %60
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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}


; 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 nofree norecurse noreturn nosync nounwind memory(argmem: readwrite, inaccessiblemem: write) uwtable
define dso_local noundef i32 @_Z13leftRotateByDPiii(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = zext i32 %2 to i64
  %5 = alloca i32, i64 %4, align 16
  %6 = icmp sgt i32 %2, 0
  br i1 %6, label %.lr.ph.preheader, label %.preheader27

.lr.ph.preheader:                                 ; preds = %3
  %7 = shl nuw nsw i64 %4, 2
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %5, ptr align 4 %0, i64 %7, i1 false), !tbaa !5
  br label %.preheader27

.preheader27:                                     ; preds = %.lr.ph.preheader, %3
  %8 = icmp slt i32 %2, %1
  %9 = sext i32 %2 to i64
  br i1 %8, label %.lr.ph30.preheader, label %.preheader

.lr.ph30.preheader:                               ; preds = %.preheader27
  %wide.trip.count = sext i32 %1 to i64
  %10 = sub nsw i64 %wide.trip.count, %9
  %min.iters.check = icmp ult i64 %10, 8
  %11 = mul nsw i64 %9, -4
  %diff.check = icmp ult i64 %11, 32
  %or.cond = select i1 %min.iters.check, i1 true, i1 %diff.check
  br i1 %or.cond, label %.lr.ph30.preheader37, label %vector.ph

.lr.ph30.preheader37:                             ; preds = %middle.block, %.lr.ph30.preheader
  %indvars.iv.ph = phi i64 [ %9, %.lr.ph30.preheader ], [ %ind.end, %middle.block ]
  %12 = sub nsw i64 %wide.trip.count, %indvars.iv.ph
  %xtraiter = and i64 %12, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph30.prol.loopexit, label %.lr.ph30.prol

.lr.ph30.prol:                                    ; preds = %.lr.ph30.preheader37, %.lr.ph30.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.lr.ph30.prol ], [ %indvars.iv.ph, %.lr.ph30.preheader37 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph30.prol ], [ 0, %.lr.ph30.preheader37 ]
  %13 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.prol
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = sub nsw i64 %indvars.iv.prol, %9
  %16 = getelementptr inbounds i32, ptr %0, i64 %15
  store i32 %14, ptr %16, align 4, !tbaa !5
  %indvars.iv.next.prol = add nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph30.prol.loopexit, label %.lr.ph30.prol, !llvm.loop !9

.lr.ph30.prol.loopexit:                           ; preds = %.lr.ph30.prol, %.lr.ph30.preheader37
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %.lr.ph30.preheader37 ], [ %indvars.iv.next.prol, %.lr.ph30.prol ]
  %17 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %18 = icmp ugt i64 %17, -4
  br i1 %18, label %.preheader, label %.lr.ph30

vector.ph:                                        ; preds = %.lr.ph30.preheader
  %n.vec = and i64 %10, -8
  %ind.end = add nsw i64 %n.vec, %9
  %invariant.gep38 = getelementptr i32, ptr %0, i64 %9
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %gep39 = getelementptr i32, ptr %invariant.gep38, i64 %index
  %19 = getelementptr inbounds i8, ptr %gep39, i64 16
  %wide.load = load <4 x i32>, ptr %gep39, align 4, !tbaa !5
  %wide.load36 = load <4 x i32>, ptr %19, align 4, !tbaa !5
  %20 = getelementptr inbounds i32, ptr %0, i64 %index
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  store <4 x i32> %wide.load, ptr %20, align 4, !tbaa !5
  store <4 x i32> %wide.load36, ptr %21, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %22 = icmp eq i64 %index.next, %n.vec
  br i1 %22, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %10, %n.vec
  br i1 %cmp.n, label %.preheader, label %.lr.ph30.preheader37

.preheader:                                       ; preds = %.lr.ph30.prol.loopexit, %.lr.ph30, %middle.block, %.preheader27
  %23 = sub i32 %1, %2
  %24 = sext i32 %23 to i64
  %invariant.gep = getelementptr i32, ptr %0, i64 %24
  br label %41

.lr.ph30:                                         ; preds = %.lr.ph30.prol.loopexit, %.lr.ph30
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.lr.ph30 ], [ %indvars.iv.unr, %.lr.ph30.prol.loopexit ]
  %25 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = sub nsw i64 %indvars.iv, %9
  %28 = getelementptr inbounds i32, ptr %0, i64 %27
  store i32 %26, ptr %28, align 4, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %29 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sub nsw i64 %indvars.iv.next, %9
  %32 = getelementptr inbounds i32, ptr %0, i64 %31
  store i32 %30, ptr %32, align 4, !tbaa !5
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, 2
  %33 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next.1
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = sub nsw i64 %indvars.iv.next.1, %9
  %36 = getelementptr inbounds i32, ptr %0, i64 %35
  store i32 %34, ptr %36, align 4, !tbaa !5
  %indvars.iv.next.2 = add nsw i64 %indvars.iv, 3
  %37 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next.2
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = sub nsw i64 %indvars.iv.next.2, %9
  %40 = getelementptr inbounds i32, ptr %0, i64 %39
  store i32 %38, ptr %40, align 4, !tbaa !5
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %.preheader, label %.lr.ph30, !llvm.loop !15

41:                                               ; preds = %.preheader, %41
  %indvars.iv33 = phi i64 [ 0, %.preheader ], [ %indvars.iv.next34, %41 ]
  %42 = icmp slt i64 %indvars.iv33, %9
  tail call void @llvm.assume(i1 %42)
  %43 = getelementptr inbounds i32, ptr %5, i64 %indvars.iv33
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %gep = getelementptr i32, ptr %invariant.gep, i64 %indvars.iv33
  store i32 %44, ptr %gep, align 4, !tbaa !5
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  br label %41, !llvm.loop !16
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)
declare void @llvm.assume(i1 noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

attributes #0 = { mustprogress nofree norecurse noreturn nosync nounwind memory(argmem: readwrite, inaccessiblemem: write) 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 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12, !13}
!16 = distinct !{!16, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass