; LLVM IR from tangjz/acm-icpc :: lydsy/3262.ll (Z5solveii)

; 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.Node = type { i32, i32, i32, i32 }

@f = external dso_local global [100001 x i32], align 16
@tot = external dso_local global i32, align 4
@a = external dso_local global [100001 x %struct.Node], align 16
@b = external dso_local global [100001 x %struct.Node], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3addii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3sumi(i32 noundef) #0

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solveii(i32 noundef %0, i32 noundef %1) #2 {
  %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
  %8 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = icmp eq i32 %9, %10
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  br label %101

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = add nsw i32 %14, %15
  %17 = ashr i32 %16, 1
  store i32 %17, ptr %5, align 4, !tbaa !5
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z5solveii(i32 noundef %18, i32 noundef %19)
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  %22 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z5solveii(i32 noundef %21, i32 noundef %22)
  %23 = load i32, ptr @tot, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr @tot, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %25 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %25, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %8, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %93, %13
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = icmp sle i32 %29, %30
  br i1 %31, label %36, label %32

32:                                               ; preds = %28
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = icmp sle i32 %33, %34
  br label %36

36:                                               ; preds = %32, %28
  %37 = phi i1 [ true, %28 ], [ %35, %32 ]
  br i1 %37, label %39, label %38

38:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %94

39:                                               ; preds = %36
  %40 = load i32, ptr %7, align 4, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = icmp sgt i32 %40, %41
  br i1 %42, label %55, label %43

43:                                               ; preds = %39
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = icmp sle i32 %44, %45
  br i1 %46, label %47, label %79

47:                                               ; preds = %43
  %48 = load i32, ptr %8, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [100001 x %struct.Node], ptr @a, i64 0, i64 %49
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100001 x %struct.Node], ptr @a, i64 0, i64 %52
  %54 = call noundef zeroext i1 @_ZNK4NodeltERKS_(ptr noundef nonnull align 4 dereferenceable(16) %50, ptr noundef nonnull align 4 dereferenceable(16) %53)
  br i1 %54, label %55, label %79

55:                                               ; preds = %47, %39
  %56 = load i32, ptr %8, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [100001 x %struct.Node], ptr @a, i64 0, i64 %57
  %59 = getelementptr inbounds %struct.Node, ptr %58, i32 0, i32 3
  %60 = load i32, ptr %59, align 4, !tbaa !9
  %61 = call noundef i32 @_Z3sumi(i32 noundef %60)
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [100001 x %struct.Node], ptr @a, i64 0, i64 %63
  %65 = getelementptr inbounds %struct.Node, ptr %64, i32 0, i32 0
  %66 = load i32, ptr %65, align 16, !tbaa !11
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = add nsw i32 %69, %61
  store i32 %70, ptr %68, align 4, !tbaa !5
  %71 = load i32, ptr %8, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %8, align 4, !tbaa !5
  %73 = sext i32 %71 to i64
  %74 = getelementptr inbounds [100001 x %struct.Node], ptr @a, i64 0, i64 %73
  %75 = load i32, ptr %6, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %6, align 4, !tbaa !5
  %77 = sext i32 %75 to i64
  %78 = getelementptr inbounds [100001 x %struct.Node], ptr @b, i64 0, i64 %77
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %78, ptr align 16 %74, i64 16, i1 false), !tbaa.struct !12
  br label %93

79:                                               ; preds = %47, %43
  %80 = load i32, ptr %7, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [100001 x %struct.Node], ptr @a, i64 0, i64 %81
  %83 = getelementptr inbounds %struct.Node, ptr %82, i32 0, i32 3
  %84 = load i32, ptr %83, align 4, !tbaa !9
  call void @_Z3addii(i32 noundef %84, i32 noundef 1)
  %85 = load i32, ptr %7, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %7, align 4, !tbaa !5
  %87 = sext i32 %85 to i64
  %88 = getelementptr inbounds [100001 x %struct.Node], ptr @a, i64 0, i64 %87
  %89 = load i32, ptr %6, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %6, align 4, !tbaa !5
  %91 = sext i32 %89 to i64
  %92 = getelementptr inbounds [100001 x %struct.Node], ptr @b, i64 0, i64 %91
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %92, ptr align 16 %88, i64 16, i1 false), !tbaa.struct !12
  br label %93

93:                                               ; preds = %79, %55
  br label %28, !llvm.loop !13

94:                                               ; preds = %38
  %95 = load i32, ptr %3, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds %struct.Node, ptr @a, i64 %96
  %98 = load i32, ptr %6, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = mul i64 %99, 16
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %97, ptr align 16 @b, i64 %100, i1 false)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %101

101:                                              ; preds = %94, %12
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4NodeltERKS_(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16)) #0 align 2

; 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) #3

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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 12}
!10 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!11 = !{!10, !6, i64 0}
!12 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 12, i64 4, !5}
!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"

%struct.Node = type { i32, i32, i32, i32 }

@f = external dso_local local_unnamed_addr global [100001 x i32], align 16
@tot = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local global [100001 x %struct.Node], align 16
@b = external dso_local local_unnamed_addr global [100001 x %struct.Node], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3addii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3sumi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5solveii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %0, %1
  br i1 %3, label %47, label %4

4:                                                ; preds = %2
  %5 = add nsw i32 %1, %0
  %6 = ashr i32 %5, 1
  tail call void @_Z5solveii(i32 noundef %0, i32 noundef %6)
  %7 = add nsw i32 %6, 1
  tail call void @_Z5solveii(i32 noundef %7, i32 noundef %1)
  %8 = load i32, ptr @tot, align 4, !tbaa !5
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr @tot, align 4, !tbaa !5
  %10 = icmp sge i32 %6, %0
  %11 = icmp slt i32 %6, %1
  %12 = or i1 %10, %11
  br i1 %12, label %.lr.ph, label %._crit_edge

._crit_edge.loopexit:                             ; preds = %42
  %13 = shl i64 %indvars.iv.next, 4
  %14 = and i64 %13, 68719476720
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %4
  %.031.lcssa = phi i64 [ 0, %4 ], [ %14, %._crit_edge.loopexit ]
  %15 = sext i32 %0 to i64
  %16 = getelementptr inbounds %struct.Node, ptr @a, i64 %15
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %16, ptr nonnull align 16 @b, i64 %.031.lcssa, i1 false)
  br label %47

.lr.ph:                                           ; preds = %4, %42
  %indvars.iv = phi i64 [ %indvars.iv.next, %42 ], [ 0, %4 ]
  %17 = phi i1 [ %45, %42 ], [ %11, %4 ]
  %.037 = phi i32 [ %.1, %42 ], [ %7, %4 ]
  %.02936 = phi i32 [ %.130, %42 ], [ %0, %4 ]
  %18 = icmp sgt i32 %.02936, %6
  br i1 %18, label %.lr.ph._crit_edge, label %19

.lr.ph._crit_edge:                                ; preds = %.lr.ph
  %.pre = sext i32 %.037 to i64
  br label %26

19:                                               ; preds = %.lr.ph
  br i1 %17, label %20, label %._crit_edge38

._crit_edge38:                                    ; preds = %19
  %.pre39 = sext i32 %.02936 to i64
  br label %37

20:                                               ; preds = %19
  %21 = sext i32 %.037 to i64
  %22 = getelementptr inbounds [100001 x %struct.Node], ptr @a, i64 0, i64 %21
  %23 = sext i32 %.02936 to i64
  %24 = getelementptr inbounds [100001 x %struct.Node], ptr @a, i64 0, i64 %23
  %25 = tail call noundef zeroext i1 @_ZNK4NodeltERKS_(ptr noundef nonnull align 4 dereferenceable(16) %22, ptr noundef nonnull align 4 dereferenceable(16) %24)
  br i1 %25, label %26, label %37

26:                                               ; preds = %.lr.ph._crit_edge, %20
  %.pre-phi = phi i64 [ %.pre, %.lr.ph._crit_edge ], [ %21, %20 ]
  %27 = getelementptr inbounds [100001 x %struct.Node], ptr @a, i64 0, i64 %.pre-phi
  %28 = getelementptr inbounds i8, ptr %27, i64 12
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = tail call noundef i32 @_Z3sumi(i32 noundef %29)
  %31 = load i32, ptr %27, align 16, !tbaa !11
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = add nsw i32 %34, %30
  store i32 %35, ptr %33, align 4, !tbaa !5
  %36 = add nsw i32 %.037, 1
  br label %42

37:                                               ; preds = %._crit_edge38, %20
  %.pre-phi40 = phi i64 [ %.pre39, %._crit_edge38 ], [ %23, %20 ]
  %38 = getelementptr inbounds [100001 x %struct.Node], ptr @a, i64 0, i64 %.pre-phi40
  %39 = getelementptr inbounds i8, ptr %38, i64 12
  %40 = load i32, ptr %39, align 4, !tbaa !9
  tail call void @_Z3addii(i32 noundef %40, i32 noundef 1)
  %41 = add nsw i32 %.02936, 1
  br label %42

42:                                               ; preds = %37, %26
  %.sink41 = phi ptr [ %38, %37 ], [ %27, %26 ]
  %.130 = phi i32 [ %41, %37 ], [ %.02936, %26 ]
  %.1 = phi i32 [ %.037, %37 ], [ %36, %26 ]
  %43 = getelementptr inbounds [100001 x %struct.Node], ptr @b, i64 0, i64 %indvars.iv
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %43, ptr noundef nonnull align 16 dereferenceable(16) %.sink41, i64 16, i1 false)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %44 = icmp sle i32 %.130, %6
  %45 = icmp sle i32 %.1, %1
  %46 = select i1 %44, i1 true, i1 %45
  br i1 %46, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !12

47:                                               ; preds = %2, %._crit_edge
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4NodeltERKS_(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress 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) #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 = { mustprogress 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 = !{!10, !6, i64 12}
!10 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!11 = !{!10, !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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