; LLVM IR from ravireddy07/cpp-book :: src/Code-Chef/JAN2021-Long/CURMAT.ll (Z6modifyiiiP4Nodeii)

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

%struct.Node = type { %"class.std::vector", [2 x ptr] }
%"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 }

; 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
define dso_local void @_Z6modifyiiiP4Nodeii(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr 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 ptr, align 8
  %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 ptr %3, ptr %10, align 8, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !5
  store i32 %5, ptr %12, align 4, !tbaa !5
  %14 = load i32, ptr %7, align 4, !tbaa !5
  %15 = load i32, ptr %11, align 4, !tbaa !5
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %17, label %24

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

21:                                               ; preds = %17
  %22 = load ptr, ptr %10, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.Node, ptr %22, i32 0, i32 0
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %23, ptr noundef nonnull align 4 dereferenceable(4) %9)
  br label %57

24:                                               ; preds = %17, %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %25 = load i32, ptr %11, align 4, !tbaa !5
  %26 = load i32, ptr %12, align 4, !tbaa !5
  %27 = add nsw i32 %25, %26
  %28 = ashr i32 %27, 1
  store i32 %28, ptr %13, align 4, !tbaa !5
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = load i32, ptr %13, align 4, !tbaa !5
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %32, label %42

32:                                               ; preds = %24
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = load ptr, ptr %10, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.Node, ptr %36, i32 0, i32 1
  %38 = getelementptr inbounds [2 x ptr], ptr %37, i64 0, i64 0
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = load i32, ptr %11, align 4, !tbaa !5
  %41 = load i32, ptr %13, align 4, !tbaa !5
  call void @_Z6modifyiiiP4Nodeii(i32 noundef %33, i32 noundef %34, i32 noundef %35, ptr noundef %39, i32 noundef %40, i32 noundef %41)
  br label %42

42:                                               ; preds = %32, %24
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = load i32, ptr %13, align 4, !tbaa !5
  %45 = icmp sgt i32 %43, %44
  br i1 %45, label %46, label %56

46:                                               ; preds = %42
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = load i32, ptr %8, align 4, !tbaa !5
  %49 = load i32, ptr %9, align 4, !tbaa !5
  %50 = load ptr, ptr %10, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.Node, ptr %50, i32 0, i32 1
  %52 = getelementptr inbounds [2 x ptr], ptr %51, i64 0, i64 1
  %53 = load ptr, ptr %52, align 8, !tbaa !9
  %54 = load i32, ptr %13, align 4, !tbaa !5
  %55 = load i32, ptr %12, align 4, !tbaa !5
  call void @_Z6modifyiiiP4Nodeii(i32 noundef %47, i32 noundef %48, i32 noundef %49, ptr noundef %53, i32 noundef %54, i32 noundef %55)
  br label %56

56:                                               ; preds = %46, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  br label %57

57:                                               ; preds = %56, %21
  ret void
}

; 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

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 = !{!"any pointer", !7, i64 0}


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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6modifyiiiP4Nodeii(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = alloca i32, align 4
  %.not22 = icmp sgt i32 %5, %1
  %.not30 = icmp sgt i32 %0, %4
  %or.cond31 = or i1 %.not22, %.not30
  br i1 %or.cond31, label %.lr.ph, label %tailrecurse._crit_edge

.lr.ph:                                           ; preds = %6
  br i1 %.not22, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %tailrecurse.us
  %.tr2634.us = phi i32 [ %9, %tailrecurse.us ], [ %4, %.lr.ph ]
  %.tr2533.us = phi ptr [ %17, %tailrecurse.us ], [ %3, %.lr.ph ]
  %8 = add nsw i32 %.tr2634.us, %5
  %9 = ashr i32 %8, 1
  %10 = icmp sgt i32 %9, %0
  br i1 %10, label %11, label %14

11:                                               ; preds = %.lr.ph.split.us
  %12 = getelementptr inbounds i8, ptr %.tr2533.us, i64 24
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  tail call void @_Z6modifyiiiP4Nodeii(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %13, i32 noundef %.tr2634.us, i32 noundef %9)
  br label %14

14:                                               ; preds = %11, %.lr.ph.split.us
  %15 = icmp slt i32 %9, %1
  br i1 %15, label %tailrecurse.us, label %.loopexit

tailrecurse.us:                                   ; preds = %14
  %16 = getelementptr inbounds i8, ptr %.tr2533.us, i64 32
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  br label %.lr.ph.split.us

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %6
  %.tr25.lcssa = phi ptr [ %3, %6 ], [ %27, %tailrecurse ]
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %.tr25.lcssa, ptr noundef nonnull align 4 dereferenceable(4) %7)
  br label %.loopexit

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr2634 = phi i32 [ %19, %tailrecurse ], [ %4, %.lr.ph ]
  %.tr2533 = phi ptr [ %27, %tailrecurse ], [ %3, %.lr.ph ]
  %18 = add nsw i32 %.tr2634, %5
  %19 = ashr i32 %18, 1
  %20 = icmp sgt i32 %19, %0
  br i1 %20, label %21, label %24

21:                                               ; preds = %.lr.ph.split
  %22 = getelementptr inbounds i8, ptr %.tr2533, i64 24
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  tail call void @_Z6modifyiiiP4Nodeii(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %23, i32 noundef %.tr2634, i32 noundef %19)
  br label %24

24:                                               ; preds = %21, %.lr.ph.split
  %25 = icmp slt i32 %19, %1
  br i1 %25, label %tailrecurse, label %.loopexit

tailrecurse:                                      ; preds = %24
  %26 = getelementptr inbounds i8, ptr %.tr2533, i64 32
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %.not = icmp slt i32 %19, %0
  br i1 %.not, label %.lr.ph.split, label %tailrecurse._crit_edge

.loopexit:                                        ; preds = %24, %14, %tailrecurse._crit_edge
  ret void
}

; 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

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


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