; LLVM IR from eyangch/competitive-programming :: Codeforces/1618/g.ll (Z2unxx)

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

@par = external dso_local global [400000 x i64], align 16
@sz = external dso_local global [400000 x i64], align 16
@ac = external dso_local global [400000 x i64], align 16
@rv = external dso_local global [400000 x i64], align 16
@tot = external dso_local global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z1pxx(i64 noundef, i64 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z4findx(i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z2unxx(i64 noundef %0, i64 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !5
  %5 = load i64, ptr %3, align 8, !tbaa !5
  %6 = call noundef i64 @_Z4findx(i64 noundef %5)
  store i64 %6, ptr %3, align 8, !tbaa !5
  %7 = load i64, ptr %4, align 8, !tbaa !5
  %8 = call noundef i64 @_Z4findx(i64 noundef %7)
  store i64 %8, ptr %4, align 8, !tbaa !5
  %9 = load i64, ptr %3, align 8, !tbaa !5
  %10 = load i64, ptr %4, align 8, !tbaa !5
  %11 = icmp eq i64 %9, %10
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  br label %74

13:                                               ; preds = %2
  %14 = load i64, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds [400000 x i64], ptr @sz, i64 0, i64 %14
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds [400000 x i64], ptr @sz, i64 0, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = icmp sgt i64 %16, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %13
  call void @_ZSt4swapIxENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4) #3
  br label %22

22:                                               ; preds = %21, %13
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds [400000 x i64], ptr @rv, i64 0, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = load i64, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds [400000 x i64], ptr @ac, i64 0, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = call noundef i64 @_Z1pxx(i64 noundef %25, i64 noundef %28)
  %30 = load i64, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds [400000 x i64], ptr @rv, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = load i64, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds [400000 x i64], ptr @ac, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !5
  %36 = call noundef i64 @_Z1pxx(i64 noundef %32, i64 noundef %35)
  %37 = add nsw i64 %29, %36
  %38 = load i64, ptr @tot, align 8, !tbaa !5
  %39 = sub nsw i64 %38, %37
  store i64 %39, ptr @tot, align 8, !tbaa !5
  %40 = load i64, ptr %4, align 8, !tbaa !5
  %41 = load i64, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds [400000 x i64], ptr @par, i64 0, i64 %41
  store i64 %40, ptr %42, align 8, !tbaa !5
  %43 = load i64, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds [400000 x i64], ptr @sz, i64 0, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !5
  %46 = load i64, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds [400000 x i64], ptr @sz, i64 0, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !5
  %49 = add nsw i64 %48, %45
  store i64 %49, ptr %47, align 8, !tbaa !5
  %50 = load i64, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds [400000 x i64], ptr @ac, i64 0, i64 %50
  %52 = load i64, ptr %51, align 8, !tbaa !5
  %53 = load i64, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds [400000 x i64], ptr @ac, i64 0, i64 %53
  %55 = load i64, ptr %54, align 8, !tbaa !5
  %56 = add nsw i64 %55, %52
  store i64 %56, ptr %54, align 8, !tbaa !5
  %57 = load i64, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds [400000 x i64], ptr @rv, i64 0, i64 %57
  %59 = load i64, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds [400000 x i64], ptr @rv, i64 0, i64 %59
  %61 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %58, ptr noundef nonnull align 8 dereferenceable(8) %60)
  %62 = load i64, ptr %61, align 8, !tbaa !5
  %63 = load i64, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds [400000 x i64], ptr @rv, i64 0, i64 %63
  store i64 %62, ptr %64, align 8, !tbaa !5
  %65 = load i64, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds [400000 x i64], ptr @rv, i64 0, i64 %65
  %67 = load i64, ptr %66, align 8, !tbaa !5
  %68 = load i64, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds [400000 x i64], ptr @ac, i64 0, i64 %68
  %70 = load i64, ptr %69, align 8, !tbaa !5
  %71 = call noundef i64 @_Z1pxx(i64 noundef %67, i64 noundef %70)
  %72 = load i64, ptr @tot, align 8, !tbaa !5
  %73 = add nsw i64 %72, %71
  store i64 %73, ptr @tot, align 8, !tbaa !5
  br label %74

74:                                               ; preds = %22, %12
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIxENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #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)) #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 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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

@par = external dso_local local_unnamed_addr global [400000 x i64], align 16
@sz = external dso_local local_unnamed_addr global [400000 x i64], align 16
@ac = external dso_local local_unnamed_addr global [400000 x i64], align 16
@rv = external dso_local global [400000 x i64], align 16
@tot = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z1pxx(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z4findx(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z2unxx(i64 noundef %0, i64 noundef %1) local_unnamed_addr #1 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = tail call noundef i64 @_Z4findx(i64 noundef %0)
  store i64 %5, ptr %3, align 8, !tbaa !5
  %6 = tail call noundef i64 @_Z4findx(i64 noundef %1)
  store i64 %6, ptr %4, align 8, !tbaa !5
  %7 = icmp eq i64 %5, %6
  br i1 %7, label %55, label %8

8:                                                ; preds = %2
  %9 = getelementptr inbounds [400000 x i64], ptr @sz, i64 0, i64 %5
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds [400000 x i64], ptr @sz, i64 0, i64 %6
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = icmp sgt i64 %10, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %8
  call void @_ZSt4swapIxENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4) #3
  %.pre = load i64, ptr %3, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %14, %8
  %16 = phi i64 [ %.pre, %14 ], [ %5, %8 ]
  %17 = getelementptr inbounds [400000 x i64], ptr @rv, i64 0, i64 %16
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds [400000 x i64], ptr @ac, i64 0, i64 %16
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = call noundef i64 @_Z1pxx(i64 noundef %18, i64 noundef %20)
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds [400000 x i64], ptr @rv, i64 0, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds [400000 x i64], ptr @ac, i64 0, i64 %22
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %27 = call noundef i64 @_Z1pxx(i64 noundef %24, i64 noundef %26)
  %28 = load i64, ptr @tot, align 8, !tbaa !5
  %29 = add i64 %27, %21
  %30 = sub i64 %28, %29
  store i64 %30, ptr @tot, align 8, !tbaa !5
  %31 = load i64, ptr %4, align 8, !tbaa !5
  %32 = load i64, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds [400000 x i64], ptr @par, i64 0, i64 %32
  store i64 %31, ptr %33, align 8, !tbaa !5
  %34 = getelementptr inbounds [400000 x i64], ptr @sz, i64 0, i64 %32
  %35 = load i64, ptr %34, align 8, !tbaa !5
  %36 = getelementptr inbounds [400000 x i64], ptr @sz, i64 0, i64 %31
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = add nsw i64 %37, %35
  store i64 %38, ptr %36, align 8, !tbaa !5
  %39 = getelementptr inbounds [400000 x i64], ptr @ac, i64 0, i64 %32
  %40 = load i64, ptr %39, align 8, !tbaa !5
  %41 = getelementptr inbounds [400000 x i64], ptr @ac, i64 0, i64 %31
  %42 = load i64, ptr %41, align 8, !tbaa !5
  %43 = add nsw i64 %42, %40
  store i64 %43, ptr %41, align 8, !tbaa !5
  %44 = getelementptr inbounds [400000 x i64], ptr @rv, i64 0, i64 %31
  %45 = getelementptr inbounds [400000 x i64], ptr @rv, i64 0, i64 %32
  %46 = 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) %45)
  %47 = load i64, ptr %46, align 8, !tbaa !5
  %48 = load i64, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds [400000 x i64], ptr @rv, i64 0, i64 %48
  store i64 %47, ptr %49, align 8, !tbaa !5
  %50 = getelementptr inbounds [400000 x i64], ptr @ac, i64 0, i64 %48
  %51 = load i64, ptr %50, align 8, !tbaa !5
  %52 = call noundef i64 @_Z1pxx(i64 noundef %47, i64 noundef %51)
  %53 = load i64, ptr @tot, align 8, !tbaa !5
  %54 = add nsw i64 %53, %52
  store i64 %54, ptr @tot, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %2, %15
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIxENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) 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 #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 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,ReassociatePass,SimplifyCFGPass,TailCallElimPass