; LLVM IR from Izaron/ACM-ICPC :: Timus Online Judge/Volume 4/1326. Bottle Taps.ll (Z2dpi)

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@sub = external dso_local global %"class.std::vector", align 8
@add_masks = external dso_local global %"class.std::vector", align 8
@add_costs = external dso_local global %"class.std::vector", align 8
@target = external dso_local global i32, align 4
@calced = external dso_local global [1048576 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z2dpi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %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
  store i32 %0, ptr %3, align 4, !tbaa !5
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = load i32, ptr @target, align 4, !tbaa !5
  %12 = or i32 %10, %11
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = icmp eq i32 %12, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  br label %98

16:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1048576 x i32], ptr @calced, i64 0, i64 %18
  store ptr %19, ptr %4, align 8, !tbaa !9
  %20 = load ptr, ptr %4, align 8, !tbaa !9
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = icmp ne i32 %21, -1
  br i1 %22, label %23, label %26

23:                                               ; preds = %16
  %24 = load ptr, ptr %4, align 8, !tbaa !9
  %25 = load i32, ptr %24, align 4, !tbaa !5
  store i32 %25, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %97

26:                                               ; preds = %16
  %27 = load ptr, ptr %4, align 8, !tbaa !9
  store i32 1073741823, ptr %27, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %55, %26
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %58

33:                                               ; preds = %28
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = shl i32 1, %35
  %37 = and i32 %34, %36
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %33
  br label %55

40:                                               ; preds = %33
  %41 = load ptr, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = shl i32 1, %43
  %45 = or i32 %42, %44
  %46 = call noundef i32 @_Z2dpi(i32 noundef %45)
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @sub, i64 noundef %48) #4
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = add nsw i32 %46, %50
  store i32 %51, ptr %7, align 4, !tbaa !5
  %52 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %41, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = load ptr, ptr %4, align 8, !tbaa !9
  store i32 %53, ptr %54, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %55

55:                                               ; preds = %40, %39
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %6, align 4, !tbaa !5
  br label %28, !llvm.loop !11

58:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %91, %58
  %60 = load i32, ptr %8, align 4, !tbaa !5
  %61 = load i32, ptr @m, align 4, !tbaa !5
  %62 = icmp slt i32 %60, %61
  br i1 %62, label %64, label %63

63:                                               ; preds = %59
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %94

64:                                               ; preds = %59
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @add_masks, i64 noundef %67) #4
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = or i32 %65, %69
  %71 = load i32, ptr %3, align 4, !tbaa !5
  %72 = icmp eq i32 %70, %71
  br i1 %72, label %73, label %74

73:                                               ; preds = %64
  br label %91

74:                                               ; preds = %64
  %75 = load ptr, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %76 = load i32, ptr %3, align 4, !tbaa !5
  %77 = load i32, ptr %8, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @add_masks, i64 noundef %78) #4
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = or i32 %76, %80
  %82 = call noundef i32 @_Z2dpi(i32 noundef %81)
  %83 = load i32, ptr %8, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @add_costs, i64 noundef %84) #4
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = add nsw i32 %82, %86
  store i32 %87, ptr %9, align 4, !tbaa !5
  %88 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %75, ptr noundef nonnull align 4 dereferenceable(4) %9)
  %89 = load i32, ptr %88, align 4, !tbaa !5
  %90 = load ptr, ptr %4, align 8, !tbaa !9
  store i32 %89, ptr %90, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %91

91:                                               ; preds = %74, %73
  %92 = load i32, ptr %8, align 4, !tbaa !5
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %8, align 4, !tbaa !5
  br label %59, !llvm.loop !13

94:                                               ; preds = %63
  %95 = load ptr, ptr %4, align 8, !tbaa !9
  %96 = load i32, ptr %95, align 4, !tbaa !5
  store i32 %96, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %97

97:                                               ; preds = %94, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %98

98:                                               ; preds = %97, %15
  %99 = load i32, ptr %2, align 4
  ret i32 %99
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@sub = external dso_local global %"class.std::vector", align 8
@add_masks = external dso_local global %"class.std::vector", align 8
@add_costs = external dso_local global %"class.std::vector", align 8
@target = external dso_local local_unnamed_addr global i32, align 4
@calced = external dso_local global [1048576 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z2dpi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = load i32, ptr @target, align 4, !tbaa !5
  %5 = or i32 %4, %0
  %6 = icmp eq i32 %5, %0
  br i1 %6, label %._crit_edge, label %7

7:                                                ; preds = %1
  %8 = sext i32 %0 to i64
  %9 = getelementptr inbounds [1048576 x i32], ptr @calced, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %.not = icmp eq i32 %10, -1
  br i1 %.not, label %11, label %._crit_edge

11:                                               ; preds = %7
  store i32 1073741823, ptr %9, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %30, %11
  %14 = phi i32 [ 1073741823, %11 ], [ %31, %30 ]
  %15 = load i32, ptr @m, align 4, !tbaa !5
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %.lr.ph33, label %._crit_edge

.lr.ph:                                           ; preds = %11, %30
  %17 = phi i32 [ %31, %30 ], [ 1073741823, %11 ]
  %18 = phi i32 [ %32, %30 ], [ %12, %11 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %30 ], [ 0, %11 ]
  %19 = trunc nuw nsw i64 %indvars.iv to i32
  %20 = shl nuw i32 1, %19
  %21 = and i32 %20, %0
  %.not30 = icmp eq i32 %21, 0
  br i1 %.not30, label %22, label %30

22:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %23 = or i32 %20, %0
  %24 = call noundef i32 @_Z2dpi(i32 noundef %23)
  %25 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @sub, i64 noundef %indvars.iv) #3
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = add nsw i32 %26, %24
  store i32 %27, ptr %2, align 4, !tbaa !5
  %28 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %9, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %29 = load i32, ptr %28, align 4, !tbaa !5
  store i32 %29, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %.lr.ph, %22
  %31 = phi i32 [ %17, %.lr.ph ], [ %29, %22 ]
  %32 = phi i32 [ %18, %.lr.ph ], [ %.pre, %22 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %33 = sext i32 %32 to i64
  %34 = icmp slt i64 %indvars.iv.next, %33
  br i1 %34, label %.lr.ph, label %.preheader, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %49
  %.pre38 = load i32, ptr %9, align 4, !tbaa !5
  br label %._crit_edge

.lr.ph33:                                         ; preds = %.preheader, %49
  %indvars.iv35 = phi i64 [ %indvars.iv.next36, %49 ], [ 0, %.preheader ]
  %35 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @add_masks, i64 noundef %indvars.iv35) #3
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = or i32 %36, %0
  %38 = icmp eq i32 %37, %0
  br i1 %38, label %49, label %39

39:                                               ; preds = %.lr.ph33
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %40 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @add_masks, i64 noundef %indvars.iv35) #3
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = or i32 %41, %0
  %43 = call noundef i32 @_Z2dpi(i32 noundef %42)
  %44 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @add_costs, i64 noundef %indvars.iv35) #3
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = add nsw i32 %45, %43
  store i32 %46, ptr %3, align 4, !tbaa !5
  %47 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %9, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %48 = load i32, ptr %47, align 4, !tbaa !5
  store i32 %48, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br label %49

49:                                               ; preds = %.lr.ph33, %39
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %50 = load i32, ptr @m, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = icmp slt i64 %indvars.iv.next36, %51
  br i1 %52, label %.lr.ph33, label %._crit_edge.loopexit, !llvm.loop !11

._crit_edge:                                      ; preds = %.preheader, %._crit_edge.loopexit, %7, %1
  %.1 = phi i32 [ 0, %1 ], [ %10, %7 ], [ %.pre38, %._crit_edge.loopexit ], [ %14, %.preheader ]
  ret i32 %.1
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass