; LLVM IR from tangjz/acm-icpc :: uvalive/5871.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.Point = type { i32, i32, i32, i32 }

@t = external dso_local global i32, align 4
@ans = external dso_local global [500001 x i32], align 16
@a = external dso_local global [500001 x %struct.Point], align 16

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

; 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
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = icmp eq i32 %7, %8
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  br label %94

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = add nsw i32 %12, %13
  %15 = ashr i32 %14, 1
  store i32 %15, ptr %5, align 4, !tbaa !5
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z5solveii(i32 noundef %16, i32 noundef %17)
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  %20 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z5solveii(i32 noundef %19, i32 noundef %20)
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds %struct.Point, ptr @a, i64 %22
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds %struct.Point, ptr @a, i64 %25
  %27 = getelementptr inbounds %struct.Point, ptr %26, i64 1
  call void @_ZSt4sortIP5PointPFbRKS0_S3_EEvT_S6_T0_(ptr noundef %23, ptr noundef %27, ptr noundef @_Z4cmp2RK5PointS1_)
  %28 = load i32, ptr @t, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr @t, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %30 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %30, ptr %6, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %90, %11
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = icmp sle i32 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %93

36:                                               ; preds = %31
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [500001 x %struct.Point], ptr @a, i64 0, i64 %38
  %40 = getelementptr inbounds %struct.Point, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 16, !tbaa !9
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = icmp sle i32 %41, %42
  br i1 %43, label %44, label %57

44:                                               ; preds = %36
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [500001 x %struct.Point], ptr @a, i64 0, i64 %46
  %48 = getelementptr inbounds %struct.Point, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %48, align 4, !tbaa !11
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %57, label %51

51:                                               ; preds = %44
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [500001 x %struct.Point], ptr @a, i64 0, i64 %53
  %55 = getelementptr inbounds %struct.Point, ptr %54, i32 0, i32 3
  %56 = load i32, ptr %55, align 4, !tbaa !12
  call void @_Z3addii(i32 noundef %56, i32 noundef 1)
  br label %89

57:                                               ; preds = %44, %36
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [500001 x %struct.Point], ptr @a, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.Point, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 16, !tbaa !9
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = icmp sgt i32 %62, %63
  br i1 %64, label %65, label %88

65:                                               ; preds = %57
  %66 = load i32, ptr %6, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [500001 x %struct.Point], ptr @a, i64 0, i64 %67
  %69 = getelementptr inbounds %struct.Point, ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 4, !tbaa !11
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %88

72:                                               ; preds = %65
  %73 = load i32, ptr %6, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [500001 x %struct.Point], ptr @a, i64 0, i64 %74
  %76 = getelementptr inbounds %struct.Point, ptr %75, i32 0, i32 3
  %77 = load i32, ptr %76, align 4, !tbaa !12
  %78 = call noundef i32 @_Z3sumi(i32 noundef %77)
  %79 = load i32, ptr %6, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [500001 x %struct.Point], ptr @a, i64 0, i64 %80
  %82 = getelementptr inbounds %struct.Point, ptr %81, i32 0, i32 1
  %83 = load i32, ptr %82, align 4, !tbaa !11
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [500001 x i32], ptr @ans, i64 0, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = add nsw i32 %86, %78
  store i32 %87, ptr %85, align 4, !tbaa !5
  br label %88

88:                                               ; preds = %72, %65, %57
  br label %89

89:                                               ; preds = %88, %51
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %6, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %6, align 4, !tbaa !5
  br label %31, !llvm.loop !13

93:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %94

94:                                               ; preds = %93, %10
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIP5PointPFbRKS0_S3_EEvT_S6_T0_(ptr noundef, ptr noundef, ptr noundef) #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 = { 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 #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 0}
!10 = !{!"_ZTS5Point", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 12}
!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.Point = type { i32, i32, i32, i32 }

@t = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global [500001 x i32], align 16
@a = external dso_local global [500001 x %struct.Point], align 16

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

; 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 uwtable
define dso_local void @_Z5solveii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = icmp eq i32 %0, %1
  br i1 %3, label %.loopexit, 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 = sext i32 %0 to i64
  %9 = getelementptr inbounds %struct.Point, ptr @a, i64 %8
  %10 = sext i32 %1 to i64
  %11 = getelementptr inbounds %struct.Point, ptr @a, i64 %10
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  tail call void @_ZSt4sortIP5PointPFbRKS0_S3_EEvT_S6_T0_(ptr noundef nonnull %9, ptr noundef nonnull %12, ptr noundef nonnull @_Z4cmp2RK5PointS1_)
  %13 = load i32, ptr @t, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr @t, align 4, !tbaa !5
  %.not28 = icmp sgt i32 %0, %1
  br i1 %.not28, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %15 = add i32 %1, 1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %34
  %indvars.iv = phi i64 [ %8, %.lr.ph.preheader ], [ %indvars.iv.next, %34 ]
  %16 = getelementptr inbounds [500001 x %struct.Point], ptr @a, i64 0, i64 %indvars.iv
  %17 = load i32, ptr %16, align 16, !tbaa !9
  %.not25 = icmp sgt i32 %17, %6
  %18 = getelementptr inbounds i8, ptr %16, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %.not27 = icmp eq i32 %19, 0
  br i1 %.not25, label %24, label %20

20:                                               ; preds = %.lr.ph
  br i1 %.not27, label %21, label %34

21:                                               ; preds = %20
  %22 = getelementptr inbounds i8, ptr %16, i64 12
  %23 = load i32, ptr %22, align 4, !tbaa !12
  tail call void @_Z3addii(i32 noundef %23, i32 noundef 1)
  br label %34

24:                                               ; preds = %.lr.ph
  br i1 %.not27, label %34, label %25

25:                                               ; preds = %24
  %26 = getelementptr inbounds i8, ptr %16, i64 12
  %27 = load i32, ptr %26, align 4, !tbaa !12
  %28 = tail call noundef i32 @_Z3sumi(i32 noundef %27)
  %29 = load i32, ptr %18, align 4, !tbaa !11
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [500001 x i32], ptr @ans, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = add nsw i32 %32, %28
  store i32 %33, ptr %31, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %20, %21, %25, %24
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
  %exitcond.not = icmp eq i32 %15, %lftr.wideiv
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !13

.loopexit:                                        ; preds = %34, %4, %2
  ret void
}

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

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

!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 = !{!"_ZTS5Point", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 12}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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