; LLVM IR from tangjz/acm-icpc :: codeforces/complete/755F.ll (Z9bit_shiftPyiS_)

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

@sz = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z9bit_shiftPyiS_(ptr noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = ashr i32 %10, 6
  store i32 %11, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = and i32 %12, 63
  store i32 %13, ptr %8, align 4, !tbaa !9
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load i32, ptr @sz, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = mul i64 %16, 8
  call void @llvm.memset.p0.i64(ptr align 8 %14, i8 0, i64 %17, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %71, %3
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = add nsw i32 %19, %20
  %22 = load i32, ptr @sz, align 4, !tbaa !9
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

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

25:                                               ; preds = %18
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i64, ptr %26, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !11
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = zext i32 %31 to i64
  %33 = shl i64 %30, %32
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = add nsw i32 %35, %36
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i64, ptr %34, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !11
  %41 = or i64 %40, %33
  store i64 %41, ptr %39, align 8, !tbaa !11
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = add nsw i32 %42, %43
  %45 = add nsw i32 %44, 1
  %46 = load i32, ptr @sz, align 4, !tbaa !9
  %47 = icmp slt i32 %45, %46
  br i1 %47, label %48, label %70

48:                                               ; preds = %25
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %70

51:                                               ; preds = %48
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i64, ptr %52, i64 %54
  %56 = load i64, ptr %55, align 8, !tbaa !11
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = sub nsw i32 64, %57
  %59 = zext i32 %58 to i64
  %60 = lshr i64 %56, %59
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load i32, ptr %9, align 4, !tbaa !9
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = add nsw i32 %62, %63
  %65 = add nsw i32 %64, 1
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds i64, ptr %61, i64 %66
  %68 = load i64, ptr %67, align 8, !tbaa !11
  %69 = or i64 %68, %60
  store i64 %69, ptr %67, align 8, !tbaa !11
  br label %70

70:                                               ; preds = %51, %48, %25
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %9, align 4, !tbaa !9
  br label %18, !llvm.loop !13

74:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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 memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

@sz = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z9bit_shiftPyiS_(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  %4 = ashr i32 %1, 6
  %5 = load i32, ptr @sz, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = shl nsw i64 %6, 3
  tail call void @llvm.memset.p0.i64(ptr align 8 %2, i8 0, i64 %7, i1 false)
  %8 = load i32, ptr @sz, align 4, !tbaa !5
  %9 = icmp slt i32 %4, %8
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %10 = and i32 %1, 63
  %11 = zext nneg i32 %10 to i64
  %.not = icmp eq i32 %10, 0
  %12 = sub nuw nsw i32 64, %10
  %13 = zext nneg i32 %12 to i64
  %14 = sext i32 %4 to i64
  br i1 %.not, label %.lr.ph.split.us.preheader, label %.lr.ph.split.preheader

.lr.ph.split.preheader:                           ; preds = %.lr.ph
  %15 = sext i32 %8 to i64
  %16 = sub i32 %8, %4
  %wide.trip.count = zext i32 %16 to i64
  br label %.lr.ph.split

.lr.ph.split.us.preheader:                        ; preds = %.lr.ph
  %17 = sub i32 %8, %4
  %wide.trip.count30 = zext i32 %17 to i64
  %invariant.gep = getelementptr i64, ptr %2, i64 %14
  %min.iters.check = icmp ult i32 %17, 10
  br i1 %min.iters.check, label %.lr.ph.split.us.preheader38, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph.split.us.preheader
  %18 = shl nuw nsw i64 %wide.trip.count30, 3
  %19 = add nsw i64 %14, %wide.trip.count30
  %20 = shl nsw i64 %19, 3
  %scevgep = getelementptr i8, ptr %2, i64 %20
  %scevgep34 = getelementptr i8, ptr %0, i64 %18
  %bound0 = icmp ult ptr %invariant.gep, %scevgep34
  %bound1 = icmp ugt ptr %scevgep, %0
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %.lr.ph.split.us.preheader38, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %wide.trip.count30, 4294967292
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %21 = getelementptr inbounds i64, ptr %0, i64 %index
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  %wide.load = load <2 x i64>, ptr %21, align 8, !tbaa !9, !alias.scope !11
  %wide.load35 = load <2 x i64>, ptr %22, align 8, !tbaa !9, !alias.scope !11
  %23 = getelementptr i64, ptr %invariant.gep, i64 %index
  %24 = getelementptr i8, ptr %23, i64 16
  %wide.load36 = load <2 x i64>, ptr %23, align 8, !tbaa !9, !alias.scope !14, !noalias !11
  %wide.load37 = load <2 x i64>, ptr %24, align 8, !tbaa !9, !alias.scope !14, !noalias !11
  %25 = or <2 x i64> %wide.load36, %wide.load
  %26 = or <2 x i64> %wide.load37, %wide.load35
  store <2 x i64> %25, ptr %23, align 8, !tbaa !9, !alias.scope !14, !noalias !11
  store <2 x i64> %26, ptr %24, align 8, !tbaa !9, !alias.scope !14, !noalias !11
  %index.next = add nuw i64 %index, 4
  %27 = icmp eq i64 %index.next, %n.vec
  br i1 %27, label %middle.block, label %vector.body, !llvm.loop !16

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count30
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.split.us.preheader38

.lr.ph.split.us.preheader38:                      ; preds = %middle.block, %vector.memcheck, %.lr.ph.split.us.preheader
  %indvars.iv27.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph.split.us.preheader ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %wide.trip.count30, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.split.us.prol.loopexit, label %.lr.ph.split.us.prol

.lr.ph.split.us.prol:                             ; preds = %.lr.ph.split.us.preheader38, %.lr.ph.split.us.prol
  %indvars.iv27.prol = phi i64 [ %indvars.iv.next28.prol, %.lr.ph.split.us.prol ], [ %indvars.iv27.ph, %.lr.ph.split.us.preheader38 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.split.us.prol ], [ 0, %.lr.ph.split.us.preheader38 ]
  %28 = getelementptr inbounds i64, ptr %0, i64 %indvars.iv27.prol
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %gep.prol = getelementptr i64, ptr %invariant.gep, i64 %indvars.iv27.prol
  %30 = load i64, ptr %gep.prol, align 8, !tbaa !9
  %31 = or i64 %30, %29
  store i64 %31, ptr %gep.prol, align 8, !tbaa !9
  %indvars.iv.next28.prol = add nuw nsw i64 %indvars.iv27.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.ph.split.us.prol.loopexit, label %.lr.ph.split.us.prol, !llvm.loop !20

.lr.ph.split.us.prol.loopexit:                    ; preds = %.lr.ph.split.us.prol, %.lr.ph.split.us.preheader38
  %indvars.iv27.unr = phi i64 [ %indvars.iv27.ph, %.lr.ph.split.us.preheader38 ], [ %indvars.iv.next28.prol, %.lr.ph.split.us.prol ]
  %32 = sub nsw i64 %indvars.iv27.ph, %wide.trip.count30
  %33 = icmp ugt i64 %32, -4
  br i1 %33, label %._crit_edge, label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph.split.us.prol.loopexit, %.lr.ph.split.us
  %indvars.iv27 = phi i64 [ %indvars.iv.next28.3, %.lr.ph.split.us ], [ %indvars.iv27.unr, %.lr.ph.split.us.prol.loopexit ]
  %34 = getelementptr inbounds i64, ptr %0, i64 %indvars.iv27
  %35 = load i64, ptr %34, align 8, !tbaa !9
  %gep = getelementptr i64, ptr %invariant.gep, i64 %indvars.iv27
  %36 = load i64, ptr %gep, align 8, !tbaa !9
  %37 = or i64 %36, %35
  store i64 %37, ptr %gep, align 8, !tbaa !9
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %38 = getelementptr inbounds i64, ptr %0, i64 %indvars.iv.next28
  %39 = load i64, ptr %38, align 8, !tbaa !9
  %gep.1 = getelementptr i64, ptr %invariant.gep, i64 %indvars.iv.next28
  %40 = load i64, ptr %gep.1, align 8, !tbaa !9
  %41 = or i64 %40, %39
  store i64 %41, ptr %gep.1, align 8, !tbaa !9
  %indvars.iv.next28.1 = add nuw nsw i64 %indvars.iv27, 2
  %42 = getelementptr inbounds i64, ptr %0, i64 %indvars.iv.next28.1
  %43 = load i64, ptr %42, align 8, !tbaa !9
  %gep.2 = getelementptr i64, ptr %invariant.gep, i64 %indvars.iv.next28.1
  %44 = load i64, ptr %gep.2, align 8, !tbaa !9
  %45 = or i64 %44, %43
  store i64 %45, ptr %gep.2, align 8, !tbaa !9
  %indvars.iv.next28.2 = add nuw nsw i64 %indvars.iv27, 3
  %46 = getelementptr inbounds i64, ptr %0, i64 %indvars.iv.next28.2
  %47 = load i64, ptr %46, align 8, !tbaa !9
  %gep.3 = getelementptr i64, ptr %invariant.gep, i64 %indvars.iv.next28.2
  %48 = load i64, ptr %gep.3, align 8, !tbaa !9
  %49 = or i64 %48, %47
  store i64 %49, ptr %gep.3, align 8, !tbaa !9
  %indvars.iv.next28.3 = add nuw nsw i64 %indvars.iv27, 4
  %exitcond31.not.3 = icmp eq i64 %indvars.iv.next28.3, %wide.trip.count30
  br i1 %exitcond31.not.3, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !22

._crit_edge:                                      ; preds = %65, %.lr.ph.split.us.prol.loopexit, %.lr.ph.split.us, %middle.block, %3
  ret void

.lr.ph.split:                                     ; preds = %.lr.ph.split.preheader, %65
  %indvars.iv = phi i64 [ 0, %.lr.ph.split.preheader ], [ %indvars.iv.next, %65 ]
  %50 = add nsw i64 %indvars.iv, %14
  %51 = getelementptr inbounds i64, ptr %0, i64 %indvars.iv
  %52 = load i64, ptr %51, align 8, !tbaa !9
  %53 = shl i64 %52, %11
  %54 = getelementptr inbounds i64, ptr %2, i64 %50
  %55 = load i64, ptr %54, align 8, !tbaa !9
  %56 = or i64 %55, %53
  store i64 %56, ptr %54, align 8, !tbaa !9
  %57 = add nsw i64 %50, 1
  %58 = icmp slt i64 %57, %15
  br i1 %58, label %59, label %65

59:                                               ; preds = %.lr.ph.split
  %60 = load i64, ptr %51, align 8, !tbaa !9
  %61 = lshr i64 %60, %13
  %62 = getelementptr inbounds i64, ptr %2, i64 %57
  %63 = load i64, ptr %62, align 8, !tbaa !9
  %64 = or i64 %63, %61
  store i64 %64, ptr %62, align 8, !tbaa !9
  br label %65

65:                                               ; preds = %.lr.ph.split, %59
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph.split, !llvm.loop !23
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

!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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12}
!12 = distinct !{!12, !13}
!13 = distinct !{!13, !"LVerDomain"}
!14 = !{!15}
!15 = distinct !{!15, !13}
!16 = distinct !{!16, !17, !18, !19}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.isvectorized", i32 1}
!19 = !{!"llvm.loop.unroll.runtime.disable"}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.unroll.disable"}
!22 = distinct !{!22, !17, !18}
!23 = distinct !{!23, !17}


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