; LLVM IR from tangjz/acm-icpc :: loj/6473.ll (Z5solveiiii)

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

%"struct.std::pair" = type { i32, i32 }

@a = external dso_local global [500001 x %"struct.std::pair"], align 16
@b = external dso_local global [500001 x %"struct.std::pair"], align 16
@f = external dso_local global [500001 x i64], align 16
@ans = external dso_local global i64, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solveiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %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 i64, align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = icmp sgt i32 %13, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %4
  br label %94

17:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = add nsw i32 %18, %19
  %21 = ashr i32 %20, 1
  store i32 %21, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %22 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %22, ptr %11, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %75, %17
  %24 = load i32, ptr %11, align 4, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = icmp sle i32 %24, %25
  br i1 %26, label %28, label %27

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

28:                                               ; preds = %23
  %29 = load i32, ptr %11, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @b, i64 0, i64 %30
  %32 = getelementptr inbounds %"struct.std::pair", ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !9
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %35
  %37 = getelementptr inbounds %"struct.std::pair", ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !9
  %39 = icmp slt i32 %33, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %28
  br label %75

41:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %42 = load i32, ptr %11, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @b, i64 0, i64 %43
  %45 = getelementptr inbounds %"struct.std::pair", ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 8, !tbaa !9
  %47 = load i32, ptr %9, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %48
  %50 = getelementptr inbounds %"struct.std::pair", ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 8, !tbaa !9
  %52 = sub nsw i32 %46, %51
  %53 = sext i32 %52 to i64
  %54 = load i32, ptr %11, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @b, i64 0, i64 %55
  %57 = getelementptr inbounds %"struct.std::pair", ptr %56, i32 0, i32 1
  %58 = load i32, ptr %57, align 4, !tbaa !11
  %59 = load i32, ptr %9, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %60
  %62 = getelementptr inbounds %"struct.std::pair", ptr %61, i32 0, i32 1
  %63 = load i32, ptr %62, align 4, !tbaa !11
  %64 = sub nsw i32 %58, %63
  %65 = sext i32 %64 to i64
  %66 = mul nsw i64 %53, %65
  store i64 %66, ptr %12, align 8, !tbaa !12
  %67 = load i32, ptr %9, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [500001 x i64], ptr @f, i64 0, i64 %68
  %70 = load i64, ptr %12, align 8, !tbaa !12
  %71 = call noundef zeroext i1 @_Z3updRxx(ptr noundef nonnull align 8 dereferenceable(8) %69, i64 noundef %70)
  br i1 %71, label %72, label %74

72:                                               ; preds = %41
  %73 = load i32, ptr %11, align 4, !tbaa !5
  store i32 %73, ptr %10, align 4, !tbaa !5
  br label %74

74:                                               ; preds = %72, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %75

75:                                               ; preds = %74, %40
  %76 = load i32, ptr %11, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %11, align 4, !tbaa !5
  br label %23, !llvm.loop !14

78:                                               ; preds = %27
  %79 = load i32, ptr %9, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [500001 x i64], ptr @f, i64 0, i64 %80
  %82 = load i64, ptr %81, align 8, !tbaa !12
  %83 = call noundef zeroext i1 @_Z3updRxx(ptr noundef nonnull align 8 dereferenceable(8) @ans, i64 noundef %82)
  %84 = load i32, ptr %5, align 4, !tbaa !5
  %85 = load i32, ptr %9, align 4, !tbaa !5
  %86 = sub nsw i32 %85, 1
  %87 = load i32, ptr %7, align 4, !tbaa !5
  %88 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z5solveiiii(i32 noundef %84, i32 noundef %86, i32 noundef %87, i32 noundef %88)
  %89 = load i32, ptr %9, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  %91 = load i32, ptr %6, align 4, !tbaa !5
  %92 = load i32, ptr %10, align 4, !tbaa !5
  %93 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z5solveiiii(i32 noundef %90, i32 noundef %91, i32 noundef %92, i32 noundef %93)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %94

94:                                               ; preds = %78, %16
  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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3updRxx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #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 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 = { inlinehint 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 #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 = !{!10, !6, i64 0}
!10 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

%"struct.std::pair" = type { i32, i32 }

@a = external dso_local local_unnamed_addr global [500001 x %"struct.std::pair"], align 16
@b = external dso_local local_unnamed_addr global [500001 x %"struct.std::pair"], align 16
@f = external dso_local global [500001 x i64], align 16
@ans = external dso_local global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5solveiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %0, %1
  br i1 %5, label %tailrecurse._crit_edge, label %.lr.ph41.preheader

.lr.ph41.preheader:                               ; preds = %4
  %6 = add i32 %3, 1
  br label %.lr.ph41

.lr.ph41:                                         ; preds = %.lr.ph41.preheader, %tailrecurse
  %.tr3339 = phi i32 [ %.0.lcssa, %tailrecurse ], [ %2, %.lr.ph41.preheader ]
  %.tr38 = phi i32 [ %17, %tailrecurse ], [ %0, %.lr.ph41.preheader ]
  %7 = add nsw i32 %.tr38, %1
  %8 = ashr i32 %7, 1
  %.not35 = icmp sgt i32 %.tr3339, %3
  %.pre = sext i32 %8 to i64
  br i1 %.not35, label %tailrecurse, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph41
  %9 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %.pre
  %10 = getelementptr inbounds i8, ptr %9, i64 4
  %11 = getelementptr inbounds [500001 x i64], ptr @f, i64 0, i64 %.pre
  %12 = sext i32 %.tr3339 to i64
  br label %18

tailrecurse:                                      ; preds = %34, %.lr.ph41
  %.0.lcssa = phi i32 [ undef, %.lr.ph41 ], [ %.2, %34 ]
  %13 = getelementptr inbounds [500001 x i64], ptr @f, i64 0, i64 %.pre
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = tail call noundef zeroext i1 @_Z3updRxx(ptr noundef nonnull align 8 dereferenceable(8) @ans, i64 noundef %14)
  %16 = add nsw i32 %8, -1
  tail call void @_Z5solveiiii(i32 noundef %.tr38, i32 noundef %16, i32 noundef %.tr3339, i32 noundef %.0.lcssa)
  %17 = add nsw i32 %8, 1
  %.not = icmp slt i32 %8, %1
  br i1 %.not, label %.lr.ph41, label %tailrecurse._crit_edge

18:                                               ; preds = %.lr.ph, %34
  %indvars.iv = phi i64 [ %12, %.lr.ph ], [ %indvars.iv.next, %34 ]
  %.037 = phi i32 [ undef, %.lr.ph ], [ %.2, %34 ]
  %19 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @b, i64 0, i64 %indvars.iv
  %20 = load i32, ptr %19, align 8, !tbaa !9
  %21 = load i32, ptr %9, align 8, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %34, label %23

23:                                               ; preds = %18
  %24 = sub nsw i32 %20, %21
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %19, i64 4
  %27 = load i32, ptr %26, align 4, !tbaa !12
  %28 = load i32, ptr %10, align 4, !tbaa !12
  %29 = sub nsw i32 %27, %28
  %30 = sext i32 %29 to i64
  %31 = mul nsw i64 %30, %25
  %32 = tail call noundef zeroext i1 @_Z3updRxx(ptr noundef nonnull align 8 dereferenceable(8) %11, i64 noundef %31)
  %33 = trunc nsw i64 %indvars.iv to i32
  %spec.select = select i1 %32, i32 %33, i32 %.037
  br label %34

34:                                               ; preds = %18, %23
  %.2 = phi i32 [ %.037, %18 ], [ %spec.select, %23 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
  %exitcond.not = icmp eq i32 %6, %lftr.wideiv
  br i1 %exitcond.not, label %tailrecurse, label %18, !llvm.loop !13

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %4
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3updRxx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #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 = { inlinehint 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" }

!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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTSSt4pairIiiE", !11, i64 0, !11, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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