; LLVM IR from eyangch/competitive-programming :: USACOcontests/gold/2014.01/skilevel.ll (Z2unxxx)

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

@T = external dso_local global i64, align 8
@par = external dso_local global [250000 x i64], align 16
@sz = external dso_local global [250000 x i64], align 16
@hstart = external dso_local global [250000 x i64], align 16
@ans = external dso_local global i64, align 8

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

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

14:                                               ; preds = %3
  br label %62

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

23:                                               ; preds = %15
  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) %4, ptr noundef nonnull align 8 dereferenceable(8) %5) #2
  br label %24

24:                                               ; preds = %23, %15
  %25 = load i64, ptr %5, align 8, !tbaa !5
  %26 = load i64, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds [250000 x i64], ptr @par, i64 0, i64 %26
  store i64 %25, ptr %27, align 8, !tbaa !5
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds [250000 x i64], ptr @sz, i64 0, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = load i64, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds [250000 x i64], ptr @sz, i64 0, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = add nsw i64 %33, %30
  store i64 %34, ptr %32, align 8, !tbaa !5
  %35 = load i64, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds [250000 x i64], ptr @hstart, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = load i64, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds [250000 x i64], ptr @hstart, i64 0, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !5
  %41 = add nsw i64 %40, %37
  store i64 %41, ptr %39, align 8, !tbaa !5
  %42 = load i64, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds [250000 x i64], ptr @sz, i64 0, i64 %42
  %44 = load i64, ptr %43, align 8, !tbaa !5
  %45 = load i64, ptr @T, align 8, !tbaa !5
  %46 = icmp sge i64 %44, %45
  br i1 %46, label %47, label %62

47:                                               ; preds = %24
  %48 = load i64, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds [250000 x i64], ptr @hstart, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !5
  %51 = icmp ne i64 %50, 0
  br i1 %51, label %52, label %62

52:                                               ; preds = %47
  %53 = load i64, ptr %6, align 8, !tbaa !5
  %54 = load i64, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds [250000 x i64], ptr @hstart, i64 0, i64 %54
  %56 = load i64, ptr %55, align 8, !tbaa !5
  %57 = mul nsw i64 %53, %56
  %58 = load i64, ptr @ans, align 8, !tbaa !5
  %59 = add nsw i64 %58, %57
  store i64 %59, ptr @ans, align 8, !tbaa !5
  %60 = load i64, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds [250000 x i64], ptr @hstart, i64 0, i64 %60
  store i64 0, ptr %61, align 8, !tbaa !5
  br label %62

62:                                               ; preds = %52, %47, %24, %14
  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)) #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 = { 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 #2 = { 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"

@T = external dso_local local_unnamed_addr global i64, align 8
@par = external dso_local local_unnamed_addr global [250000 x i64], align 16
@sz = external dso_local local_unnamed_addr global [250000 x i64], align 16
@hstart = external dso_local local_unnamed_addr global [250000 x i64], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8

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

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

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

15:                                               ; preds = %9
  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) %4, ptr noundef nonnull align 8 dereferenceable(8) %5) #2
  %.pre = load i64, ptr %5, align 8, !tbaa !5
  %.pre4 = load i64, ptr %4, align 8, !tbaa !5
  %.phi.trans.insert = getelementptr inbounds [250000 x i64], ptr @sz, i64 0, i64 %.pre4
  %.pre5 = load i64, ptr %.phi.trans.insert, align 8, !tbaa !5
  %.phi.trans.insert6 = getelementptr inbounds [250000 x i64], ptr @sz, i64 0, i64 %.pre
  %.pre7 = load i64, ptr %.phi.trans.insert6, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %15, %9
  %17 = phi i64 [ %.pre7, %15 ], [ %13, %9 ]
  %18 = phi i64 [ %.pre5, %15 ], [ %11, %9 ]
  %19 = phi i64 [ %.pre4, %15 ], [ %6, %9 ]
  %20 = phi i64 [ %.pre, %15 ], [ %7, %9 ]
  %21 = getelementptr inbounds [250000 x i64], ptr @par, i64 0, i64 %19
  store i64 %20, ptr %21, align 8, !tbaa !5
  %22 = getelementptr inbounds [250000 x i64], ptr @sz, i64 0, i64 %20
  %23 = add nsw i64 %17, %18
  store i64 %23, ptr %22, align 8, !tbaa !5
  %24 = getelementptr inbounds [250000 x i64], ptr @hstart, i64 0, i64 %19
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = getelementptr inbounds [250000 x i64], ptr @hstart, i64 0, i64 %20
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = add nsw i64 %27, %25
  store i64 %28, ptr %26, align 8, !tbaa !5
  %29 = load i64, ptr @T, align 8, !tbaa !5
  %.not = icmp slt i64 %23, %29
  %.not3 = icmp eq i64 %28, 0
  %or.cond = select i1 %.not, i1 true, i1 %.not3
  br i1 %or.cond, label %34, label %30

30:                                               ; preds = %16
  %31 = mul nsw i64 %28, %2
  %32 = load i64, ptr @ans, align 8, !tbaa !5
  %33 = add nsw i64 %32, %31
  store i64 %33, ptr @ans, align 8, !tbaa !5
  store i64 0, ptr %26, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %3, %30, %16
  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 #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 = { 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 #2 = { 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: BDCEPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass