; LLVM IR from imteekay/algorithms :: competitive-programming/acm-icpc-br/regionals_2017_1/A.ll (Z11lazy_updateiiiiii)

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

@segtree = external dso_local global [1048576 x i32], align 16
@lazy = external dso_local global [1048576 x i32], 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 nounwind uwtable
declare dso_local void @_Z9propagateiii(i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z11lazy_updateiiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #2 {
  %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
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !5
  store i32 %5, ptr %12, align 4, !tbaa !5
  %14 = load i32, ptr %7, align 4, !tbaa !5
  %15 = load i32, ptr %8, align 4, !tbaa !5
  %16 = load i32, ptr %9, align 4, !tbaa !5
  call void @_Z9propagateiii(i32 noundef %14, i32 noundef %15, i32 noundef %16)
  %17 = load i32, ptr %8, align 4, !tbaa !5
  %18 = load i32, ptr %9, align 4, !tbaa !5
  %19 = icmp sgt i32 %17, %18
  br i1 %19, label %28, label %20

20:                                               ; preds = %6
  %21 = load i32, ptr %9, align 4, !tbaa !5
  %22 = load i32, ptr %10, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %28, label %24

24:                                               ; preds = %20
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = load i32, ptr %11, align 4, !tbaa !5
  %27 = icmp sgt i32 %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %24, %20, %6
  br label %85

29:                                               ; preds = %24
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = load i32, ptr %10, align 4, !tbaa !5
  %32 = icmp sge i32 %30, %31
  br i1 %32, label %33, label %64

33:                                               ; preds = %29
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = load i32, ptr %11, align 4, !tbaa !5
  %36 = icmp sle i32 %34, %35
  br i1 %36, label %37, label %64

37:                                               ; preds = %33
  %38 = load i32, ptr %12, align 4, !tbaa !5
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [1048576 x i32], ptr @segtree, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = add nsw i32 %42, %38
  store i32 %43, ptr %41, align 4, !tbaa !5
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = load i32, ptr %9, align 4, !tbaa !5
  %46 = icmp ne i32 %44, %45
  br i1 %46, label %47, label %63

47:                                               ; preds = %37
  %48 = load i32, ptr %12, align 4, !tbaa !5
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = mul nsw i32 %49, 2
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [1048576 x i32], ptr @lazy, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = add nsw i32 %53, %48
  store i32 %54, ptr %52, align 4, !tbaa !5
  %55 = load i32, ptr %12, align 4, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = mul nsw i32 %56, 2
  %58 = add nsw i32 %57, 1
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [1048576 x i32], ptr @lazy, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = add nsw i32 %61, %55
  store i32 %62, ptr %60, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %47, %37
  br label %85

64:                                               ; preds = %33, %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %65 = load i32, ptr %8, align 4, !tbaa !5
  %66 = load i32, ptr %9, align 4, !tbaa !5
  %67 = add nsw i32 %65, %66
  %68 = sdiv i32 %67, 2
  store i32 %68, ptr %13, align 4, !tbaa !5
  %69 = load i32, ptr %7, align 4, !tbaa !5
  %70 = mul nsw i32 %69, 2
  %71 = load i32, ptr %8, align 4, !tbaa !5
  %72 = load i32, ptr %13, align 4, !tbaa !5
  %73 = load i32, ptr %10, align 4, !tbaa !5
  %74 = load i32, ptr %11, align 4, !tbaa !5
  %75 = load i32, ptr %12, align 4, !tbaa !5
  call void @_Z11lazy_updateiiiiii(i32 noundef %70, i32 noundef %71, i32 noundef %72, i32 noundef %73, i32 noundef %74, i32 noundef %75)
  %76 = load i32, ptr %7, align 4, !tbaa !5
  %77 = mul nsw i32 %76, 2
  %78 = add nsw i32 %77, 1
  %79 = load i32, ptr %13, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  %81 = load i32, ptr %9, align 4, !tbaa !5
  %82 = load i32, ptr %10, align 4, !tbaa !5
  %83 = load i32, ptr %11, align 4, !tbaa !5
  %84 = load i32, ptr %12, align 4, !tbaa !5
  call void @_Z11lazy_updateiiiiii(i32 noundef %78, i32 noundef %80, i32 noundef %81, i32 noundef %82, i32 noundef %83, i32 noundef %84)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %85

85:                                               ; preds = %64, %63, %28
  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"}


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

@segtree = external dso_local local_unnamed_addr global [1048576 x i32], align 16
@lazy = external dso_local local_unnamed_addr global [1048576 x i32], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z11lazy_updateiiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  tail call void @_Z9propagateiii(i32 noundef %0, i32 noundef %1, i32 noundef %2)
  %7 = icmp sgt i32 %1, %2
  %8 = icmp slt i32 %2, %3
  %9 = icmp sgt i32 %1, %4
  %10 = or i1 %7, %9
  %or.cond4050 = or i1 %10, %8
  br i1 %or.cond4050, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %6
  %.not38 = icmp sgt i32 %2, %4
  %invariant.smin59 = tail call i32 @llvm.smin.i32(i32 %4, i32 %2)
  br i1 %.not38, label %tailrecurse.us, label %.lr.ph.split.split

tailrecurse.us:                                   ; preds = %.lr.ph, %tailrecurse.us
  %.tr4252.us = phi i32 [ %15, %tailrecurse.us ], [ %1, %.lr.ph ]
  %.tr51.us = phi i32 [ %14, %tailrecurse.us ], [ %0, %.lr.ph ]
  %11 = add nsw i32 %.tr4252.us, %2
  %12 = sdiv i32 %11, 2
  %13 = shl nsw i32 %.tr51.us, 1
  tail call void @_Z11lazy_updateiiiiii(i32 noundef %13, i32 noundef %.tr4252.us, i32 noundef %12, i32 noundef %3, i32 noundef %4, i32 noundef %5)
  %14 = or disjoint i32 %13, 1
  %15 = add nsw i32 %12, 1
  tail call void @_Z9propagateiii(i32 noundef %14, i32 noundef %15, i32 noundef %2)
  %or.cond40.us.not = icmp slt i32 %12, %invariant.smin59
  br i1 %or.cond40.us.not, label %tailrecurse.us, label %.loopexit

.lr.ph.split.split:                               ; preds = %.lr.ph, %tailrecurse
  %.tr4252 = phi i32 [ %32, %tailrecurse ], [ %1, %.lr.ph ]
  %.tr51 = phi i32 [ %31, %tailrecurse ], [ %0, %.lr.ph ]
  %.not = icmp slt i32 %.tr4252, %3
  br i1 %.not, label %tailrecurse, label %.split.us

.split.us:                                        ; preds = %.lr.ph.split.split
  %16 = sext i32 %.tr51 to i64
  %17 = getelementptr inbounds [1048576 x i32], ptr @segtree, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = add nsw i32 %18, %5
  store i32 %19, ptr %17, align 4, !tbaa !5
  %.not39 = icmp eq i32 %.tr4252, %2
  br i1 %.not39, label %.loopexit, label %20

20:                                               ; preds = %.split.us
  %21 = shl nsw i32 %.tr51, 1
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1048576 x i32], ptr @lazy, i64 0, i64 %22
  %24 = load <2 x i32>, ptr %23, align 8, !tbaa !5
  %25 = insertelement <2 x i32> poison, i32 %5, i64 0
  %26 = shufflevector <2 x i32> %25, <2 x i32> poison, <2 x i32> zeroinitializer
  %27 = add nsw <2 x i32> %24, %26
  store <2 x i32> %27, ptr %23, align 8, !tbaa !5
  br label %.loopexit

tailrecurse:                                      ; preds = %.lr.ph.split.split
  %28 = add nsw i32 %.tr4252, %2
  %29 = sdiv i32 %28, 2
  %30 = shl nsw i32 %.tr51, 1
  tail call void @_Z11lazy_updateiiiiii(i32 noundef %30, i32 noundef %.tr4252, i32 noundef %29, i32 noundef %3, i32 noundef %4, i32 noundef %5)
  %31 = or disjoint i32 %30, 1
  %32 = add nsw i32 %29, 1
  tail call void @_Z9propagateiii(i32 noundef %31, i32 noundef %32, i32 noundef %2)
  %or.cond40.not = icmp slt i32 %29, %invariant.smin59
  br i1 %or.cond40.not, label %.lr.ph.split.split, label %.loopexit

.loopexit:                                        ; preds = %tailrecurse, %tailrecurse.us, %6, %.split.us, %20
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #1

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" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass