; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2011-12/Mar/12 Mar G1.ll (Z3getiii)

; 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 }
%"struct.std::pair" = type { i64, i64 }

@M = external dso_local global i64, align 8
@N = external dso_local global i64, align 8
@B = external dso_local global i64, align 8
@ans = external dso_local global i64, align 8
@prime = external dso_local global [100001 x %"class.std::vector"], align 16

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i64 } @_Z3badiii(i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3getiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca %"struct.std::pair", align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %102, %3
  %15 = load i32, ptr %8, align 4, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100001 x %"class.std::vector"], ptr @prime, i64 0, i64 %17
  %19 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %18) #3
  %20 = trunc i64 %19 to i32
  %21 = shl i32 1, %20
  %22 = icmp slt i32 %15, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %14
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %105

24:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 1, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %53, %24
  %26 = load i32, ptr %12, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100001 x %"class.std::vector"], ptr @prime, i64 0, i64 %29
  %31 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %30) #3
  %32 = icmp ult i64 %27, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %25
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %56

34:                                               ; preds = %25
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = load i32, ptr %12, align 4, !tbaa !5
  %37 = shl i32 1, %36
  %38 = and i32 %35, %37
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %52

40:                                               ; preds = %34
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [100001 x %"class.std::vector"], ptr @prime, i64 0, i64 %42
  %44 = load i32, ptr %12, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %43, i64 noundef %45) #3
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = load i32, ptr %10, align 4, !tbaa !5
  %49 = mul nsw i32 %48, %47
  store i32 %49, ptr %10, align 4, !tbaa !5
  %50 = load i32, ptr %11, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %11, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %40, %34
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %12, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %12, align 4, !tbaa !5
  br label %25, !llvm.loop !11

56:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #3
  %57 = load i32, ptr %10, align 4, !tbaa !5
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = load i32, ptr %6, align 4, !tbaa !5
  %60 = call { i64, i64 } @_Z3badiii(i32 noundef %57, i32 noundef %58, i32 noundef %59)
  %61 = getelementptr inbounds { i64, i64 }, ptr %13, i32 0, i32 0
  %62 = extractvalue { i64, i64 } %60, 0
  store i64 %62, ptr %61, align 8
  %63 = getelementptr inbounds { i64, i64 }, ptr %13, i32 0, i32 1
  %64 = extractvalue { i64, i64 } %60, 1
  store i64 %64, ptr %63, align 8
  %65 = load i32, ptr %11, align 4, !tbaa !5
  %66 = srem i32 %65, 2
  %67 = icmp eq i32 %66, 0
  br i1 %67, label %68, label %83

68:                                               ; preds = %56
  %69 = load i64, ptr %7, align 8, !tbaa !9
  %70 = getelementptr inbounds %"struct.std::pair", ptr %13, i32 0, i32 0
  %71 = load i64, ptr %70, align 8, !tbaa !13
  %72 = load i64, ptr @N, align 8, !tbaa !9
  %73 = add nsw i64 %72, 1
  %74 = mul nsw i64 %71, %73
  %75 = add nsw i64 %69, %74
  %76 = getelementptr inbounds %"struct.std::pair", ptr %13, i32 0, i32 1
  %77 = load i64, ptr %76, align 8, !tbaa !15
  %78 = sub nsw i64 %75, %77
  %79 = load i64, ptr @B, align 8, !tbaa !9
  %80 = add nsw i64 %78, %79
  %81 = load i64, ptr @B, align 8, !tbaa !9
  %82 = srem i64 %80, %81
  store i64 %82, ptr %7, align 8, !tbaa !9
  br label %101

83:                                               ; preds = %56
  %84 = load i64, ptr %7, align 8, !tbaa !9
  %85 = getelementptr inbounds %"struct.std::pair", ptr %13, i32 0, i32 0
  %86 = load i64, ptr %85, align 8, !tbaa !13
  %87 = load i64, ptr @N, align 8, !tbaa !9
  %88 = add nsw i64 %87, 1
  %89 = mul nsw i64 %86, %88
  %90 = getelementptr inbounds %"struct.std::pair", ptr %13, i32 0, i32 1
  %91 = load i64, ptr %90, align 8, !tbaa !15
  %92 = sub nsw i64 %89, %91
  %93 = sub nsw i64 %84, %92
  %94 = load i64, ptr @B, align 8, !tbaa !9
  %95 = srem i64 %93, %94
  store i64 %95, ptr %7, align 8, !tbaa !9
  %96 = load i64, ptr %7, align 8, !tbaa !9
  %97 = load i64, ptr @B, align 8, !tbaa !9
  %98 = add nsw i64 %96, %97
  %99 = load i64, ptr @B, align 8, !tbaa !9
  %100 = srem i64 %98, %99
  store i64 %100, ptr %7, align 8, !tbaa !9
  br label %101

101:                                              ; preds = %83, %68
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %102

102:                                              ; preds = %101
  %103 = load i32, ptr %8, align 4, !tbaa !5
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %8, align 4, !tbaa !5
  br label %14, !llvm.loop !16

105:                                              ; preds = %23
  %106 = load i64, ptr @ans, align 8, !tbaa !9
  %107 = load i64, ptr @M, align 8, !tbaa !9
  %108 = add nsw i64 %107, 1
  %109 = load i32, ptr %4, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %111 = sub nsw i64 %108, %110
  %112 = mul nsw i64 2, %111
  %113 = load i64, ptr %7, align 8, !tbaa !9
  %114 = mul nsw i64 %112, %113
  %115 = add nsw i64 %106, %114
  %116 = load i64, ptr @B, align 8, !tbaa !9
  %117 = srem i64 %115, %116
  store i64 %117, ptr @ans, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

; 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) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTSSt4pairIxxE", !10, i64 0, !10, i64 8}
!15 = !{!14, !10, i64 8}
!16 = distinct !{!16, !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 }

@M = external dso_local local_unnamed_addr global i64, align 8
@N = external dso_local local_unnamed_addr global i64, align 8
@B = external dso_local local_unnamed_addr global i64, align 8
@ans = external dso_local local_unnamed_addr global i64, align 8
@prime = external dso_local global [100001 x %"class.std::vector"], align 16

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

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i64 } @_Z3badiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3getiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [100001 x %"class.std::vector"], ptr @prime, i64 0, i64 %4
  %6 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #2
  %7 = and i64 %6, 4294967295
  %.not43 = icmp eq i64 %7, 31
  br i1 %.not43, label %._crit_edge40, label %.preheader

.preheader:                                       ; preds = %3, %54
  %.039 = phi i64 [ %.1, %54 ], [ 0, %3 ]
  %.02338 = phi i32 [ %55, %54 ], [ 0, %3 ]
  %8 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #2
  %.not44 = icmp eq i64 %8, 0
  br i1 %.not44, label %._crit_edge.thread, label %.lr.ph

._crit_edge.thread:                               ; preds = %.preheader
  %9 = tail call { i64, i64 } @_Z3badiii(i32 noundef 1, i32 noundef %1, i32 noundef %2)
  %10 = extractvalue { i64, i64 } %9, 0
  %11 = extractvalue { i64, i64 } %9, 1
  br label %36

._crit_edge40.loopexit:                           ; preds = %54
  %12 = shl i64 %.1, 1
  br label %._crit_edge40

._crit_edge40:                                    ; preds = %._crit_edge40.loopexit, %3
  %.0.lcssa = phi i64 [ 0, %3 ], [ %12, %._crit_edge40.loopexit ]
  %13 = load i64, ptr @ans, align 8, !tbaa !5
  %14 = load i64, ptr @M, align 8, !tbaa !5
  %reass.sub = sub i64 %14, %4
  %15 = add i64 %reass.sub, 1
  %16 = mul i64 %.0.lcssa, %15
  %17 = add nsw i64 %16, %13
  %18 = load i64, ptr @B, align 8, !tbaa !5
  %19 = srem i64 %17, %18
  store i64 %19, ptr @ans, align 8, !tbaa !5
  ret void

._crit_edge:                                      ; preds = %33
  %20 = tail call { i64, i64 } @_Z3badiii(i32 noundef %.128, i32 noundef %1, i32 noundef %2)
  %21 = extractvalue { i64, i64 } %20, 0
  %22 = extractvalue { i64, i64 } %20, 1
  %23 = and i32 %.126, 1
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %36, label %47

.lr.ph:                                           ; preds = %.preheader, %33
  %indvars.iv = phi i64 [ %indvars.iv.next, %33 ], [ 0, %.preheader ]
  %.02535 = phi i32 [ %.126, %33 ], [ 0, %.preheader ]
  %.02734 = phi i32 [ %.128, %33 ], [ 1, %.preheader ]
  %25 = trunc nuw nsw i64 %indvars.iv to i32
  %26 = shl nuw i32 1, %25
  %27 = and i32 %26, %.02338
  %.not = icmp eq i32 %27, 0
  br i1 %.not, label %33, label %28

28:                                               ; preds = %.lr.ph
  %29 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %indvars.iv) #2
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = mul nsw i32 %30, %.02734
  %32 = add nsw i32 %.02535, 1
  br label %33

33:                                               ; preds = %.lr.ph, %28
  %.128 = phi i32 [ %31, %28 ], [ %.02734, %.lr.ph ]
  %.126 = phi i32 [ %32, %28 ], [ %.02535, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %34 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #2
  %35 = icmp ugt i64 %34, %indvars.iv.next
  br i1 %35, label %.lr.ph, label %._crit_edge, !llvm.loop !11

36:                                               ; preds = %._crit_edge.thread, %._crit_edge
  %37 = phi i64 [ %11, %._crit_edge.thread ], [ %22, %._crit_edge ]
  %38 = phi i64 [ %10, %._crit_edge.thread ], [ %21, %._crit_edge ]
  %39 = load i64, ptr @N, align 8, !tbaa !5
  %40 = add nsw i64 %39, 1
  %41 = mul nsw i64 %40, %38
  %42 = load i64, ptr @B, align 8, !tbaa !5
  %43 = sub i64 %.039, %37
  %44 = add i64 %43, %42
  %45 = add i64 %44, %41
  %46 = srem i64 %45, %42
  br label %54

47:                                               ; preds = %._crit_edge
  %48 = load i64, ptr @N, align 8, !tbaa !5
  %.neg30 = xor i64 %48, -1
  %.neg31 = mul i64 %21, %.neg30
  %.neg = add i64 %22, %.039
  %49 = add i64 %.neg, %.neg31
  %50 = load i64, ptr @B, align 8, !tbaa !5
  %51 = srem i64 %49, %50
  %52 = add nsw i64 %51, %50
  %53 = srem i64 %52, %50
  br label %54

54:                                               ; preds = %47, %36
  %.1 = phi i64 [ %46, %36 ], [ %53, %47 ]
  %55 = add nuw nsw i32 %.02338, 1
  %56 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #2
  %57 = trunc i64 %56 to i32
  %58 = shl nuw i32 1, %57
  %59 = icmp slt i32 %55, %58
  br i1 %59, label %.preheader, label %._crit_edge40.loopexit, !llvm.loop !13
}

; 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

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 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 #2 = { 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"}
!13 = distinct !{!13, !12}


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