; LLVM IR from tangjz/acm-icpc :: codeforces/gym/101471D.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 %106

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 = %87, %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 %90

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 %53

40:                                               ; preds = %28
  %41 = load i32, ptr %11, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @b, i64 0, i64 %42
  %44 = getelementptr inbounds %"struct.std::pair", ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !11
  %46 = load i32, ptr %9, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %47
  %49 = getelementptr inbounds %"struct.std::pair", ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !11
  %51 = icmp slt i32 %45, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %40
  br label %87

53:                                               ; preds = %40, %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %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 0
  %58 = load i32, ptr %57, align 8, !tbaa !9
  %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 0
  %63 = load i32, ptr %62, align 8, !tbaa !9
  %64 = sub nsw i32 %58, %63
  %65 = sext i32 %64 to i64
  %66 = load i32, ptr %11, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @b, i64 0, i64 %67
  %69 = getelementptr inbounds %"struct.std::pair", ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 4, !tbaa !11
  %71 = load i32, ptr %9, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [500001 x %"struct.std::pair"], ptr @a, i64 0, i64 %72
  %74 = getelementptr inbounds %"struct.std::pair", ptr %73, i32 0, i32 1
  %75 = load i32, ptr %74, align 4, !tbaa !11
  %76 = sub nsw i32 %70, %75
  %77 = sext i32 %76 to i64
  %78 = mul nsw i64 %65, %77
  store i64 %78, ptr %12, align 8, !tbaa !12
  %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 %12, align 8, !tbaa !12
  %83 = call noundef zeroext i1 @_Z3updRxx(ptr noundef nonnull align 8 dereferenceable(8) %81, i64 noundef %82)
  br i1 %83, label %84, label %86

84:                                               ; preds = %53
  %85 = load i32, ptr %11, align 4, !tbaa !5
  store i32 %85, ptr %10, align 4, !tbaa !5
  br label %86

86:                                               ; preds = %84, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %87

87:                                               ; preds = %86, %52
  %88 = load i32, ptr %11, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %11, align 4, !tbaa !5
  br label %23, !llvm.loop !14

90:                                               ; preds = %27
  %91 = load i32, ptr %9, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [500001 x i64], ptr @f, i64 0, i64 %92
  %94 = load i64, ptr %93, align 8, !tbaa !12
  %95 = call noundef zeroext i1 @_Z3updRxx(ptr noundef nonnull align 8 dereferenceable(8) @ans, i64 noundef %94)
  %96 = load i32, ptr %5, align 4, !tbaa !5
  %97 = load i32, ptr %9, align 4, !tbaa !5
  %98 = sub nsw i32 %97, 1
  %99 = load i32, ptr %7, align 4, !tbaa !5
  %100 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z5solveiiii(i32 noundef %96, i32 noundef %98, i32 noundef %99, i32 noundef %100)
  %101 = load i32, ptr %9, align 4, !tbaa !5
  %102 = add nsw i32 %101, 1
  %103 = load i32, ptr %6, align 4, !tbaa !5
  %104 = load i32, ptr %10, align 4, !tbaa !5
  %105 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z5solveiiii(i32 noundef %102, i32 noundef %103, i32 noundef %104, i32 noundef %105)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %106

106:                                              ; preds = %90, %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
  %.pre44 = 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 %.pre44
  %10 = getelementptr inbounds i8, ptr %9, i64 4
  %11 = getelementptr inbounds [500001 x i64], ptr @f, i64 0, i64 %.pre44
  %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 %.pre44
  %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
  %23 = getelementptr inbounds i8, ptr %19, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !12
  %25 = load i32, ptr %10, align 4, !tbaa !12
  %26 = icmp slt i32 %24, %25
  %or.cond = select i1 %22, i1 %26, i1 false
  br i1 %or.cond, label %34, label %._crit_edge

._crit_edge:                                      ; preds = %18
  %27 = sub nsw i32 %20, %21
  %28 = sext i32 %27 to i64
  %29 = sub nsw i32 %24, %25
  %30 = sext i32 %29 to i64
  %31 = mul nsw i64 %30, %28
  %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, %._crit_edge
  %.2 = phi i32 [ %spec.select, %._crit_edge ], [ %.037, %18 ]
  %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: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass