; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2017-18/Open 2018/Plat/sort.ll (Z7processSt4pairIiiE)

; 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.anon = type { [131072 x i32] }
%"struct.std::pair" = type { i32, i32 }

@ans = external dso_local global i64, align 8
@cur = external dso_local global [131071 x i32], align 16
@BIT = external hidden global %struct.anon, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7processSt4pairIiiE(i64 %0) #0 {
  %2 = alloca %"struct.std::pair", align 4
  %3 = alloca i32, align 4
  store i64 %0, ptr %2, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %4 = call noundef i32 @"_ZN3$_07getlst0Ev"(ptr noundef nonnull align 4 dereferenceable(524288) @BIT)
  store i32 %4, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds %"struct.std::pair", ptr %2, i32 0, i32 1
  %6 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = call noundef i32 @"_ZN3$_05queryEi"(ptr noundef nonnull align 4 dereferenceable(524288) @BIT, i32 noundef %7)
  %9 = sext i32 %8 to i64
  %10 = load i64, ptr @ans, align 8, !tbaa !9
  %11 = add nsw i64 %10, %9
  store i64 %11, ptr @ans, align 8, !tbaa !9
  %12 = getelementptr inbounds %"struct.std::pair", ptr %2, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !11
  call void @"_ZN3$_03updEii"(ptr noundef nonnull align 4 dereferenceable(524288) @BIT, i32 noundef %13, i32 noundef -1)
  %14 = getelementptr inbounds %"struct.std::pair", ptr %2, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [131071 x i32], ptr @cur, i64 0, i64 %16
  store i32 0, ptr %17, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @"_ZN3$_07getlst0Ev"(ptr noundef nonnull align 4 dereferenceable(524288)) #2 align 2

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @"_ZN3$_05queryEi"(ptr noundef nonnull align 4 dereferenceable(524288), i32 noundef) #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @"_ZN3$_03updEii"(ptr noundef nonnull align 4 dereferenceable(524288), i32 noundef, i32 noundef) #2 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 = { 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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !6, i64 4}
!12 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}


; 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.anon = type { [131072 x i32] }
%"struct.std::pair" = type { i32, i32 }

@ans = external dso_local local_unnamed_addr global i64, align 8
@cur = external dso_local local_unnamed_addr global [131071 x i32], align 16
@BIT = external hidden global %struct.anon, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7processSt4pairIiiE(i64 %0) local_unnamed_addr #0 {
  %2 = alloca %"struct.std::pair", align 8
  %3 = alloca i32, align 4
  store i64 %0, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  %4 = tail call noundef i32 @"_ZN3$_07getlst0Ev"(ptr noundef nonnull align 4 dereferenceable(524288) @BIT)
  store i32 %4, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %2, i64 4
  %6 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = call noundef i32 @"_ZN3$_05queryEi"(ptr noundef nonnull align 4 dereferenceable(524288) @BIT, i32 noundef %7)
  %9 = sext i32 %8 to i64
  %10 = load i64, ptr @ans, align 8, !tbaa !9
  %11 = add nsw i64 %10, %9
  store i64 %11, ptr @ans, align 8, !tbaa !9
  %12 = load i32, ptr %5, align 4, !tbaa !11
  call void @"_ZN3$_03updEii"(ptr noundef nonnull align 4 dereferenceable(524288) @BIT, i32 noundef %12, i32 noundef -1)
  %13 = load i32, ptr %5, align 4, !tbaa !11
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [131071 x i32], ptr @cur, i64 0, i64 %14
  store i32 0, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @"_ZN3$_07getlst0Ev"(ptr noundef nonnull align 4 dereferenceable(524288)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @"_ZN3$_05queryEi"(ptr noundef nonnull align 4 dereferenceable(524288), i32 noundef) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @"_ZN3$_03updEii"(ptr noundef nonnull align 4 dereferenceable(524288), i32 noundef, i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 = { 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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !6, i64 4}
!12 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,TailCallElimPass