; LLVM IR from Dev-XYS/Algorithms :: Persistent-Segment-Tree(Sum).ll (Z6modifyiiP4nodeS0_)

; 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 { i32, i32, i32, 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #1

; 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 @_Z6modifyiiP4nodeS0_(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  %10 = load ptr, ptr %8, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.node, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = load ptr, ptr %7, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.node, ptr %13, i32 0, i32 0
  store i32 %12, ptr %14, align 8, !tbaa !11
  %15 = load ptr, ptr %8, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.node, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !13
  %18 = load ptr, ptr %7, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.node, ptr %18, i32 0, i32 1
  store i32 %17, ptr %19, align 4, !tbaa !13
  %20 = load ptr, ptr %7, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.node, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = load ptr, ptr %7, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.node, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !13
  %26 = icmp eq i32 %22, %25
  br i1 %26, label %27, label %31

27:                                               ; preds = %4
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = load ptr, ptr %7, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.node, ptr %29, i32 0, i32 2
  store i32 %28, ptr %30, align 8, !tbaa !14
  br label %91

31:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %32 = load ptr, ptr %7, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.node, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %7, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.node, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !13
  %38 = add nsw i32 %34, %37
  %39 = ashr i32 %38, 1
  store i32 %39, ptr %9, align 4, !tbaa !5
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = load i32, ptr %9, align 4, !tbaa !5
  %42 = icmp sle i32 %40, %41
  br i1 %42, label %43, label %60

43:                                               ; preds = %31
  %44 = load ptr, ptr %8, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.node, ptr %44, i32 0, i32 4
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  %47 = load ptr, ptr %7, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.node, ptr %47, i32 0, i32 4
  store ptr %46, ptr %48, align 8, !tbaa !15
  %49 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 32) #4
  %50 = load ptr, ptr %7, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.node, ptr %50, i32 0, i32 3
  store ptr %49, ptr %51, align 8, !tbaa !16
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = load ptr, ptr %7, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.node, ptr %54, i32 0, i32 3
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  %57 = load ptr, ptr %8, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.node, ptr %57, i32 0, i32 3
  %59 = load ptr, ptr %58, align 8, !tbaa !16
  call void @_Z6modifyiiP4nodeS0_(i32 noundef %52, i32 noundef %53, ptr noundef %56, ptr noundef %59)
  br label %77

60:                                               ; preds = %31
  %61 = load ptr, ptr %8, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.node, ptr %61, i32 0, i32 3
  %63 = load ptr, ptr %62, align 8, !tbaa !16
  %64 = load ptr, ptr %7, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.node, ptr %64, i32 0, i32 3
  store ptr %63, ptr %65, align 8, !tbaa !16
  %66 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 32) #4
  %67 = load ptr, ptr %7, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.node, ptr %67, i32 0, i32 4
  store ptr %66, ptr %68, align 8, !tbaa !15
  %69 = load i32, ptr %5, align 4, !tbaa !5
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = load ptr, ptr %7, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.node, ptr %71, i32 0, i32 4
  %73 = load ptr, ptr %72, align 8, !tbaa !15
  %74 = load ptr, ptr %8, align 8, !tbaa !9
  %75 = getelementptr inbounds %struct.node, ptr %74, i32 0, i32 4
  %76 = load ptr, ptr %75, align 8, !tbaa !15
  call void @_Z6modifyiiP4nodeS0_(i32 noundef %69, i32 noundef %70, ptr noundef %73, ptr noundef %76)
  br label %77

77:                                               ; preds = %60, %43
  %78 = load ptr, ptr %7, align 8, !tbaa !9
  %79 = getelementptr inbounds %struct.node, ptr %78, i32 0, i32 3
  %80 = load ptr, ptr %79, align 8, !tbaa !16
  %81 = getelementptr inbounds %struct.node, ptr %80, i32 0, i32 2
  %82 = load i32, ptr %81, align 8, !tbaa !14
  %83 = load ptr, ptr %7, align 8, !tbaa !9
  %84 = getelementptr inbounds %struct.node, ptr %83, i32 0, i32 4
  %85 = load ptr, ptr %84, align 8, !tbaa !15
  %86 = getelementptr inbounds %struct.node, ptr %85, i32 0, i32 2
  %87 = load i32, ptr %86, align 8, !tbaa !14
  %88 = add nsw i32 %82, %87
  %89 = load ptr, ptr %7, align 8, !tbaa !9
  %90 = getelementptr inbounds %struct.node, ptr %89, i32 0, i32 2
  store i32 %88, ptr %90, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %91

91:                                               ; preds = %77, %27
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nobuiltin allocsize(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 }
attributes #4 = { builtin allocsize(0) }

!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 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4node", !6, i64 0, !6, i64 4, !6, i64 8, !10, i64 16, !10, i64 24}
!13 = !{!12, !6, i64 4}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !10, i64 24}
!16 = !{!12, !10, i64 16}


; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6modifyiiP4nodeS0_(i32 noundef %0, i32 noundef %1, ptr nocapture noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #1 {
  %5 = load i32, ptr %3, align 8, !tbaa !5
  store i32 %5, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %3, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %2, i64 4
  store i32 %7, ptr %8, align 4, !tbaa !11
  %9 = icmp eq i32 %5, %7
  br i1 %9, label %29, label %10

10:                                               ; preds = %4
  %11 = add nsw i32 %7, %5
  %12 = ashr i32 %11, 1
  %.not = icmp slt i32 %12, %0
  %. = select i1 %.not, i64 16, i64 24
  %.41 = select i1 %.not, i64 24, i64 16
  %13 = getelementptr inbounds i8, ptr %3, i64 %.
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %2, i64 %.
  store ptr %14, ptr %15, align 8, !tbaa !12
  %16 = tail call noalias noundef nonnull dereferenceable(32) ptr @_Znwm(i64 noundef 32) #2
  %17 = getelementptr inbounds i8, ptr %2, i64 %.41
  store ptr %16, ptr %17, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %3, i64 %.41
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  tail call void @_Z6modifyiiP4nodeS0_(i32 noundef %0, i32 noundef %1, ptr noundef nonnull %16, ptr noundef %19)
  %20 = getelementptr inbounds i8, ptr %2, i64 16
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = getelementptr inbounds i8, ptr %21, i64 8
  %23 = load i32, ptr %22, align 8, !tbaa !14
  %24 = getelementptr inbounds i8, ptr %2, i64 24
  %25 = load ptr, ptr %24, align 8, !tbaa !15
  %26 = getelementptr inbounds i8, ptr %25, i64 8
  %27 = load i32, ptr %26, align 8, !tbaa !14
  %28 = add nsw i32 %27, %23
  br label %29

29:                                               ; preds = %4, %10
  %.sink39 = phi i32 [ %28, %10 ], [ %1, %4 ]
  %30 = getelementptr inbounds i8, ptr %2, i64 8
  store i32 %.sink39, ptr %30, align 8, !tbaa !14
  ret void
}

attributes #0 = { nobuiltin allocsize(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 = { builtin allocsize(0) }

!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, !7, i64 0}
!6 = !{!"_ZTS4node", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!10, !10, i64 0}
!13 = !{!6, !10, i64 16}
!14 = !{!6, !7, i64 8}
!15 = !{!6, !10, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass