; LLVM IR from Aryansh-S/USACO :: USACO/2019/Feb/Gold (cowland)

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

%"class.std::chrono::time_point" = type { %"class.std::chrono::duration" }
%"class.std::chrono::duration" = type { i64 }
%struct.HLD = type { [100000 x %"class.std::vector"], %"class.std::vector", [100000 x i32], [100000 x i32], [100000 x i32], [100000 x i32], [100000 x i32], i32, %struct.LSEG, i64 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.LSEG = type { %"struct.std::pair", %"class.std::vector", i32, i32, %"class.std::vector.0", %"class.std::vector.5", %"class.std::vector.5" }
%"struct.std::pair" = type { i64, i64 }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<std::array<int, 2>, std::allocator<std::array<int, 2>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::array<int, 2>, std::allocator<std::array<int, 2>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::array<int, 2>, std::allocator<std::array<int, 2>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::array<int, 2>, std::allocator<std::array<int, 2>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.5" = type { %"struct.std::_Vector_base.6" }
%"struct.std::_Vector_base.6" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@CLK = external dso_local global %"class.std::chrono::time_point", align 8
@n = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@e = external dso_local global [100000 x i64], align 16
@h = external dso_local global %struct.HLD, align 8
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external global ptr, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8

; 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: nounwind
declare i64 @_ZNSt6chrono3_V212steady_clock3nowEv() #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca %"class.std::chrono::time_point", align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %12 = call noalias ptr @fopen(ptr noundef @.str, ptr noundef @.str.5)
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %19

14:                                               ; preds = %0
  %15 = load ptr, ptr @stdin, align 8, !tbaa !5
  %16 = call ptr @freopen(ptr noundef @.str, ptr noundef @.str.5, ptr noundef %15)
  %17 = load ptr, ptr @stdout, align 8, !tbaa !5
  %18 = call ptr @freopen(ptr noundef @.str.6, ptr noundef @.str.7, ptr noundef %17)
  br label %19

19:                                               ; preds = %14, %0
  %20 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !9
  %21 = getelementptr i8, ptr %20, i64 -24
  %22 = load i64, ptr %21, align 8
  %23 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %22
  %24 = call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %23, ptr noundef null)
  %25 = call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #8
  %26 = call i64 @_ZNSt6chrono3_V212steady_clock3nowEv() #8
  %27 = getelementptr inbounds %"class.std::chrono::time_point", ptr %2, i32 0, i32 0
  %28 = getelementptr inbounds %"class.std::chrono::duration", ptr %27, i32 0, i32 0
  store i64 %26, ptr %28, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 @CLK, ptr align 8 %2, i64 8, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #8
  call void @_ZN7aryansh9io_macros2inIiJiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4) @n, ptr noundef nonnull align 4 dereferenceable(4) @q)
  %29 = load i32, ptr @n, align 4, !tbaa !14
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i64, ptr @e, i64 %30
  call void @_ZN7aryansh9io_macros2inIPxvEEvT_S3_(ptr noundef @e, ptr noundef %31)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #8
  %32 = load i32, ptr @n, align 4, !tbaa !14
  %33 = sub nsw i32 %32, 1
  %34 = icmp sgt i32 0, %33
  %35 = zext i1 %34 to i32
  %36 = sub nsw i32 0, %35
  store i32 %36, ptr %3, align 4, !tbaa !14
  br label %37

37:                                               ; preds = %65, %19
  %38 = load i32, ptr %3, align 4, !tbaa !14
  %39 = load i32, ptr @n, align 4, !tbaa !14
  %40 = sub nsw i32 %39, 1
  %41 = load i32, ptr @n, align 4, !tbaa !14
  %42 = sub nsw i32 %41, 1
  %43 = icmp sgt i32 0, %42
  %44 = zext i1 %43 to i32
  %45 = sub nsw i32 %40, %44
  %46 = icmp ne i32 %38, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #8
  br label %67

48:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #8
  call void @_ZN7aryansh9io_macros2inIiJiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %49 = load i32, ptr %4, align 4, !tbaa !14
  %50 = add nsw i32 %49, -1
  store i32 %50, ptr %4, align 4, !tbaa !14
  %51 = load i32, ptr %5, align 4, !tbaa !14
  %52 = add nsw i32 %51, -1
  store i32 %52, ptr %5, align 4, !tbaa !14
  %53 = load i32, ptr %4, align 4, !tbaa !14
  %54 = load i32, ptr %5, align 4, !tbaa !14
  call void @_ZN3HLDILi100000ELb0EE3addEii(ptr noundef nonnull align 8 dereferenceable(4400160) @h, i32 noundef %53, i32 noundef %54)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #8
  br label %55

55:                                               ; preds = %48
  %56 = load i32, ptr @n, align 4, !tbaa !14
  %57 = sub nsw i32 %56, 1
  %58 = icmp sgt i32 0, %57
  br i1 %58, label %59, label %62

59:                                               ; preds = %55
  %60 = load i32, ptr %3, align 4, !tbaa !14
  %61 = add nsw i32 %60, -1
  store i32 %61, ptr %3, align 4, !tbaa !14
  br label %65

62:                                               ; preds = %55
  %63 = load i32, ptr %3, align 4, !tbaa !14
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %3, align 4, !tbaa !14
  br label %65

65:                                               ; preds = %62, %59
  %66 = phi ptr [ %3, %59 ], [ %3, %62 ]
  br label %37, !llvm.loop !16

67:                                               ; preds = %47
  call void @_ZN3HLDILi100000ELb0EE4initEi(ptr noundef nonnull align 8 dereferenceable(4400160) @h, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #8
  %68 = load i32, ptr @n, align 4, !tbaa !14
  %69 = icmp sgt i32 0, %68
  %70 = zext i1 %69 to i32
  %71 = sub nsw i32 0, %70
  store i32 %71, ptr %6, align 4, !tbaa !14
  br label %72

72:                                               ; preds = %98, %67
  %73 = load i32, ptr %6, align 4, !tbaa !14
  %74 = load i32, ptr @n, align 4, !tbaa !14
  %75 = load i32, ptr @n, align 4, !tbaa !14
  %76 = icmp sgt i32 0, %75
  %77 = zext i1 %76 to i32
  %78 = sub nsw i32 %74, %77
  %79 = icmp ne i32 %73, %78
  br i1 %79, label %81, label %80

80:                                               ; preds = %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #8
  br label %100

81:                                               ; preds = %72
  %82 = load i32, ptr %6, align 4, !tbaa !14
  %83 = load i32, ptr %6, align 4, !tbaa !14
  %84 = load i32, ptr %6, align 4, !tbaa !14
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [100000 x i64], ptr @e, i64 0, i64 %85
  %87 = load i64, ptr %86, align 8, !tbaa !18
  %88 = trunc i64 %87 to i32
  call void @_ZN3HLDILi100000ELb0EE7updpathEiii(ptr noundef nonnull align 8 dereferenceable(4400160) @h, i32 noundef %82, i32 noundef %83, i32 noundef %88)
  br label %89

89:                                               ; preds = %81
  %90 = load i32, ptr @n, align 4, !tbaa !14
  %91 = icmp sgt i32 0, %90
  br i1 %91, label %92, label %95

92:                                               ; preds = %89
  %93 = load i32, ptr %6, align 4, !tbaa !14
  %94 = add nsw i32 %93, -1
  store i32 %94, ptr %6, align 4, !tbaa !14
  br label %98

95:                                               ; preds = %89
  %96 = load i32, ptr %6, align 4, !tbaa !14
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %6, align 4, !tbaa !14
  br label %98

98:                                               ; preds = %95, %92
  %99 = phi ptr [ %6, %92 ], [ %6, %95 ]
  br label %72, !llvm.loop !20

100:                                              ; preds = %80
  br label %101

101:                                              ; preds = %122, %100
  %102 = load i32, ptr @q, align 4, !tbaa !14
  %103 = add nsw i32 %102, -1
  store i32 %103, ptr @q, align 4, !tbaa !14
  %104 = icmp ne i32 %102, 0
  br i1 %104, label %105, label %123

105:                                              ; preds = %101
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #8
  call void @_ZN7aryansh9io_macros2inIivEEvRT_(ptr noundef nonnull align 4 dereferenceable(4) %7)
  %106 = load i32, ptr %7, align 4, !tbaa !14
  %107 = icmp eq i32 %106, 1
  br i1 %107, label %108, label %114

108:                                              ; preds = %105
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #8
  call void @_ZN7aryansh9io_macros2inIiJiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %9)
  %109 = load i32, ptr %8, align 4, !tbaa !14
  %110 = add nsw i32 %109, -1
  store i32 %110, ptr %8, align 4, !tbaa !14
  %111 = load i32, ptr %8, align 4, !tbaa !14
  %112 = load i32, ptr %8, align 4, !tbaa !14
  %113 = load i32, ptr %9, align 4, !tbaa !14
  call void @_ZN3HLDILi100000ELb0EE7updpathEiii(ptr noundef nonnull align 8 dereferenceable(4400160) @h, i32 noundef %111, i32 noundef %112, i32 noundef %113)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #8
  br label %122

114:                                              ; preds = %105
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #8
  call void @_ZN7aryansh9io_macros2inIiJiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4) %10, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %115 = load i32, ptr %10, align 4, !tbaa !14
  %116 = add nsw i32 %115, -1
  store i32 %116, ptr %10, align 4, !tbaa !14
  %117 = load i32, ptr %11, align 4, !tbaa !14
  %118 = add nsw i32 %117, -1
  store i32 %118, ptr %11, align 4, !tbaa !14
  %119 = load i32, ptr %10, align 4, !tbaa !14
  %120 = load i32, ptr %11, align 4, !tbaa !14
  %121 = call noundef i64 @_ZN3HLDILi100000ELb0EE7qrypathEii(ptr noundef nonnull align 8 dereferenceable(4400160) @h, i32 noundef %119, i32 noundef %120)
  call void @_ZN7aryansh9io_macros3outIxvEEvT_(i64 noundef %121)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #8
  br label %122

122:                                              ; preds = %114, %108
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #8
  br label %101, !llvm.loop !21

123:                                              ; preds = %101
  %124 = load i32, ptr %1, align 4
  ret i32 %124
}

declare noalias ptr @fopen(ptr noundef, ptr noundef) #3

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264), ptr noundef) #4 align 2

declare noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN7aryansh9io_macros2inIiJiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #6

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN7aryansh9io_macros2inIPxvEEvT_S3_(ptr noundef, ptr noundef) #6

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3HLDILi100000ELb0EE3addEii(ptr noundef nonnull align 8 dereferenceable(4400160), i32 noundef, i32 noundef) #7 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3HLDILi100000ELb0EE4initEi(ptr noundef nonnull align 8 dereferenceable(4400160), i32 noundef) #7 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3HLDILi100000ELb0EE7updpathEiii(ptr noundef nonnull align 8 dereferenceable(4400160), i32 noundef, i32 noundef, i32 noundef) #7 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN7aryansh9io_macros2inIivEEvRT_(ptr noundef nonnull align 4 dereferenceable(4)) #6

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN7aryansh9io_macros3outIxvEEvT_(i64 noundef) #6

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN3HLDILi100000ELb0EE7qrypathEii(ptr noundef nonnull align 8 dereferenceable(4400160), i32 noundef, i32 noundef) #7 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { mustprogress norecurse 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 = { "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 = { 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { inlinehint 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 #7 = { 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 #8 = { 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 = !{!"vtable pointer", !8, i64 0}
!11 = !{i64 0, i64 8, !12}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !19, i64 0}
!19 = !{!"long long", !7, i64 0}
!20 = distinct !{!20, !17}
!21 = distinct !{!21, !17}


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

%"class.std::chrono::time_point" = type { %"class.std::chrono::duration" }
%"class.std::chrono::duration" = type { i64 }
%struct.HLD = type { [100000 x %"class.std::vector"], %"class.std::vector", [100000 x i32], [100000 x i32], [100000 x i32], [100000 x i32], [100000 x i32], i32, %struct.LSEG, i64 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.LSEG = type { %"struct.std::pair", %"class.std::vector", i32, i32, %"class.std::vector.0", %"class.std::vector.5", %"class.std::vector.5" }
%"struct.std::pair" = type { i64, i64 }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<std::array<int, 2>, std::allocator<std::array<int, 2>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::array<int, 2>, std::allocator<std::array<int, 2>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::array<int, 2>, std::allocator<std::array<int, 2>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::array<int, 2>, std::allocator<std::array<int, 2>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.5" = type { %"struct.std::_Vector_base.6" }
%"struct.std::_Vector_base.6" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@CLK = external dso_local local_unnamed_addr global %"class.std::chrono::time_point", align 8
@n = external dso_local global i32, align 4
@q = external dso_local global i32, align 4
@e = external dso_local global [100000 x i64], align 16
@h = external dso_local global %struct.HLD, align 8
@.str = external hidden unnamed_addr constant [11 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8

; 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: nounwind
declare i64 @_ZNSt6chrono3_V212steady_clock3nowEv() local_unnamed_addr #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = tail call noalias ptr @fopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.5)
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %14, label %9

9:                                                ; preds = %0
  %10 = load ptr, ptr @stdin, align 8, !tbaa !5
  %11 = tail call ptr @freopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.5, ptr noundef %10)
  %12 = load ptr, ptr @stdout, align 8, !tbaa !5
  %13 = tail call ptr @freopen(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.7, ptr noundef %12)
  br label %14

14:                                               ; preds = %9, %0
  %15 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !9
  %16 = getelementptr i8, ptr %15, i64 -24
  %17 = load i64, ptr %16, align 8
  %18 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %17
  %19 = tail call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %18, ptr noundef null)
  %20 = tail call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  %21 = tail call i64 @_ZNSt6chrono3_V212steady_clock3nowEv() #8
  store i64 %21, ptr @CLK, align 8, !tbaa !11
  tail call void @_ZN7aryansh9io_macros2inIiJiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4) @n, ptr noundef nonnull align 4 dereferenceable(4) @q)
  %22 = load i32, ptr @n, align 4, !tbaa !13
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i64, ptr @e, i64 %23
  tail call void @_ZN7aryansh9io_macros2inIPxvEEvT_S3_(ptr noundef nonnull @e, ptr noundef nonnull %24)
  %25 = load i32, ptr @n, align 4, !tbaa !13
  %.not1318 = icmp eq i32 %25, 1
  br i1 %.not1318, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %14
  %26 = icmp slt i32 %25, 1
  %.neg = sext i1 %26 to i32
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %14
  call void @_ZN3HLDILi100000ELb0EE4initEi(ptr noundef nonnull align 8 dereferenceable(4400160) @h, i32 noundef 0)
  %27 = load i32, ptr @n, align 4, !tbaa !13
  %.not1521 = icmp eq i32 %27, 0
  br i1 %.not1521, label %.preheader, label %.lr.ph24.preheader

.lr.ph24.preheader:                               ; preds = %._crit_edge
  %.lobit.neg = ashr i32 %27, 31
  br label %.lr.ph24

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.01019 = phi i32 [ %.111, %.lr.ph ], [ %.neg, %.lr.ph.preheader ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #8
  call void @_ZN7aryansh9io_macros2inIiJiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %28 = load i32, ptr %1, align 4, !tbaa !13
  %29 = add nsw i32 %28, -1
  store i32 %29, ptr %1, align 4, !tbaa !13
  %30 = load i32, ptr %2, align 4, !tbaa !13
  %31 = add nsw i32 %30, -1
  store i32 %31, ptr %2, align 4, !tbaa !13
  call void @_ZN3HLDILi100000ELb0EE3addEii(ptr noundef nonnull align 8 dereferenceable(4400160) @h, i32 noundef %29, i32 noundef %31)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #8
  %32 = load i32, ptr @n, align 4, !tbaa !13
  %33 = icmp slt i32 %32, 1
  %.111.v = select i1 %33, i32 -1, i32 1
  %.111 = add nsw i32 %.111.v, %.01019
  %34 = add nsw i32 %32, -1
  %.neg12 = sext i1 %33 to i32
  %35 = add i32 %34, %.neg12
  %.not13 = icmp eq i32 %.111, %35
  br i1 %.not13, label %._crit_edge, label %.lr.ph, !llvm.loop !15

.preheader:                                       ; preds = %.lr.ph24, %._crit_edge
  %36 = load i32, ptr @q, align 4, !tbaa !13
  %37 = add nsw i32 %36, -1
  store i32 %37, ptr @q, align 4, !tbaa !13
  %.not1625 = icmp eq i32 %36, 0
  br i1 %.not1625, label %._crit_edge27, label %.lr.ph26

.lr.ph24:                                         ; preds = %.lr.ph24.preheader, %.lr.ph24
  %.022 = phi i32 [ %.1, %.lr.ph24 ], [ %.lobit.neg, %.lr.ph24.preheader ]
  %38 = sext i32 %.022 to i64
  %39 = getelementptr inbounds [100000 x i64], ptr @e, i64 0, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !17
  %41 = trunc i64 %40 to i32
  call void @_ZN3HLDILi100000ELb0EE7updpathEiii(ptr noundef nonnull align 8 dereferenceable(4400160) @h, i32 noundef %.022, i32 noundef %.022, i32 noundef %41)
  %42 = load i32, ptr @n, align 4, !tbaa !13
  %.inv = icmp sgt i32 %42, -1
  %.1.v = select i1 %.inv, i32 1, i32 -1
  %.1 = add nsw i32 %.1.v, %.022
  %.lobit.neg14 = ashr i32 %42, 31
  %43 = add i32 %.lobit.neg14, %42
  %.not15 = icmp eq i32 %.1, %43
  br i1 %.not15, label %.preheader, label %.lr.ph24, !llvm.loop !19

.lr.ph26:                                         ; preds = %.preheader, %56
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #8
  call void @_ZN7aryansh9io_macros2inIivEEvRT_(ptr noundef nonnull align 4 dereferenceable(4) %3)
  %44 = load i32, ptr %3, align 4, !tbaa !13
  %45 = icmp eq i32 %44, 1
  br i1 %45, label %46, label %50

46:                                               ; preds = %.lr.ph26
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #8
  call void @_ZN7aryansh9io_macros2inIiJiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %47 = load i32, ptr %4, align 4, !tbaa !13
  %48 = add nsw i32 %47, -1
  store i32 %48, ptr %4, align 4, !tbaa !13
  %49 = load i32, ptr %5, align 4, !tbaa !13
  call void @_ZN3HLDILi100000ELb0EE7updpathEiii(ptr noundef nonnull align 8 dereferenceable(4400160) @h, i32 noundef %48, i32 noundef %48, i32 noundef %49)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #8
  br label %56

50:                                               ; preds = %.lr.ph26
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #8
  call void @_ZN7aryansh9io_macros2inIiJiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %51 = load i32, ptr %6, align 4, !tbaa !13
  %52 = add nsw i32 %51, -1
  store i32 %52, ptr %6, align 4, !tbaa !13
  %53 = load i32, ptr %7, align 4, !tbaa !13
  %54 = add nsw i32 %53, -1
  store i32 %54, ptr %7, align 4, !tbaa !13
  %55 = call noundef i64 @_ZN3HLDILi100000ELb0EE7qrypathEii(ptr noundef nonnull align 8 dereferenceable(4400160) @h, i32 noundef %52, i32 noundef %54)
  call void @_ZN7aryansh9io_macros3outIxvEEvT_(i64 noundef %55)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #8
  br label %56

56:                                               ; preds = %50, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #8
  %57 = load i32, ptr @q, align 4, !tbaa !13
  %58 = add nsw i32 %57, -1
  store i32 %58, ptr @q, align 4, !tbaa !13
  %.not16 = icmp eq i32 %57, 0
  br i1 %.not16, label %._crit_edge27, label %.lr.ph26, !llvm.loop !20

._crit_edge27:                                    ; preds = %56, %.preheader
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #3

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264), ptr noundef) local_unnamed_addr #5 align 2

declare noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext) local_unnamed_addr #4

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN7aryansh9io_macros2inIiJiEEEvRT_DpRT0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #6

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN7aryansh9io_macros2inIPxvEEvT_S3_(ptr noundef, ptr noundef) local_unnamed_addr #6

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3HLDILi100000ELb0EE3addEii(ptr noundef nonnull align 8 dereferenceable(4400160), i32 noundef, i32 noundef) local_unnamed_addr #7 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3HLDILi100000ELb0EE4initEi(ptr noundef nonnull align 8 dereferenceable(4400160), i32 noundef) local_unnamed_addr #7 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3HLDILi100000ELb0EE7updpathEiii(ptr noundef nonnull align 8 dereferenceable(4400160), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #7 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN7aryansh9io_macros2inIivEEvRT_(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #6

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN7aryansh9io_macros3outIxvEEvT_(i64 noundef) local_unnamed_addr #6

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN3HLDILi100000ELb0EE7qrypathEii(ptr noundef nonnull align 8 dereferenceable(4400160), i32 noundef, i32 noundef) local_unnamed_addr #7 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { mustprogress norecurse 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 = { nofree nounwind "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 = { "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 #5 = { 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 #6 = { inlinehint 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 #7 = { 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 #8 = { 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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !18, i64 0}
!18 = !{!"long long", !7, i64 0}
!19 = distinct !{!19, !16}
!20 = distinct !{!20, !16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass