; LLVM IR from tangjz/acm-icpc :: lydsy/1602.ll (Z3lcaii)

; 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::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.std::pair" = type { i32, i32 }

@g = external dso_local global [1001 x %"class.std::vector"], align 16
@level = external dso_local global [1001 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIiiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3lcaii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %15, %2
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [1001 x i32], ptr @level, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [1001 x i32], ptr @level, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp sgt i32 %9, %13
  br i1 %14, label %15, label %22

15:                                               ; preds = %5
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [1001 x %"class.std::vector"], ptr @g, i64 0, i64 %17
  %19 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIiiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %18, i64 noundef 0) #1
  %20 = getelementptr inbounds %"struct.std::pair", ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 4, !tbaa !9
  store i32 %21, ptr %3, align 4, !tbaa !5
  br label %5, !llvm.loop !11

22:                                               ; preds = %5
  br label %23

23:                                               ; preds = %33, %22
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [1001 x i32], ptr @level, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [1001 x i32], ptr @level, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = icmp slt i32 %27, %31
  br i1 %32, label %33, label %40

33:                                               ; preds = %23
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [1001 x %"class.std::vector"], ptr @g, i64 0, i64 %35
  %37 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIiiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %36, i64 noundef 0) #1
  %38 = getelementptr inbounds %"struct.std::pair", ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 4, !tbaa !9
  store i32 %39, ptr %4, align 4, !tbaa !5
  br label %23, !llvm.loop !13

40:                                               ; preds = %23
  br label %41

41:                                               ; preds = %45, %40
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = icmp ne i32 %42, %43
  br i1 %44, label %45, label %58

45:                                               ; preds = %41
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [1001 x %"class.std::vector"], ptr @g, i64 0, i64 %47
  %49 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIiiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %48, i64 noundef 0) #1
  %50 = getelementptr inbounds %"struct.std::pair", ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 4, !tbaa !9
  store i32 %51, ptr %3, align 4, !tbaa !5
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [1001 x %"class.std::vector"], ptr @g, i64 0, i64 %53
  %55 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIiiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %54, i64 noundef 0) #1
  %56 = getelementptr inbounds %"struct.std::pair", ptr %55, i32 0, i32 0
  %57 = load i32, ptr %56, align 4, !tbaa !9
  store i32 %57, ptr %4, align 4, !tbaa !5
  br label %41, !llvm.loop !14

58:                                               ; preds = %41
  %59 = load i32, ptr %3, align 4, !tbaa !5
  ret i32 %59
}

attributes #0 = { 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 #1 = { 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, !6, i64 0}
!10 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; 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::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@g = external dso_local global [1001 x %"class.std::vector"], align 16
@level = external dso_local local_unnamed_addr global [1001 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIiiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3lcaii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %1 to i64
  %4 = getelementptr inbounds [1001 x i32], ptr @level, i64 0, i64 %3
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [1001 x i32], ptr @level, i64 0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = icmp sgt i32 %7, %8
  br i1 %9, label %.lr.ph, label %.preheader13

.preheader13:                                     ; preds = %.lr.ph, %2
  %10 = phi i32 [ %8, %2 ], [ %21, %.lr.ph ]
  %11 = phi i32 [ %7, %2 ], [ %20, %.lr.ph ]
  %.lcssa14 = phi i64 [ %5, %2 ], [ %18, %.lr.ph ]
  %.011.lcssa = phi i32 [ %0, %2 ], [ %17, %.lr.ph ]
  %12 = getelementptr inbounds [1001 x i32], ptr @level, i64 0, i64 %.lcssa14
  %13 = icmp slt i32 %11, %10
  br i1 %13, label %.lr.ph16, label %.preheader

.lr.ph:                                           ; preds = %2, %.lr.ph
  %14 = phi i64 [ %18, %.lr.ph ], [ %5, %2 ]
  %15 = getelementptr inbounds [1001 x %"class.std::vector"], ptr @g, i64 0, i64 %14
  %16 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIiiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %15, i64 noundef 0) #1
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1001 x i32], ptr @level, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = icmp sgt i32 %20, %21
  br i1 %22, label %.lr.ph, label %.preheader13, !llvm.loop !11

.preheader:                                       ; preds = %.lr.ph16, %.preheader13
  %.0.lcssa = phi i32 [ %1, %.preheader13 ], [ %26, %.lr.ph16 ]
  %.not18 = icmp eq i32 %.011.lcssa, %.0.lcssa
  br i1 %.not18, label %._crit_edge, label %.lr.ph21

.lr.ph16:                                         ; preds = %.preheader13, %.lr.ph16
  %23 = phi i64 [ %28, %.lr.ph16 ], [ %3, %.preheader13 ]
  %24 = getelementptr inbounds [1001 x %"class.std::vector"], ptr @g, i64 0, i64 %23
  %25 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIiiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %24, i64 noundef 0) #1
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = load i32, ptr %12, align 4, !tbaa !5
  %28 = sext i32 %26 to i64
  %29 = getelementptr inbounds [1001 x i32], ptr @level, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = icmp slt i32 %27, %30
  br i1 %31, label %.lr.ph16, label %.preheader, !llvm.loop !13

.lr.ph21:                                         ; preds = %.preheader, %.lr.ph21
  %.120 = phi i32 [ %39, %.lr.ph21 ], [ %.0.lcssa, %.preheader ]
  %.11219 = phi i32 [ %35, %.lr.ph21 ], [ %.011.lcssa, %.preheader ]
  %32 = sext i32 %.11219 to i64
  %33 = getelementptr inbounds [1001 x %"class.std::vector"], ptr @g, i64 0, i64 %32
  %34 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIiiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %33, i64 noundef 0) #1
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = sext i32 %.120 to i64
  %37 = getelementptr inbounds [1001 x %"class.std::vector"], ptr @g, i64 0, i64 %36
  %38 = tail call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt6vectorISt4pairIiiESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %37, i64 noundef 0) #1
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %.not = icmp eq i32 %35, %39
  br i1 %.not, label %._crit_edge, label %.lr.ph21, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph21, %.preheader
  %.112.lcssa = phi i32 [ %.011.lcssa, %.preheader ], [ %35, %.lr.ph21 ]
  ret i32 %.112.lcssa
}

attributes #0 = { 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 #1 = { 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, !6, i64 0}
!10 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass