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

; 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::pair" = type { i8, i32 }

@X = external dso_local global i64, align 8
@Y = external dso_local global i64, align 8
@pres = external dso_local global [1000002 x i64], align 16
@prel = external dso_local global [1000002 x i64], align 16
@sufs = external dso_local global [1000002 x i64], align 16
@sufl = external dso_local global [1000002 x i64], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6genpreRSt6vectorISt4pairIciESaIS1_EE(ptr noundef nonnull align 8 dereferenceable(24)) #0

; 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 dso_local noundef i64 @_ZNKSt6vectorISt4pairIciESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIciESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6gensufRSt6vectorISt4pairIciESaIS1_EE(ptr noundef nonnull align 8 dereferenceable(24)) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z4testRSt6vectorISt4pairIciESaIS1_EE(ptr noundef nonnull align 8 dereferenceable(24) %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_Z6genpreRSt6vectorISt4pairIciESaIS1_EE(ptr noundef nonnull align 8 dereferenceable(24) %7)
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = call noundef i64 @_ZNKSt6vectorISt4pairIciESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %8) #4
  %10 = urem i64 %9, 2
  %11 = icmp eq i64 %10, 0
  br i1 %11, label %12, label %21

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = call noundef i64 @_ZNKSt6vectorISt4pairIciESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %13) #4
  %15 = getelementptr inbounds [1000002 x i64], ptr @pres, i64 0, i64 %14
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call noundef i64 @_ZNKSt6vectorISt4pairIciESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %16) #4
  %18 = getelementptr inbounds [1000002 x i64], ptr @prel, i64 0, i64 %17
  %19 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %15, ptr noundef nonnull align 8 dereferenceable(8) %18)
  %20 = load i64, ptr %19, align 8, !tbaa !9
  store i64 %20, ptr %2, align 8
  br label %82

21:                                               ; preds = %1
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_Z6gensufRSt6vectorISt4pairIciESaIS1_EE(ptr noundef nonnull align 8 dereferenceable(24) %22)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 1000000000000000000, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %23

23:                                               ; preds = %77, %21
  %24 = load i32, ptr %5, align 4, !tbaa !11
  %25 = sext i32 %24 to i64
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = call noundef i64 @_ZNKSt6vectorISt4pairIciESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %26) #4
  %28 = udiv i64 %27, 2
  %29 = add i64 %28, 1
  %30 = icmp ult i64 %25, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %80

32:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %33 = load i32, ptr %5, align 4, !tbaa !11
  %34 = mul nsw i32 2, %33
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [1000002 x i64], ptr @prel, i64 0, i64 %35
  %37 = load i32, ptr %5, align 4, !tbaa !11
  %38 = mul nsw i32 2, %37
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [1000002 x i64], ptr @pres, i64 0, i64 %39
  %41 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %36, ptr noundef nonnull align 8 dereferenceable(8) %40)
  %42 = load i64, ptr %41, align 8, !tbaa !9
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = call noundef i64 @_ZNKSt6vectorISt4pairIciESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %43) #4
  %45 = sub i64 %44, 1
  %46 = load i32, ptr %5, align 4, !tbaa !11
  %47 = mul nsw i32 2, %46
  %48 = sext i32 %47 to i64
  %49 = sub i64 %45, %48
  %50 = getelementptr inbounds [1000002 x i64], ptr @sufs, i64 0, i64 %49
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = call noundef i64 @_ZNKSt6vectorISt4pairIciESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %51) #4
  %53 = sub i64 %52, 1
  %54 = load i32, ptr %5, align 4, !tbaa !11
  %55 = mul nsw i32 2, %54
  %56 = sext i32 %55 to i64
  %57 = sub i64 %53, %56
  %58 = getelementptr inbounds [1000002 x i64], ptr @sufl, i64 0, i64 %57
  %59 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %50, ptr noundef nonnull align 8 dereferenceable(8) %58)
  %60 = load i64, ptr %59, align 8, !tbaa !9
  %61 = add nsw i64 %42, %60
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIciESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %62, i64 noundef 0) #4
  %64 = getelementptr inbounds %"struct.std::pair", ptr %63, i32 0, i32 0
  %65 = load i8, ptr %64, align 4, !tbaa !13
  %66 = sext i8 %65 to i32
  %67 = icmp eq i32 %66, 65
  br i1 %67, label %68, label %70

68:                                               ; preds = %32
  %69 = load i64, ptr @Y, align 8, !tbaa !9
  br label %72

70:                                               ; preds = %32
  %71 = load i64, ptr @X, align 8, !tbaa !9
  br label %72

72:                                               ; preds = %70, %68
  %73 = phi i64 [ %69, %68 ], [ %71, %70 ]
  %74 = add nsw i64 %61, %73
  store i64 %74, ptr %6, align 8, !tbaa !9
  %75 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %6)
  %76 = load i64, ptr %75, align 8, !tbaa !9
  store i64 %76, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %77

77:                                               ; preds = %72
  %78 = load i32, ptr %5, align 4, !tbaa !11
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %5, align 4, !tbaa !11
  br label %23, !llvm.loop !15

80:                                               ; preds = %31
  %81 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %81, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %82

82:                                               ; preds = %80, %12
  %83 = load i64, ptr %2, align 8
  ret i64 %83
}

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 = !{!"any pointer", !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 = !{!"int", !7, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"_ZTSSt4pairIciE", !7, i64 0, !12, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@X = external dso_local local_unnamed_addr global i64, align 8
@Y = external dso_local local_unnamed_addr global i64, align 8
@pres = external dso_local global [1000002 x i64], align 16
@prel = external dso_local global [1000002 x i64], align 16
@sufs = external dso_local global [1000002 x i64], align 16
@sufl = external dso_local global [1000002 x i64], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6genpreRSt6vectorISt4pairIciESaIS1_EE(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0

; 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 dso_local noundef i64 @_ZNKSt6vectorISt4pairIciESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIciESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6gensufRSt6vectorISt4pairIciESaIS1_EE(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z4testRSt6vectorISt4pairIciESaIS1_EE(ptr noundef nonnull align 8 dereferenceable(24) %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  tail call void @_Z6genpreRSt6vectorISt4pairIciESaIS1_EE(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %4 = tail call noundef i64 @_ZNKSt6vectorISt4pairIciESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #4
  %5 = and i64 %4, 1
  %6 = icmp eq i64 %5, 0
  br i1 %6, label %7, label %14

7:                                                ; preds = %1
  %8 = tail call noundef i64 @_ZNKSt6vectorISt4pairIciESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #4
  %9 = getelementptr inbounds [1000002 x i64], ptr @pres, i64 0, i64 %8
  %10 = tail call noundef i64 @_ZNKSt6vectorISt4pairIciESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #4
  %11 = getelementptr inbounds [1000002 x i64], ptr @prel, i64 0, i64 %10
  %12 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %9, ptr noundef nonnull align 8 dereferenceable(8) %11)
  %13 = load i64, ptr %12, align 8, !tbaa !5
  br label %45

14:                                               ; preds = %1
  tail call void @_Z6gensufRSt6vectorISt4pairIciESaIS1_EE(ptr noundef nonnull align 8 dereferenceable(24) %0)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  store i64 1000000000000000000, ptr %2, align 8, !tbaa !5
  %15 = tail call noundef i64 @_ZNKSt6vectorISt4pairIciESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #4
  br label %18

16:                                               ; preds = %18
  %17 = load i64, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  br label %45

18:                                               ; preds = %14, %18
  %indvars.iv = phi i64 [ 0, %14 ], [ %indvars.iv.next, %18 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %19 = shl nuw nsw i64 %indvars.iv, 1
  %20 = getelementptr inbounds [1000002 x i64], ptr @prel, i64 0, i64 %19
  %21 = getelementptr inbounds [1000002 x i64], ptr @pres, i64 0, i64 %19
  %22 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %20, ptr noundef nonnull align 8 dereferenceable(8) %21)
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = call noundef i64 @_ZNKSt6vectorISt4pairIciESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #4
  %25 = xor i64 %19, -1
  %26 = add i64 %24, %25
  %27 = getelementptr inbounds [1000002 x i64], ptr @sufs, i64 0, i64 %26
  %28 = call noundef i64 @_ZNKSt6vectorISt4pairIciESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #4
  %29 = add i64 %28, %25
  %30 = getelementptr inbounds [1000002 x i64], ptr @sufl, i64 0, i64 %29
  %31 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %27, ptr noundef nonnull align 8 dereferenceable(8) %30)
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = add nsw i64 %32, %23
  %34 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIciESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #4
  %35 = load i8, ptr %34, align 4, !tbaa !9
  %36 = icmp eq i8 %35, 65
  %37 = load i64, ptr @Y, align 8
  %38 = load i64, ptr @X, align 8
  %39 = select i1 %36, i64 %37, i64 %38
  %40 = add nsw i64 %33, %39
  store i64 %40, ptr %3, align 8, !tbaa !5
  %41 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %42 = load i64, ptr %41, align 8, !tbaa !5
  store i64 %42, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %43 = call noundef i64 @_ZNKSt6vectorISt4pairIciESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #4
  %44 = lshr i64 %43, 1
  %.not.not = icmp ugt i64 %44, %indvars.iv
  br i1 %.not.not, label %18, label %16, !llvm.loop !12

45:                                               ; preds = %16, %7
  %.015 = phi i64 [ %13, %7 ], [ %17, %16 ]
  ret i64 %.015
}

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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !7, i64 0}
!10 = !{!"_ZTSSt4pairIciE", !7, i64 0, !11, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass