; LLVM IR from ayush-tulsyan/ACM-ICPC-Handbook :: code/segmentTree.ll (Z10updateTreeixiii)

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

@Arr = external dso_local global [101000 x i64], align 16
@Tree = external dso_local global [404000 x i64], 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10updateTreeixiii(i32 noundef %0, i64 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !5
  %14 = load i32, ptr %8, align 4, !tbaa !5
  %15 = load i32, ptr %10, align 4, !tbaa !5
  %16 = icmp sgt i32 %14, %15
  br i1 %16, label %21, label %17

17:                                               ; preds = %5
  %18 = load i32, ptr %9, align 4, !tbaa !5
  %19 = load i32, ptr %10, align 4, !tbaa !5
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %17, %5
  br label %80

22:                                               ; preds = %17
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = load i32, ptr %9, align 4, !tbaa !5
  %25 = icmp eq i32 %23, %24
  br i1 %25, label %26, label %35

26:                                               ; preds = %22
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [404000 x i64], ptr @Tree, i64 0, i64 %29
  store i64 %27, ptr %30, align 8, !tbaa !9
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = load i32, ptr %10, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [101000 x i64], ptr @Arr, i64 0, i64 %33
  store i64 %31, ptr %34, align 8, !tbaa !9
  br label %79

35:                                               ; preds = %22
  %36 = load i32, ptr %8, align 4, !tbaa !5
  %37 = load i32, ptr %10, align 4, !tbaa !5
  %38 = icmp sle i32 %36, %37
  br i1 %38, label %39, label %78

39:                                               ; preds = %35
  %40 = load i32, ptr %9, align 4, !tbaa !5
  %41 = load i32, ptr %10, align 4, !tbaa !5
  %42 = icmp sge i32 %40, %41
  br i1 %42, label %43, label %78

43:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = load i32, ptr %9, align 4, !tbaa !5
  %46 = add nsw i32 %44, %45
  %47 = ashr i32 %46, 1
  store i32 %47, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = shl i32 %48, 1
  store i32 %49, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %50 = load i32, ptr %12, align 4, !tbaa !5
  %51 = or i32 %50, 1
  store i32 %51, ptr %13, align 4, !tbaa !5
  %52 = load i32, ptr %12, align 4, !tbaa !5
  %53 = load i32, ptr %10, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = load i64, ptr %7, align 8, !tbaa !9
  %56 = trunc i64 %55 to i32
  %57 = load i32, ptr %8, align 4, !tbaa !5
  %58 = load i32, ptr %11, align 4, !tbaa !5
  call void @_Z10updateTreeixiii(i32 noundef %52, i64 noundef %54, i32 noundef %56, i32 noundef %57, i32 noundef %58)
  %59 = load i32, ptr %13, align 4, !tbaa !5
  %60 = load i32, ptr %10, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = load i64, ptr %7, align 8, !tbaa !9
  %63 = trunc i64 %62 to i32
  %64 = load i32, ptr %11, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  %66 = load i32, ptr %9, align 4, !tbaa !5
  call void @_Z10updateTreeixiii(i32 noundef %59, i64 noundef %61, i32 noundef %63, i32 noundef %65, i32 noundef %66)
  %67 = load i32, ptr %12, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [404000 x i64], ptr @Tree, i64 0, i64 %68
  %70 = load i32, ptr %13, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [404000 x i64], ptr @Tree, i64 0, i64 %71
  %73 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %69, ptr noundef nonnull align 8 dereferenceable(8) %72)
  %74 = load i64, ptr %73, align 8, !tbaa !9
  %75 = load i32, ptr %6, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [404000 x i64], ptr @Tree, i64 0, i64 %76
  store i64 %74, ptr %77, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %78

78:                                               ; preds = %43, %39, %35
  br label %79

79:                                               ; preds = %78, %26
  br label %80

80:                                               ; preds = %79, %21
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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, !10, i64 0}
!10 = !{!"long long", !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"

@Arr = external dso_local local_unnamed_addr global [101000 x i64], align 16
@Tree = external dso_local global [404000 x i64], align 16

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z10updateTreeixiii(i32 noundef %0, i64 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = icmp sgt i32 %2, %4
  %7 = icmp slt i32 %3, %4
  %or.cond = or i1 %6, %7
  br i1 %or.cond, label %common.ret35, label %8

8:                                                ; preds = %5
  %9 = icmp eq i32 %2, %3
  br i1 %9, label %10, label %15

10:                                               ; preds = %8
  %11 = sext i32 %0 to i64
  %12 = getelementptr inbounds [404000 x i64], ptr @Tree, i64 0, i64 %11
  store i64 %1, ptr %12, align 8, !tbaa !5
  %13 = sext i32 %4 to i64
  %14 = getelementptr inbounds [101000 x i64], ptr @Arr, i64 0, i64 %13
  store i64 %1, ptr %14, align 8, !tbaa !5
  br label %common.ret35

common.ret35:                                     ; preds = %10, %5, %15
  ret void

15:                                               ; preds = %8
  %16 = add nsw i32 %3, %2
  %17 = ashr i32 %16, 1
  %18 = shl i32 %0, 1
  %19 = or disjoint i32 %18, 1
  %20 = sext i32 %4 to i64
  %21 = trunc i64 %1 to i32
  tail call void @_Z10updateTreeixiii(i32 noundef %18, i64 noundef %20, i32 noundef %21, i32 noundef %2, i32 noundef %17)
  %22 = add nsw i32 %17, 1
  tail call void @_Z10updateTreeixiii(i32 noundef %19, i64 noundef %20, i32 noundef %21, i32 noundef %22, i32 noundef %3)
  %23 = sext i32 %18 to i64
  %24 = getelementptr inbounds [404000 x i64], ptr @Tree, i64 0, i64 %23
  %25 = sext i32 %19 to i64
  %26 = getelementptr inbounds [404000 x i64], ptr @Tree, i64 0, i64 %25
  %27 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %24, ptr noundef nonnull align 8 dereferenceable(8) %26)
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = sext i32 %0 to i64
  %30 = getelementptr inbounds [404000 x i64], ptr @Tree, i64 0, i64 %29
  store i64 %28, ptr %30, align 8, !tbaa !5
  br label %common.ret35
}

attributes #0 = { inlinehint 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 #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, !6, i64 0}
!6 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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