; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2018-19/Feb 2019/Plat/mowing.ll (Z3insiiiiii)

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

@seg = external dso_local global [524288 x %"class.std::vector.6"], align 16
@er = external dso_local global %"class.std::vector.6", align 8
@ER = external dso_local global [524288 x i8], 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: 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 void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

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

17:                                               ; preds = %6
  %18 = load i32, ptr %8, align 4, !tbaa !5
  %19 = load i32, ptr %11, align 4, !tbaa !5
  %20 = icmp sgt i32 %18, %19
  br i1 %20, label %25, label %21

21:                                               ; preds = %17
  %22 = load i32, ptr %9, align 4, !tbaa !5
  %23 = load i32, ptr %10, align 4, !tbaa !5
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %21, %17, %6
  br label %69

26:                                               ; preds = %21
  %27 = load i32, ptr %8, align 4, !tbaa !5
  %28 = load i32, ptr %10, align 4, !tbaa !5
  %29 = icmp sle i32 %27, %28
  br i1 %29, label %30, label %48

30:                                               ; preds = %26
  %31 = load i32, ptr %11, align 4, !tbaa !5
  %32 = load i32, ptr %9, align 4, !tbaa !5
  %33 = icmp sle i32 %31, %32
  br i1 %33, label %34, label %48

34:                                               ; preds = %30
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [524288 x %"class.std::vector.6"], ptr @seg, i64 0, i64 %36
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %37, ptr noundef nonnull align 4 dereferenceable(4) %12)
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [524288 x i8], ptr @ER, i64 0, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !9, !range !11, !noundef !12
  %42 = trunc i8 %41 to i1
  br i1 %42, label %47, label %43

43:                                               ; preds = %34
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [524288 x i8], ptr @ER, i64 0, i64 %45
  store i8 1, ptr %46, align 1, !tbaa !9
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) @er, ptr noundef nonnull align 4 dereferenceable(4) %7)
  br label %47

47:                                               ; preds = %43, %34
  br label %69

48:                                               ; preds = %30, %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %49 = load i32, ptr %10, align 4, !tbaa !5
  %50 = load i32, ptr %11, align 4, !tbaa !5
  %51 = add nsw i32 %49, %50
  %52 = sdiv i32 %51, 2
  store i32 %52, ptr %13, align 4, !tbaa !5
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = mul nsw i32 2, %53
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = load i32, ptr %9, align 4, !tbaa !5
  %57 = load i32, ptr %10, align 4, !tbaa !5
  %58 = load i32, ptr %13, align 4, !tbaa !5
  %59 = load i32, ptr %12, align 4, !tbaa !5
  call void @_Z3insiiiiii(i32 noundef %54, i32 noundef %55, i32 noundef %56, i32 noundef %57, i32 noundef %58, i32 noundef %59)
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = mul nsw i32 2, %60
  %62 = add nsw i32 %61, 1
  %63 = load i32, ptr %8, align 4, !tbaa !5
  %64 = load i32, ptr %9, align 4, !tbaa !5
  %65 = load i32, ptr %13, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  %67 = load i32, ptr %11, align 4, !tbaa !5
  %68 = load i32, ptr %12, align 4, !tbaa !5
  call void @_Z3insiiiiii(i32 noundef %62, i32 noundef %63, i32 noundef %64, i32 noundef %66, i32 noundef %67, i32 noundef %68)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  br label %69

69:                                               ; preds = %48, %47, %25
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!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.6" = type { %"struct.std::_Vector_base.7" }
%"struct.std::_Vector_base.7" = 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 }

@seg = external dso_local global [524288 x %"class.std::vector.6"], align 16
@er = external dso_local global %"class.std::vector.6", align 8
@ER = external dso_local local_unnamed_addr global [524288 x i8], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3insiiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = icmp sgt i32 %1, %2
  %10 = icmp sgt i32 %1, %4
  %or.cond = or i1 %9, %10
  %11 = icmp slt i32 %2, %3
  %or.cond2434 = or i1 %or.cond, %11
  br i1 %or.cond2434, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %6
  %.not23 = icmp sgt i32 %4, %2
  br i1 %.not23, label %tailrecurse.us, label %.lr.ph.split.split

tailrecurse.us:                                   ; preds = %.lr.ph, %tailrecurse.us
  %.tr2836.us = phi i32 [ %16, %tailrecurse.us ], [ %3, %.lr.ph ]
  %.tr35.us = phi i32 [ %15, %tailrecurse.us ], [ %0, %.lr.ph ]
  %12 = add nsw i32 %.tr2836.us, %4
  %13 = sdiv i32 %12, 2
  %14 = shl nsw i32 %.tr35.us, 1
  tail call void @_Z3insiiiiii(i32 noundef %14, i32 noundef %1, i32 noundef %2, i32 noundef %.tr2836.us, i32 noundef %13, i32 noundef %5)
  %15 = or disjoint i32 %14, 1
  %16 = add nsw i32 %13, 1
  %.not54 = icmp slt i32 %13, %2
  br i1 %.not54, label %tailrecurse.us, label %.loopexit

.lr.ph.split.split:                               ; preds = %.lr.ph, %tailrecurse
  %.tr2836 = phi i32 [ %27, %tailrecurse ], [ %3, %.lr.ph ]
  %.tr35 = phi i32 [ %26, %tailrecurse ], [ %0, %.lr.ph ]
  %.not = icmp slt i32 %.tr2836, %1
  br i1 %.not, label %tailrecurse, label %.split.us

.split.us:                                        ; preds = %.lr.ph.split.split
  store i32 %.tr35, ptr %7, align 4, !tbaa !5
  store i32 %5, ptr %8, align 4, !tbaa !5
  %17 = sext i32 %.tr35 to i64
  %18 = getelementptr inbounds [524288 x %"class.std::vector.6"], ptr @seg, i64 0, i64 %17
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %18, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %19 = getelementptr inbounds [524288 x i8], ptr @ER, i64 0, i64 %17
  %20 = load i8, ptr %19, align 1, !tbaa !9, !range !11, !noundef !12
  %21 = trunc nuw i8 %20 to i1
  br i1 %21, label %.loopexit, label %22

22:                                               ; preds = %.split.us
  store i8 1, ptr %19, align 1, !tbaa !9
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) @er, ptr noundef nonnull align 4 dereferenceable(4) %7)
  br label %.loopexit

tailrecurse:                                      ; preds = %.lr.ph.split.split
  %23 = add nsw i32 %.tr2836, %4
  %24 = sdiv i32 %23, 2
  %25 = shl nsw i32 %.tr35, 1
  tail call void @_Z3insiiiiii(i32 noundef %25, i32 noundef %1, i32 noundef %2, i32 noundef %.tr2836, i32 noundef %24, i32 noundef %5)
  %26 = or disjoint i32 %25, 1
  %27 = add nsw i32 %24, 1
  %.not53 = icmp slt i32 %24, %2
  br i1 %.not53, label %.lr.ph.split.split, label %.loopexit

.loopexit:                                        ; preds = %tailrecurse, %tailrecurse.us, %6, %.split.us, %22
  ret void
}

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

!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 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass