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

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

@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
declare dso_local void @_Z16propagateSegTreexxxx(i64 noundef, i64 noundef, i64 noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z12querySegTreexxxxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5) #1 {
  %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
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  store i64 %0, ptr %8, align 8, !tbaa !5
  store i64 %1, ptr %9, align 8, !tbaa !5
  store i64 %2, ptr %10, align 8, !tbaa !5
  store i64 %3, ptr %11, align 8, !tbaa !5
  store i64 %4, ptr %12, align 8, !tbaa !5
  store i64 %5, ptr %13, align 8, !tbaa !5
  %18 = load i64, ptr %10, align 8, !tbaa !5
  %19 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %18
  %20 = load i64, ptr %13, align 8, !tbaa !5
  call void @_ZN4node6updateEx(ptr noundef nonnull align 8 dereferenceable(24) %19, i64 noundef %20)
  %21 = load i64, ptr %8, align 8, !tbaa !5
  %22 = load i64, ptr %12, align 8, !tbaa !5
  %23 = icmp sge i64 %21, %22
  br i1 %23, label %32, label %24

24:                                               ; preds = %6
  %25 = load i64, ptr %11, align 8, !tbaa !5
  %26 = load i64, ptr %9, align 8, !tbaa !5
  %27 = icmp sge i64 %25, %26
  br i1 %27, label %32, label %28

28:                                               ; preds = %24
  %29 = load i64, ptr %8, align 8, !tbaa !5
  %30 = load i64, ptr %9, align 8, !tbaa !5
  %31 = icmp sge i64 %29, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %28, %24, %6
  store i64 0, ptr %7, align 8
  br label %93

33:                                               ; preds = %28
  %34 = load i64, ptr %8, align 8, !tbaa !5
  %35 = load i64, ptr %11, align 8, !tbaa !5
  %36 = icmp sle i64 %34, %35
  br i1 %36, label %37, label %53

37:                                               ; preds = %33
  %38 = load i64, ptr %12, align 8, !tbaa !5
  %39 = load i64, ptr %9, align 8, !tbaa !5
  %40 = icmp sle i64 %38, %39
  br i1 %40, label %41, label %53

41:                                               ; preds = %37
  %42 = load i64, ptr %10, align 8, !tbaa !5
  %43 = load i64, ptr %11, align 8, !tbaa !5
  %44 = load i64, ptr %12, align 8, !tbaa !5
  call void @_Z16propagateSegTreexxxx(i64 noundef %42, i64 noundef %43, i64 noundef %44, i64 noundef 0)
  %45 = load i64, ptr %12, align 8, !tbaa !5
  %46 = load i64, ptr %11, align 8, !tbaa !5
  %47 = sub nsw i64 %45, %46
  %48 = load i64, ptr %10, 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
  %51 = load i64, ptr %50, align 8, !tbaa !9
  %52 = sub nsw i64 %47, %51
  store i64 %52, ptr %7, align 8
  br label %93

53:                                               ; preds = %37, %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %54 = load i64, ptr %10, align 8, !tbaa !5
  %55 = shl i64 %54, 1
  store i64 %55, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %56 = load i64, ptr %14, align 8, !tbaa !5
  %57 = add nsw i64 %56, 1
  store i64 %57, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %58 = load i64, ptr %11, align 8, !tbaa !5
  %59 = load i64, ptr %12, align 8, !tbaa !5
  %60 = add nsw i64 %58, %59
  %61 = ashr i64 %60, 1
  store i64 %61, ptr %16, align 8, !tbaa !5
  %62 = load i64, ptr %10, align 8, !tbaa !5
  %63 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %62
  %64 = getelementptr inbounds %struct.node, ptr %63, i32 0, i32 2
  %65 = load i64, ptr %64, align 8, !tbaa !11
  store i64 %65, ptr %13, align 8, !tbaa !5
  %66 = load i64, ptr %10, align 8, !tbaa !5
  %67 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %66
  %68 = getelementptr inbounds %struct.node, ptr %67, i32 0, i32 2
  store i64 0, ptr %68, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %69 = load i64, ptr %8, align 8, !tbaa !5
  %70 = load i64, ptr %9, align 8, !tbaa !5
  %71 = load i64, ptr %14, align 8, !tbaa !5
  %72 = load i64, ptr %11, align 8, !tbaa !5
  %73 = load i64, ptr %16, align 8, !tbaa !5
  %74 = load i64, ptr %13, align 8, !tbaa !5
  %75 = call noundef i64 @_Z12querySegTreexxxxxx(i64 noundef %69, i64 noundef %70, i64 noundef %71, i64 noundef %72, i64 noundef %73, i64 noundef %74)
  %76 = load i64, ptr %8, align 8, !tbaa !5
  %77 = load i64, ptr %9, align 8, !tbaa !5
  %78 = load i64, ptr %15, align 8, !tbaa !5
  %79 = load i64, ptr %16, align 8, !tbaa !5
  %80 = load i64, ptr %12, align 8, !tbaa !5
  %81 = load i64, ptr %13, align 8, !tbaa !5
  %82 = call noundef i64 @_Z12querySegTreexxxxxx(i64 noundef %76, i64 noundef %77, i64 noundef %78, i64 noundef %79, i64 noundef %80, i64 noundef %81)
  %83 = add nsw i64 %75, %82
  %84 = trunc i64 %83 to i32
  store i32 %84, ptr %17, align 4, !tbaa !12
  %85 = load i64, ptr %10, align 8, !tbaa !5
  %86 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %85
  %87 = load i64, ptr %14, align 8, !tbaa !5
  %88 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %87
  %89 = load i64, ptr %15, align 8, !tbaa !5
  %90 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %89
  call void @_ZN4node7combineERS_S0_(ptr noundef nonnull align 8 dereferenceable(24) %86, ptr noundef nonnull align 8 dereferenceable(24) %88, ptr noundef nonnull align 8 dereferenceable(24) %90)
  %91 = load i32, ptr %17, align 4, !tbaa !12
  %92 = sext i32 %91 to i64
  store i64 %92, ptr %7, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %93

93:                                               ; preds = %53, %41, %32
  %94 = load i64, ptr %7, align 8
  ret i64 %94
}

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 0}
!10 = !{!"_ZTS4node", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 16}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !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"

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

@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
declare dso_local void @_Z16propagateSegTreexxxx(i64 noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z12querySegTreexxxxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5) local_unnamed_addr #0 {
  %7 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %2
  tail call void @_ZN4node6updateEx(ptr noundef nonnull align 8 dereferenceable(24) %7, i64 noundef %5)
  %.not = icmp slt i64 %0, %4
  %.not45 = icmp slt i64 %3, %1
  %or.cond = and i1 %.not45, %.not
  %.not46 = icmp slt i64 %0, %1
  %or.cond49 = and i1 %.not46, %or.cond
  br i1 %or.cond49, label %8, label %common.ret53

8:                                                ; preds = %6
  %.not47 = icmp sgt i64 %0, %3
  %.not48 = icmp sgt i64 %4, %1
  %or.cond50 = or i1 %.not47, %.not48
  br i1 %or.cond50, label %13, label %9

9:                                                ; preds = %8
  tail call void @_Z16propagateSegTreexxxx(i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef 0)
  %10 = load i64, ptr %7, align 8, !tbaa !5
  %11 = add i64 %10, %3
  %12 = sub i64 %4, %11
  br label %common.ret53

common.ret53:                                     ; preds = %6, %9, %13
  %common.ret53.op = phi i64 [ %25, %13 ], [ %12, %9 ], [ 0, %6 ]
  ret i64 %common.ret53.op

13:                                               ; preds = %8
  %14 = shl i64 %2, 1
  %15 = or disjoint i64 %14, 1
  %16 = add nsw i64 %4, %3
  %17 = ashr i64 %16, 1
  %18 = getelementptr inbounds i8, ptr %7, i64 16
  %19 = load i64, ptr %18, align 8, !tbaa !10
  store i64 0, ptr %18, align 8, !tbaa !10
  %20 = tail call noundef i64 @_Z12querySegTreexxxxxx(i64 noundef %0, i64 noundef %1, i64 noundef %14, i64 noundef %3, i64 noundef %17, i64 noundef %19)
  %21 = tail call noundef i64 @_Z12querySegTreexxxxxx(i64 noundef %0, i64 noundef %1, i64 noundef %15, i64 noundef %17, i64 noundef %4, i64 noundef %19)
  %22 = add nsw i64 %21, %20
  %23 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %14
  %24 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %15
  tail call void @_ZN4node7combineERS_S0_(ptr noundef nonnull align 8 dereferenceable(24) %7, ptr noundef nonnull align 8 dereferenceable(24) %23, ptr noundef nonnull align 8 dereferenceable(24) %24)
  %sext = shl i64 %22, 32
  %25 = ashr exact i64 %sext, 32
  br label %common.ret53
}

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 0}
!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 = !{!6, !7, i64 16}


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