; LLVM IR from viveakrt/Competitive-programing :: SPOJ/acquire.ll (Z5queryx)

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

@m = external dso_local global %"class.std::vector", align 8
@b = external dso_local global %"class.std::vector", align 8
@ptr = external dso_local global i32, align 4

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z5queryx(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  %4 = call noundef zeroext i1 @_ZNKSt6vectorIxSaIxEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24) @m) #1
  br i1 %4, label %5, label %6

5:                                                ; preds = %1
  store i64 9223372036854775807, ptr %2, align 8
  br label %65

6:                                                ; preds = %1
  %7 = load i32, ptr @ptr, align 4, !tbaa !9
  %8 = sext i32 %7 to i64
  %9 = call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @m) #1
  %10 = icmp uge i64 %8, %9
  br i1 %10, label %11, label %15

11:                                               ; preds = %6
  %12 = call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @m) #1
  %13 = sub i64 %12, 1
  %14 = trunc i64 %13 to i32
  store i32 %14, ptr @ptr, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %11, %6
  br label %16

16:                                               ; preds = %50, %15
  %17 = load i32, ptr @ptr, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @m) #1
  %20 = sub i64 %19, 1
  %21 = icmp ult i64 %18, %20
  br i1 %21, label %22, label %48

22:                                               ; preds = %16
  %23 = load i32, ptr @ptr, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @m, i64 noundef %25) #1
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = load i64, ptr %3, align 8, !tbaa !5
  %29 = mul nsw i64 %27, %28
  %30 = load i32, ptr @ptr, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  %32 = sext i32 %31 to i64
  %33 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @b, i64 noundef %32) #1
  %34 = load i64, ptr %33, align 8, !tbaa !5
  %35 = add nsw i64 %29, %34
  %36 = load i32, ptr @ptr, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @m, i64 noundef %37) #1
  %39 = load i64, ptr %38, align 8, !tbaa !5
  %40 = load i64, ptr %3, align 8, !tbaa !5
  %41 = mul nsw i64 %39, %40
  %42 = load i32, ptr @ptr, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @b, i64 noundef %43) #1
  %45 = load i64, ptr %44, align 8, !tbaa !5
  %46 = add nsw i64 %41, %45
  %47 = icmp sle i64 %35, %46
  br label %48

48:                                               ; preds = %22, %16
  %49 = phi i1 [ false, %16 ], [ %47, %22 ]
  br i1 %49, label %50, label %53

50:                                               ; preds = %48
  %51 = load i32, ptr @ptr, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr @ptr, align 4, !tbaa !9
  br label %16, !llvm.loop !11

53:                                               ; preds = %48
  %54 = load i32, ptr @ptr, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @m, i64 noundef %55) #1
  %57 = load i64, ptr %56, align 8, !tbaa !5
  %58 = load i64, ptr %3, align 8, !tbaa !5
  %59 = mul nsw i64 %57, %58
  %60 = load i32, ptr @ptr, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @b, i64 noundef %61) #1
  %63 = load i64, ptr %62, align 8, !tbaa !5
  %64 = add nsw i64 %59, %63
  store i64 %64, ptr %2, align 8
  br label %65

65:                                               ; preds = %53, %5
  %66 = load i64, ptr %2, align 8
  ret i64 %66
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6vectorIxSaIxEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24)) #0 align 2

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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = 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 }

@m = external dso_local global %"class.std::vector", align 8
@b = external dso_local global %"class.std::vector", align 8
@ptr = external dso_local local_unnamed_addr global i32, align 4

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z5queryx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = tail call noundef zeroext i1 @_ZNKSt6vectorIxSaIxEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24) @m) #1
  br i1 %2, label %56, label %3

3:                                                ; preds = %1
  %4 = load i32, ptr @ptr, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @m) #1
  %.not = icmp ugt i64 %6, %5
  br i1 %.not, label %._crit_edge, label %7

._crit_edge:                                      ; preds = %3
  %.pre = load i32, ptr @ptr, align 4, !tbaa !5
  br label %11

7:                                                ; preds = %3
  %8 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @m) #1
  %9 = trunc i64 %8 to i32
  %10 = add i32 %9, -1
  store i32 %10, ptr @ptr, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %._crit_edge, %7
  %12 = phi i32 [ %.pre, %._crit_edge ], [ %10, %7 ]
  %13 = sext i32 %12 to i64
  %14 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @m) #1
  %15 = add i64 %14, -1
  %16 = icmp ugt i64 %15, %13
  br i1 %16, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %11, %39
  %17 = load i32, ptr @ptr, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  %19 = sext i32 %18 to i64
  %20 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @m, i64 noundef %19) #1
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = mul nsw i64 %21, %0
  %23 = load i32, ptr @ptr, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @b, i64 noundef %25) #1
  %27 = load i64, ptr %26, align 8, !tbaa !9
  %28 = add nsw i64 %27, %22
  %29 = load i32, ptr @ptr, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @m, i64 noundef %30) #1
  %32 = load i64, ptr %31, align 8, !tbaa !9
  %33 = mul nsw i64 %32, %0
  %34 = load i32, ptr @ptr, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @b, i64 noundef %35) #1
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = add nsw i64 %37, %33
  %.not4 = icmp sgt i64 %28, %38
  br i1 %.not4, label %.critedge, label %39

39:                                               ; preds = %.lr.ph
  %40 = load i32, ptr @ptr, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr @ptr, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) @m) #1
  %44 = add i64 %43, -1
  %45 = icmp ugt i64 %44, %42
  br i1 %45, label %.lr.ph, label %.critedge, !llvm.loop !11

.critedge:                                        ; preds = %.lr.ph, %39, %11
  %46 = load i32, ptr @ptr, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @m, i64 noundef %47) #1
  %49 = load i64, ptr %48, align 8, !tbaa !9
  %50 = mul nsw i64 %49, %0
  %51 = load i32, ptr @ptr, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @b, i64 noundef %52) #1
  %54 = load i64, ptr %53, align 8, !tbaa !9
  %55 = add nsw i64 %54, %50
  br label %56

56:                                               ; preds = %1, %.critedge
  %.0 = phi i64 [ %55, %.critedge ], [ 9223372036854775807, %1 ]
  ret i64 %.0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6vectorIxSaIxEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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