; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/SHORT/COOK65/Problem E/E.ll (Z16propagateSegTreexxxx)

; 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 { i64, i64, i64 }

@P = external dso_local global i64, align 8
@tree = external dso_local global [1048576 x %struct.node], 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 uwtable
declare dso_local void @_ZN4node7combineERS_S0_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24), 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 nounwind uwtable
declare dso_local void @_ZN4node6updateEx(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z16propagateSegTreexxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store i64 %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !5
  %12 = load i64, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %12
  %14 = getelementptr inbounds %struct.node, ptr %13, i32 0, i32 1
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = load i64, ptr %8, align 8, !tbaa !5
  %17 = add nsw i64 %15, %16
  %18 = load i64, ptr @P, align 8, !tbaa !5
  %19 = icmp slt i64 %17, %18
  br i1 %19, label %26, label %20

20:                                               ; preds = %4
  %21 = load i64, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.node, ptr %22, i32 0, i32 0
  %24 = load i64, ptr %23, align 8, !tbaa !11
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %30, label %26

26:                                               ; preds = %20, %4
  %27 = load i64, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %27
  %29 = load i64, ptr %8, align 8, !tbaa !5
  call void @_ZN4node6updateEx(ptr noundef nonnull align 8 dereferenceable(24) %28, i64 noundef %29)
  br label %84

30:                                               ; preds = %20
  %31 = load i64, ptr %6, align 8, !tbaa !5
  %32 = add nsw i64 %31, 1
  %33 = load i64, ptr %7, align 8, !tbaa !5
  %34 = icmp eq i64 %32, %33
  br i1 %34, label %35, label %52

35:                                               ; preds = %30
  %36 = load i64, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.node, ptr %37, i32 0, i32 1
  %39 = load i64, ptr %38, align 8, !tbaa !9
  %40 = load i64, ptr %8, align 8, !tbaa !5
  %41 = add nsw i64 %39, %40
  %42 = load i64, ptr @P, align 8, !tbaa !5
  %43 = icmp sge i64 %41, %42
  br i1 %43, label %44, label %51

44:                                               ; preds = %35
  %45 = load i64, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %45
  %47 = getelementptr inbounds %struct.node, ptr %46, i32 0, i32 1
  store i64 -1099511627776, ptr %47, align 8, !tbaa !9
  %48 = load i64, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %48
  %50 = getelementptr inbounds %struct.node, ptr %49, i32 0, i32 0
  store i64 0, ptr %50, align 8, !tbaa !11
  br label %51

51:                                               ; preds = %44, %35
  br label %84

52:                                               ; preds = %30
  %53 = load i64, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %53
  %55 = getelementptr inbounds %struct.node, ptr %54, i32 0, i32 2
  %56 = load i64, ptr %55, align 8, !tbaa !12
  %57 = load i64, ptr %8, align 8, !tbaa !5
  %58 = add nsw i64 %57, %56
  store i64 %58, ptr %8, align 8, !tbaa !5
  %59 = load i64, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.node, ptr %60, i32 0, i32 2
  store i64 0, ptr %61, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %62 = load i64, ptr %5, align 8, !tbaa !5
  %63 = shl i64 %62, 1
  store i64 %63, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %64 = load i64, ptr %9, align 8, !tbaa !5
  %65 = add nsw i64 %64, 1
  store i64 %65, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %66 = load i64, ptr %6, align 8, !tbaa !5
  %67 = load i64, ptr %7, align 8, !tbaa !5
  %68 = add nsw i64 %66, %67
  %69 = ashr i64 %68, 1
  store i64 %69, ptr %11, align 8, !tbaa !5
  %70 = load i64, ptr %9, align 8, !tbaa !5
  %71 = load i64, ptr %6, align 8, !tbaa !5
  %72 = load i64, ptr %11, align 8, !tbaa !5
  %73 = load i64, ptr %8, align 8, !tbaa !5
  call void @_Z16propagateSegTreexxxx(i64 noundef %70, i64 noundef %71, i64 noundef %72, i64 noundef %73)
  %74 = load i64, ptr %10, align 8, !tbaa !5
  %75 = load i64, ptr %11, align 8, !tbaa !5
  %76 = load i64, ptr %7, align 8, !tbaa !5
  %77 = load i64, ptr %8, align 8, !tbaa !5
  call void @_Z16propagateSegTreexxxx(i64 noundef %74, i64 noundef %75, i64 noundef %76, i64 noundef %77)
  %78 = load i64, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %78
  %80 = load i64, ptr %9, align 8, !tbaa !5
  %81 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %80
  %82 = load i64, ptr %10, align 8, !tbaa !5
  %83 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %82
  call void @_ZN4node7combineERS_S0_(ptr noundef nonnull align 8 dereferenceable(24) %79, ptr noundef nonnull align 8 dereferenceable(24) %81, ptr noundef nonnull align 8 dereferenceable(24) %83)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %84

84:                                               ; preds = %52, %51, %26
  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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTS4node", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 0}
!12 = !{!10, !6, 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"

%struct.node = type { i64, i64, i64 }

@P = external dso_local local_unnamed_addr global i64, align 8
@tree = external dso_local global [1048576 x %struct.node], align 16

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z16propagateSegTreexxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %0
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = add nsw i64 %7, %3
  %9 = load i64, ptr @P, align 8, !tbaa !10
  %10 = icmp slt i64 %8, %9
  br i1 %10, label %13, label %11

11:                                               ; preds = %4
  %12 = load i64, ptr %5, align 8, !tbaa !11
  %.not = icmp eq i64 %12, 0
  br i1 %.not, label %13, label %14

13:                                               ; preds = %11, %4
  tail call void @_ZN4node6updateEx(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %3)
  br label %common.ret32

14:                                               ; preds = %11
  %15 = add nsw i64 %1, 1
  %16 = icmp eq i64 %15, %2
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  store i64 -1099511627776, ptr %6, align 8, !tbaa !5
  store i64 0, ptr %5, align 8, !tbaa !11
  br label %common.ret32

common.ret32:                                     ; preds = %17, %13, %18
  ret void

18:                                               ; preds = %14
  %19 = getelementptr inbounds i8, ptr %5, i64 16
  %20 = load i64, ptr %19, align 8, !tbaa !12
  %21 = add nsw i64 %20, %3
  store i64 0, ptr %19, align 8, !tbaa !12
  %22 = shl i64 %0, 1
  %23 = or disjoint i64 %22, 1
  %24 = add nsw i64 %2, %1
  %25 = ashr i64 %24, 1
  tail call void @_Z16propagateSegTreexxxx(i64 noundef %22, i64 noundef %1, i64 noundef %25, i64 noundef %21)
  tail call void @_Z16propagateSegTreexxxx(i64 noundef %23, i64 noundef %25, i64 noundef %2, i64 noundef %21)
  %26 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %22
  %27 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %23
  tail call void @_ZN4node7combineERS_S0_(ptr noundef nonnull align 8 dereferenceable(24) %5, ptr noundef nonnull align 8 dereferenceable(24) %26, ptr noundef nonnull align 8 dereferenceable(24) %27)
  br label %common.ret32
}

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

!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 8}
!6 = !{!"_ZTS4node", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 16}


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