; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2015-16/Open 2016/Plat (bcs_editorial)

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

@rigP = external dso_local global [501 x %"struct.std::array"], align 16
@dowP = external dso_local global [501 x %"struct.std::array"], 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
declare dso_local i64 @_ZmlRKSt5arrayI2miLm2EES3_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #1

; Function Attrs: mustprogress uwtable
define dso_local i64 @_Z6offsetSt5arrayI2miLm2EESt4pairIiiE(i64 %0, i64 %1) #1 {
  %3 = alloca %"struct.std::array", align 4
  %4 = alloca %"struct.std::array", align 4
  %5 = alloca %"struct.std::pair.0", align 4
  %6 = alloca %"struct.std::array", align 4
  %7 = getelementptr inbounds %"struct.std::array", ptr %4, i32 0, i32 0
  store i64 %0, ptr %7, align 4
  store i64 %1, ptr %5, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %8 = getelementptr inbounds %"struct.std::pair.0", ptr %5, i32 0, i32 0
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [501 x %"struct.std::array"], ptr @dowP, i64 0, i64 %10
  %12 = call i64 @_ZmlRKSt5arrayI2miLm2EES3_(ptr noundef nonnull align 4 dereferenceable(8) %4, ptr noundef nonnull align 4 dereferenceable(8) %11)
  %13 = getelementptr inbounds %"struct.std::array", ptr %6, i32 0, i32 0
  store i64 %12, ptr %13, align 4
  %14 = getelementptr inbounds %"struct.std::pair.0", ptr %5, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !10
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [501 x %"struct.std::array"], ptr @rigP, i64 0, i64 %16
  %18 = call i64 @_ZmlRKSt5arrayI2miLm2EES3_(ptr noundef nonnull align 4 dereferenceable(8) %6, ptr noundef nonnull align 4 dereferenceable(8) %17)
  %19 = getelementptr inbounds %"struct.std::array", ptr %3, i32 0, i32 0
  store i64 %18, ptr %19, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %20 = getelementptr inbounds %"struct.std::array", ptr %3, i32 0, i32 0
  %21 = load i64, ptr %20, align 4
  ret i64 %21
}

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 = { 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, !7, i64 0}
!6 = !{!"_ZTSSt4pairIiiE", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, 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.std::array" = type { [2 x %struct.mi] }
%struct.mi = type { i32 }

@rigP = external dso_local global [501 x %"struct.std::array"], align 16
@dowP = external dso_local global [501 x %"struct.std::array"], 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
declare dso_local i64 @_ZmlRKSt5arrayI2miLm2EES3_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local i64 @_Z6offsetSt5arrayI2miLm2EESt4pairIiiE(i64 %0, i64 %1) local_unnamed_addr #1 {
  %3 = alloca %"struct.std::array", align 8
  %4 = alloca %"struct.std::array", align 8
  store i64 %0, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #2
  %sext = shl i64 %1, 32
  %5 = ashr exact i64 %sext, 32
  %6 = getelementptr inbounds [501 x %"struct.std::array"], ptr @dowP, i64 0, i64 %5
  %7 = call i64 @_ZmlRKSt5arrayI2miLm2EES3_(ptr noundef nonnull align 4 dereferenceable(8) %3, ptr noundef nonnull align 4 dereferenceable(8) %6)
  store i64 %7, ptr %4, align 8
  %8 = ashr i64 %1, 32
  %9 = getelementptr inbounds [501 x %"struct.std::array"], ptr @rigP, i64 0, i64 %8
  %10 = call i64 @_ZmlRKSt5arrayI2miLm2EES3_(ptr noundef nonnull align 4 dereferenceable(8) %4, ptr noundef nonnull align 4 dereferenceable(8) %9)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #2
  ret i64 %10
}

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 = { 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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass