; LLVM IR from VastoLorde95/Competitive-Programming :: SPOJ/Random/SEGSQRSS/seg.ll (Z5shiftiii)

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3updiiix(i32 noundef, i32 noundef, i32 noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5shiftiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %8 = load i32, ptr %5, align 4, !tbaa !5
  %9 = load i32, ptr %6, align 4, !tbaa !5
  %10 = add nsw i32 %8, %9
  %11 = sdiv i32 %10, 2
  store i32 %11, ptr %7, align 4, !tbaa !5
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [131072 x i32], ptr @lazy2, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %17, label %52

17:                                               ; preds = %3
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = mul nsw i32 %18, 2
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [262144 x %struct.node], ptr @tree, i64 0, i64 %20
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [131072 x i32], ptr @lazy2, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = sub nsw i32 %27, %28
  call void @_ZN4node7update2Exi(ptr noundef nonnull align 8 dereferenceable(16) %21, i64 noundef %26, i32 noundef %29)
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = mul nsw i32 %30, 2
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [131072 x i32], ptr @lazy, i64 0, i64 %32
  store i32 0, ptr %33, align 4, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = mul nsw i32 %34, 2
  %36 = add nsw i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [262144 x %struct.node], ptr @tree, i64 0, i64 %37
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [131072 x i32], ptr @lazy2, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = sub nsw i32 %44, %45
  call void @_ZN4node7update2Exi(ptr noundef nonnull align 8 dereferenceable(16) %38, i64 noundef %43, i32 noundef %46)
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = mul nsw i32 %47, 2
  %49 = add nsw i32 %48, 1
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [131072 x i32], ptr @lazy, i64 0, i64 %50
  store i32 0, ptr %51, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %17, %3
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = mul nsw i32 %53, 2
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [131072 x i32], ptr @lazy, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  call void @_Z3updiiix(i32 noundef %54, i32 noundef %55, i32 noundef %56, i64 noundef %61)
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = mul nsw i32 %62, 2
  %64 = add nsw i32 %63, 1
  %65 = load i32, ptr %7, align 4, !tbaa !5
  %66 = load i32, ptr %6, align 4, !tbaa !5
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [131072 x i32], ptr @lazy, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  call void @_Z3updiiix(i32 noundef %64, i32 noundef %65, i32 noundef %66, i64 noundef %71)
  %72 = load i32, ptr %4, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [131072 x i32], ptr @lazy, i64 0, i64 %73
  store i32 0, ptr %74, align 4, !tbaa !5
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [131072 x i32], ptr @lazy2, i64 0, i64 %76
  store i32 0, ptr %77, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4node7update2Exi(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, i32 noundef) #2 align 2

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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

@lazy = external dso_local local_unnamed_addr global [131072 x i32], align 16
@lazy2 = external dso_local local_unnamed_addr global [131072 x i32], align 16
@tree = external dso_local global [262144 x %struct.node], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3updiiix(i32 noundef, i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5shiftiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = add nsw i32 %2, %1
  %5 = sdiv i32 %4, 2
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds [131072 x i32], ptr @lazy2, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  %10 = shl nsw i32 %0, 1
  br i1 %9, label %11, label %._crit_edge

._crit_edge:                                      ; preds = %3
  %.pre23 = or disjoint i32 %10, 1
  br label %24

11:                                               ; preds = %3
  %12 = sext i32 %10 to i64
  %13 = getelementptr inbounds [262144 x %struct.node], ptr @tree, i64 0, i64 %12
  %14 = zext nneg i32 %8 to i64
  %15 = sub nsw i32 %5, %1
  tail call void @_ZN4node7update2Exi(ptr noundef nonnull align 8 dereferenceable(16) %13, i64 noundef %14, i32 noundef %15)
  %16 = getelementptr inbounds [131072 x i32], ptr @lazy, i64 0, i64 %12
  store i32 0, ptr %16, align 8, !tbaa !5
  %17 = or disjoint i32 %10, 1
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [262144 x %struct.node], ptr @tree, i64 0, i64 %18
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = sub nsw i32 %2, %5
  tail call void @_ZN4node7update2Exi(ptr noundef nonnull align 8 dereferenceable(16) %19, i64 noundef %21, i32 noundef %22)
  %23 = getelementptr inbounds [131072 x i32], ptr @lazy, i64 0, i64 %18
  store i32 0, ptr %23, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %._crit_edge, %11
  %.pre-phi24 = phi i32 [ %.pre23, %._crit_edge ], [ %17, %11 ]
  %25 = getelementptr inbounds [131072 x i32], ptr @lazy, i64 0, i64 %6
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  tail call void @_Z3updiiix(i32 noundef %10, i32 noundef %1, i32 noundef %5, i64 noundef %27)
  %28 = load i32, ptr %25, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  tail call void @_Z3updiiix(i32 noundef %.pre-phi24, i32 noundef %5, i32 noundef %2, i64 noundef %29)
  store i32 0, ptr %25, align 4, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !5
  ret void
}

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

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


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