; LLVM IR from VastoLorde95/Competitive-Programming :: SPOJ/Random/QTREE3/qtree3.ll (Z11update_treeiiii)

; 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.point = type { i32, i32 }

@BLACK = external dso_local global i32, align 4
@s_tree = external dso_local global [606000 x %struct.point], 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 nounwind uwtable
declare dso_local void @_ZN5point5mergeERS_S0_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #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 uwtable
define dso_local void @_Z11update_treeiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %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
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = load i32, ptr %8, align 4, !tbaa !5
  %14 = icmp sgt i32 %12, %13
  br i1 %14, label %19, label %15

15:                                               ; preds = %4
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = load i32, ptr %8, align 4, !tbaa !5
  %18 = icmp sle i32 %16, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %15, %4
  br label %85

20:                                               ; preds = %15
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !5
  %23 = icmp eq i32 %21, %22
  br i1 %23, label %24, label %59

24:                                               ; preds = %20
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = icmp eq i32 %26, %27
  br i1 %28, label %29, label %59

29:                                               ; preds = %24
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [606000 x %struct.point], ptr @s_tree, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.point, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !9
  %35 = sub nsw i32 1, %34
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [606000 x %struct.point], ptr @s_tree, i64 0, i64 %37
  %39 = getelementptr inbounds %struct.point, ptr %38, i32 0, i32 0
  store i32 %35, ptr %39, align 8, !tbaa !9
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [606000 x %struct.point], ptr @s_tree, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.point, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !9
  %45 = load i32, ptr @BLACK, align 4, !tbaa !5
  %46 = icmp eq i32 %44, %45
  br i1 %46, label %47, label %53

47:                                               ; preds = %29
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [606000 x %struct.point], ptr @s_tree, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.point, ptr %51, i32 0, i32 1
  store i32 %48, ptr %52, align 4, !tbaa !11
  br label %58

53:                                               ; preds = %29
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [606000 x %struct.point], ptr @s_tree, i64 0, i64 %55
  %57 = getelementptr inbounds %struct.point, ptr %56, i32 0, i32 1
  store i32 -1, ptr %57, align 4, !tbaa !11
  br label %58

58:                                               ; preds = %53, %47
  br label %85

59:                                               ; preds = %24, %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = shl i32 %60, 1
  store i32 %61, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %62 = load i32, ptr %9, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = load i32, ptr %7, align 4, !tbaa !5
  %66 = add nsw i32 %64, %65
  %67 = ashr i32 %66, 1
  store i32 %67, ptr %11, align 4, !tbaa !5
  %68 = load i32, ptr %9, align 4, !tbaa !5
  %69 = load i32, ptr %6, align 4, !tbaa !5
  %70 = load i32, ptr %11, align 4, !tbaa !5
  %71 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z11update_treeiiii(i32 noundef %68, i32 noundef %69, i32 noundef %70, i32 noundef %71)
  %72 = load i32, ptr %10, align 4, !tbaa !5
  %73 = load i32, ptr %11, align 4, !tbaa !5
  %74 = load i32, ptr %7, align 4, !tbaa !5
  %75 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z11update_treeiiii(i32 noundef %72, i32 noundef %73, i32 noundef %74, i32 noundef %75)
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [606000 x %struct.point], ptr @s_tree, i64 0, i64 %77
  %79 = load i32, ptr %9, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [606000 x %struct.point], ptr @s_tree, i64 0, i64 %80
  %82 = load i32, ptr %10, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [606000 x %struct.point], ptr @s_tree, i64 0, i64 %83
  call void @_ZN5point5mergeERS_S0_(ptr noundef nonnull align 4 dereferenceable(8) %78, ptr noundef nonnull align 4 dereferenceable(8) %81, ptr noundef nonnull align 4 dereferenceable(8) %84)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %85

85:                                               ; preds = %59, %58, %19
  ret void
}

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

!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, !6, i64 0}
!10 = !{!"_ZTS5point", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}


; 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.point = type { i32, i32 }

@BLACK = external dso_local local_unnamed_addr global i32, align 4
@s_tree = external dso_local global [606000 x %struct.point], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z11update_treeiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp sle i32 %1, %3
  %.not = icmp sgt i32 %2, %3
  %or.cond = and i1 %5, %.not
  br i1 %or.cond, label %6, label %common.ret33

6:                                                ; preds = %4
  %7 = icmp eq i32 %1, %3
  %8 = add nsw i32 %1, 1
  %9 = icmp eq i32 %8, %2
  %or.cond32 = select i1 %7, i1 %9, i1 false
  br i1 %or.cond32, label %10, label %20

10:                                               ; preds = %6
  %11 = sext i32 %0 to i64
  %12 = getelementptr inbounds [606000 x %struct.point], ptr @s_tree, i64 0, i64 %11
  %13 = load i32, ptr %12, align 8, !tbaa !5
  %14 = sub nsw i32 1, %13
  store i32 %14, ptr %12, align 8, !tbaa !5
  %15 = load i32, ptr @BLACK, align 4, !tbaa !10
  %16 = icmp eq i32 %14, %15
  %17 = getelementptr inbounds i8, ptr %12, i64 4
  br i1 %16, label %18, label %19

18:                                               ; preds = %10
  store i32 %1, ptr %17, align 4, !tbaa !11
  br label %common.ret33

19:                                               ; preds = %10
  store i32 -1, ptr %17, align 4, !tbaa !11
  br label %common.ret33

common.ret33:                                     ; preds = %18, %19, %4, %20
  ret void

20:                                               ; preds = %6
  %21 = shl i32 %0, 1
  %22 = or disjoint i32 %21, 1
  %23 = add nsw i32 %2, %1
  %24 = ashr i32 %23, 1
  tail call void @_Z11update_treeiiii(i32 noundef %21, i32 noundef %1, i32 noundef %24, i32 noundef %3)
  tail call void @_Z11update_treeiiii(i32 noundef %22, i32 noundef %24, i32 noundef %2, i32 noundef %3)
  %25 = sext i32 %0 to i64
  %26 = getelementptr inbounds [606000 x %struct.point], ptr @s_tree, i64 0, i64 %25
  %27 = sext i32 %21 to i64
  %28 = getelementptr inbounds [606000 x %struct.point], ptr @s_tree, i64 0, i64 %27
  %29 = sext i32 %22 to i64
  %30 = getelementptr inbounds [606000 x %struct.point], ptr @s_tree, i64 0, i64 %29
  tail call void @_ZN5point5mergeERS_S0_(ptr noundef nonnull align 4 dereferenceable(8) %26, ptr noundef nonnull align 4 dereferenceable(8) %28, ptr noundef nonnull align 4 dereferenceable(8) %30)
  br label %common.ret33
}

attributes #0 = { 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 = !{!"_ZTS5point", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !7, i64 4}


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