; LLVM IR from kazunetakahashi/atcoder :: 2019/0615_diverta2019-2/D2.ll (Z5solveix)

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

@g = external dso_local global [2 x i64], align 16
@s = external dso_local global [2 x i64], align 16
@b = external dso_local global [2 x i64], 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
define dso_local noundef i64 @_Z5solveix(i32 noundef %0, i64 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %10 = load i64, ptr %4, align 8, !tbaa !9
  %11 = add nsw i64 %10, 1
  %12 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %11, i64 8)
  %13 = extractvalue { i64, i1 } %12, 1
  %14 = extractvalue { i64, i1 } %12, 0
  %15 = select i1 %13, i64 -1, i64 %14
  %16 = call noalias noundef nonnull ptr @_Znam(i64 noundef %15) #6
  store ptr %16, ptr %5, align 8, !tbaa !11
  %17 = load ptr, ptr %5, align 8, !tbaa !11
  %18 = getelementptr inbounds i64, ptr %17, i64 0
  store i64 0, ptr %18, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %140, %2
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = load i64, ptr %4, align 8, !tbaa !9
  %23 = icmp sle i64 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %143

25:                                               ; preds = %19
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = load ptr, ptr %5, align 8, !tbaa !11
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i64, ptr %28, i64 %30
  store i64 %27, ptr %31, align 8, !tbaa !9
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [2 x i64], ptr @g, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = sub nsw i64 %33, %37
  %39 = icmp sge i64 %38, 0
  br i1 %39, label %40, label %67

40:                                               ; preds = %25
  %41 = load ptr, ptr %5, align 8, !tbaa !11
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i64, ptr %41, i64 %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %45 = load ptr, ptr %5, align 8, !tbaa !11
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [2 x i64], ptr @g, i64 0, i64 %49
  %51 = load i64, ptr %50, align 8, !tbaa !9
  %52 = sub nsw i64 %47, %51
  %53 = getelementptr inbounds i64, ptr %45, i64 %52
  %54 = load i64, ptr %53, align 8, !tbaa !9
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = sub nsw i32 1, %55
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [2 x i64], ptr @g, i64 0, i64 %57
  %59 = load i64, ptr %58, align 8, !tbaa !9
  %60 = add nsw i64 %54, %59
  store i64 %60, ptr %7, align 8, !tbaa !9
  %61 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %44, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %62 = load i64, ptr %61, align 8, !tbaa !9
  %63 = load ptr, ptr %5, align 8, !tbaa !11
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i64, ptr %63, i64 %65
  store i64 %62, ptr %66, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %67

67:                                               ; preds = %40, %25
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = load i32, ptr %3, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [2 x i64], ptr @s, i64 0, i64 %71
  %73 = load i64, ptr %72, align 8, !tbaa !9
  %74 = sub nsw i64 %69, %73
  %75 = icmp sge i64 %74, 0
  br i1 %75, label %76, label %103

76:                                               ; preds = %67
  %77 = load ptr, ptr %5, align 8, !tbaa !11
  %78 = load i32, ptr %6, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds i64, ptr %77, i64 %79
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %81 = load ptr, ptr %5, align 8, !tbaa !11
  %82 = load i32, ptr %6, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = load i32, ptr %3, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [2 x i64], ptr @s, i64 0, i64 %85
  %87 = load i64, ptr %86, align 8, !tbaa !9
  %88 = sub nsw i64 %83, %87
  %89 = getelementptr inbounds i64, ptr %81, i64 %88
  %90 = load i64, ptr %89, align 8, !tbaa !9
  %91 = load i32, ptr %3, align 4, !tbaa !5
  %92 = sub nsw i32 1, %91
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [2 x i64], ptr @s, i64 0, i64 %93
  %95 = load i64, ptr %94, align 8, !tbaa !9
  %96 = add nsw i64 %90, %95
  store i64 %96, ptr %8, align 8, !tbaa !9
  %97 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %80, ptr noundef nonnull align 8 dereferenceable(8) %8)
  %98 = load i64, ptr %97, align 8, !tbaa !9
  %99 = load ptr, ptr %5, align 8, !tbaa !11
  %100 = load i32, ptr %6, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds i64, ptr %99, i64 %101
  store i64 %98, ptr %102, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %103

103:                                              ; preds = %76, %67
  %104 = load i32, ptr %6, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = load i32, ptr %3, align 4, !tbaa !5
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds [2 x i64], ptr @b, i64 0, i64 %107
  %109 = load i64, ptr %108, align 8, !tbaa !9
  %110 = sub nsw i64 %105, %109
  %111 = icmp sge i64 %110, 0
  br i1 %111, label %112, label %139

112:                                              ; preds = %103
  %113 = load ptr, ptr %5, align 8, !tbaa !11
  %114 = load i32, ptr %6, align 4, !tbaa !5
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds i64, ptr %113, i64 %115
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %117 = load ptr, ptr %5, align 8, !tbaa !11
  %118 = load i32, ptr %6, align 4, !tbaa !5
  %119 = sext i32 %118 to i64
  %120 = load i32, ptr %3, align 4, !tbaa !5
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds [2 x i64], ptr @b, i64 0, i64 %121
  %123 = load i64, ptr %122, align 8, !tbaa !9
  %124 = sub nsw i64 %119, %123
  %125 = getelementptr inbounds i64, ptr %117, i64 %124
  %126 = load i64, ptr %125, align 8, !tbaa !9
  %127 = load i32, ptr %3, align 4, !tbaa !5
  %128 = sub nsw i32 1, %127
  %129 = sext i32 %128 to i64
  %130 = getelementptr inbounds [2 x i64], ptr @b, i64 0, i64 %129
  %131 = load i64, ptr %130, align 8, !tbaa !9
  %132 = add nsw i64 %126, %131
  store i64 %132, ptr %9, align 8, !tbaa !9
  %133 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %116, ptr noundef nonnull align 8 dereferenceable(8) %9)
  %134 = load i64, ptr %133, align 8, !tbaa !9
  %135 = load ptr, ptr %5, align 8, !tbaa !11
  %136 = load i32, ptr %6, align 4, !tbaa !5
  %137 = sext i32 %136 to i64
  %138 = getelementptr inbounds i64, ptr %135, i64 %137
  store i64 %134, ptr %138, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %139

139:                                              ; preds = %112, %103
  br label %140

140:                                              ; preds = %139
  %141 = load i32, ptr %6, align 4, !tbaa !5
  %142 = add nsw i32 %141, 1
  store i32 %142, ptr %6, align 4, !tbaa !5
  br label %19, !llvm.loop !13

143:                                              ; preds = %24
  %144 = load ptr, ptr %5, align 8, !tbaa !11
  %145 = load i64, ptr %4, align 8, !tbaa !9
  %146 = getelementptr inbounds i64, ptr %144, i64 %145
  %147 = load i64, ptr %146, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret i64 %147
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #4

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nobuiltin allocsize(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 = { 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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }

!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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!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"

@g = external dso_local local_unnamed_addr global [2 x i64], align 16
@s = external dso_local local_unnamed_addr global [2 x i64], align 16
@b = external dso_local local_unnamed_addr global [2 x i64], align 16

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z5solveix(i32 noundef %0, i64 noundef %1) local_unnamed_addr #1 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = add nsw i64 %1, 1
  %7 = icmp ugt i64 %6, 2305843009213693951
  %8 = shl nuw i64 %6, 3
  %9 = select i1 %7, i64 -1, i64 %8
  %10 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %9) #4
  store i64 0, ptr %10, align 8, !tbaa !5
  %.not44 = icmp slt i64 %1, 1
  br i1 %.not44, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %11 = sext i32 %0 to i64
  %12 = getelementptr inbounds [2 x i64], ptr @g, i64 0, i64 %11
  %13 = sub nsw i32 1, %0
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [2 x i64], ptr @g, i64 0, i64 %14
  %16 = getelementptr inbounds [2 x i64], ptr @s, i64 0, i64 %11
  %17 = getelementptr inbounds [2 x i64], ptr @s, i64 0, i64 %14
  %18 = getelementptr inbounds [2 x i64], ptr @b, i64 0, i64 %11
  %19 = getelementptr inbounds [2 x i64], ptr @b, i64 0, i64 %14
  br label %22

._crit_edge:                                      ; preds = %53, %2
  %20 = getelementptr inbounds i64, ptr %10, i64 %1
  %21 = load i64, ptr %20, align 8, !tbaa !5
  ret i64 %21

22:                                               ; preds = %.lr.ph, %53
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %53 ]
  %23 = getelementptr inbounds i64, ptr %10, i64 %indvars.iv
  store i64 %indvars.iv, ptr %23, align 8, !tbaa !5
  %24 = load i64, ptr %12, align 8, !tbaa !5
  %.not41 = icmp sgt i64 %24, %indvars.iv
  br i1 %.not41, label %33, label %25

25:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  %26 = sub nsw i64 %indvars.iv, %24
  %27 = getelementptr inbounds i64, ptr %10, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = load i64, ptr %15, align 8, !tbaa !5
  %30 = add nsw i64 %29, %28
  store i64 %30, ptr %3, align 8, !tbaa !5
  %31 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %23, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %32 = load i64, ptr %31, align 8, !tbaa !5
  store i64 %32, ptr %23, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  br label %33

33:                                               ; preds = %25, %22
  %34 = load i64, ptr %16, align 8, !tbaa !5
  %.not42 = icmp sgt i64 %34, %indvars.iv
  br i1 %.not42, label %43, label %35

35:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  %36 = sub nsw i64 %indvars.iv, %34
  %37 = getelementptr inbounds i64, ptr %10, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !5
  %39 = load i64, ptr %17, align 8, !tbaa !5
  %40 = add nsw i64 %39, %38
  store i64 %40, ptr %4, align 8, !tbaa !5
  %41 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %23, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %42 = load i64, ptr %41, align 8, !tbaa !5
  store i64 %42, ptr %23, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  br label %43

43:                                               ; preds = %35, %33
  %44 = load i64, ptr %18, align 8, !tbaa !5
  %.not43 = icmp sgt i64 %44, %indvars.iv
  br i1 %.not43, label %53, label %45

45:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  %46 = sub nsw i64 %indvars.iv, %44
  %47 = getelementptr inbounds i64, ptr %10, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !5
  %49 = load i64, ptr %19, align 8, !tbaa !5
  %50 = add nsw i64 %49, %48
  store i64 %50, ptr %5, align 8, !tbaa !5
  %51 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %23, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %52 = load i64, ptr %51, align 8, !tbaa !5
  store i64 %52, ptr %23, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  br label %53

53:                                               ; preds = %43, %45
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.not.not = icmp slt i64 %indvars.iv, %1
  br i1 %.not.not, label %22, label %._crit_edge, !llvm.loop !9
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { nobuiltin allocsize(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 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 #4 = { builtin allocsize(0) }
attributes #5 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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