; LLVM IR from imeplusplus/icpc-notebook :: data-structures/seg_tree2d.ll (Z4addxiiii)

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

@k = external dso_local global i32, align 4
@st = external dso_local global [100000005 x i32], align 16
@lc = external dso_local global [100000005 x i32], align 16
@rc = external dso_local global [100000005 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4addxiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = 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
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %16, label %12

12:                                               ; preds = %4
  %13 = load i32, ptr %7, align 4, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %12, %4
  br label %66

17:                                               ; preds = %12
  %18 = load i32, ptr %8, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [100000005 x i32], ptr @st, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %20, align 4, !tbaa !5
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = icmp eq i32 %23, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %17
  br label %66

27:                                               ; preds = %17
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100000005 x i32], ptr @rc, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %44, label %33

33:                                               ; preds = %27
  %34 = load i32, ptr @k, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr @k, align 4, !tbaa !5
  %36 = load i32, ptr %8, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100000005 x i32], ptr @rc, i64 0, i64 %37
  store i32 %35, ptr %38, align 4, !tbaa !5
  %39 = load i32, ptr @k, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr @k, align 4, !tbaa !5
  %41 = load i32, ptr %8, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [100000005 x i32], ptr @lc, i64 0, i64 %42
  store i32 %40, ptr %43, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %33, %27
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = add nsw i32 %47, %48
  %50 = sdiv i32 %49, 2
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100000005 x i32], ptr @lc, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  call void @_Z4addxiiii(i32 noundef %45, i32 noundef %46, i32 noundef %50, i32 noundef %54)
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = add nsw i32 %56, %57
  %59 = sdiv i32 %58, 2
  %60 = add nsw i32 %59, 1
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [100000005 x i32], ptr @rc, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  call void @_Z4addxiiii(i32 noundef %55, i32 noundef %60, i32 noundef %61, i32 noundef %65)
  br label %66

66:                                               ; preds = %44, %26, %16
  ret void
}

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

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

@k = external dso_local local_unnamed_addr global i32, align 4
@st = external dso_local local_unnamed_addr global [100000005 x i32], align 16
@lc = external dso_local local_unnamed_addr global [100000005 x i32], align 16
@rc = external dso_local local_unnamed_addr global [100000005 x i32], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z4addxiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp slt i32 %2, %0
  %6 = icmp slt i32 %0, %1
  %or.cond25 = or i1 %5, %6
  br i1 %or.cond25, label %._crit_edge, label %.lr.ph.split

.lr.ph.split:                                     ; preds = %4, %tailrecurse
  %.tr2427 = phi i32 [ %24, %tailrecurse ], [ %3, %4 ]
  %.tr2226 = phi i32 [ %23, %tailrecurse ], [ %1, %4 ]
  %7 = sext i32 %.tr2427 to i64
  %8 = getelementptr inbounds [100000005 x i32], ptr @st, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr %8, align 4, !tbaa !5
  %11 = icmp eq i32 %.tr2226, %2
  br i1 %11, label %._crit_edge, label %12

12:                                               ; preds = %.lr.ph.split
  %13 = getelementptr inbounds [100000005 x i32], ptr @rc, i64 0, i64 %7
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %15, label %.tailrecurse_crit_edge

.tailrecurse_crit_edge:                           ; preds = %12
  %.phi.trans.insert = getelementptr inbounds [100000005 x i32], ptr @lc, i64 0, i64 %7
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !5
  br label %tailrecurse

15:                                               ; preds = %12
  %16 = load i32, ptr @k, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %13, align 4, !tbaa !5
  %18 = add nsw i32 %16, 2
  store i32 %18, ptr @k, align 4, !tbaa !5
  %19 = getelementptr inbounds [100000005 x i32], ptr @lc, i64 0, i64 %7
  store i32 %18, ptr %19, align 4, !tbaa !5
  br label %tailrecurse

tailrecurse:                                      ; preds = %.tailrecurse_crit_edge, %15
  %20 = phi i32 [ %.pre, %.tailrecurse_crit_edge ], [ %18, %15 ]
  %21 = add nsw i32 %.tr2226, %2
  %22 = sdiv i32 %21, 2
  tail call void @_Z4addxiiii(i32 noundef %0, i32 noundef %.tr2226, i32 noundef %22, i32 noundef %20)
  %23 = add nsw i32 %22, 1
  %24 = load i32, ptr %13, align 4, !tbaa !5
  %.not28 = icmp slt i32 %22, %0
  br i1 %.not28, label %.lr.ph.split, label %._crit_edge

._crit_edge:                                      ; preds = %tailrecurse, %.lr.ph.split, %4
  ret void
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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: BDCEPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass