; LLVM IR from tangjz/acm-icpc :: codeforces/complete/317E.ll (Z9innerMoveii)

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

@que = external dso_local global [41209 x i32], align 16
@pre = external dso_local global [41209 x i32], align 16
@_ZL2dx = external hidden constant [4 x i32], align 16
@_ZL2dy = external hidden constant [4 x i32], align 16
@m = external dso_local global i32, align 4
@adt = external dso_local global [41209 x i32], align 16

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6appendv() #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9innerMoveii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  store i32 0, ptr @m, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %8 = load i32, ptr @que, align 16, !tbaa !5
  store i32 %8, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = mul nsw i32 %9, 203
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = add nsw i32 %10, %11
  store i32 %12, ptr %6, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %18, %2
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = icmp ne i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %40

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [41209 x i32], ptr @pre, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  store i32 %22, ptr %7, align 4, !tbaa !5
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = load i32, ptr @m, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr @m, align 4, !tbaa !5
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds [41209 x i32], ptr @adt, i64 0, i64 %26
  store i32 %23, ptr %27, align 4, !tbaa !5
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [4 x i32], ptr @_ZL2dx, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = mul nsw i32 %31, 203
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [4 x i32], ptr @_ZL2dy, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = add nsw i32 %32, %36
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = sub nsw i32 %38, %37
  store i32 %39, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %13, !llvm.loop !9

40:                                               ; preds = %17
  %41 = load i32, ptr @m, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i32, ptr @adt, i64 %42
  call void @_ZSt7reverseIPiEvT_S1_(ptr noundef @adt, ptr noundef %43)
  call void @_Z6appendv()
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt7reverseIPiEvT_S1_(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

@que = external dso_local local_unnamed_addr global [41209 x i32], align 16
@pre = external dso_local local_unnamed_addr global [41209 x i32], align 16
@_ZL2dx = external hidden local_unnamed_addr constant [4 x i32], align 16
@_ZL2dy = external hidden local_unnamed_addr constant [4 x i32], align 16
@m = external dso_local local_unnamed_addr global i32, align 4
@adt = external dso_local global [41209 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6appendv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9innerMoveii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  store i32 0, ptr @m, align 4, !tbaa !5
  %3 = load i32, ptr @que, align 16, !tbaa !5
  %4 = mul nsw i32 %0, 203
  %5 = add nsw i32 %4, %1
  %.not11 = icmp eq i32 %3, %5
  br i1 %.not11, label %8, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  %6 = trunc nuw i64 %indvars.iv.next to i32
  store i32 %6, ptr @m, align 4, !tbaa !5
  %sext = shl i64 %indvars.iv.next, 32
  %7 = ashr exact i64 %sext, 32
  br label %8

8:                                                ; preds = %._crit_edge, %2
  %9 = phi i64 [ %7, %._crit_edge ], [ 0, %2 ]
  %10 = getelementptr inbounds i32, ptr @adt, i64 %9
  tail call void @_ZSt7reverseIPiEvT_S1_(ptr noundef nonnull @adt, ptr noundef nonnull %10)
  tail call void @_Z6appendv()
  ret void

.lr.ph:                                           ; preds = %2, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %2 ]
  %.012 = phi i32 [ %20, %.lr.ph ], [ %5, %2 ]
  %11 = sext i32 %.012 to i64
  %12 = getelementptr inbounds [41209 x i32], ptr @pre, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %14 = getelementptr inbounds [41209 x i32], ptr @adt, i64 0, i64 %indvars.iv
  store i32 %13, ptr %14, align 4, !tbaa !5
  %15 = sext i32 %13 to i64
  %16 = getelementptr inbounds [4 x i32], ptr @_ZL2dx, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = getelementptr inbounds [4 x i32], ptr @_ZL2dy, i64 0, i64 %15
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %.neg = mul i32 %17, -203
  %.neg10 = sub i32 %.012, %19
  %20 = add i32 %.neg10, %.neg
  %.not = icmp eq i32 %3, %20
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt7reverseIPiEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { inlinehint 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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