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

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

@n = 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
declare dso_local noundef i32 @_Z6countxiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5countiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %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 %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
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %18

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

18:                                               ; preds = %14, %5
  store i32 0, ptr %6, align 4
  br label %58

19:                                               ; preds = %14
  %20 = load i32, ptr %10, align 4, !tbaa !5
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = icmp sle i32 %20, %21
  br i1 %22, label %23, label %31

23:                                               ; preds = %19
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = load i32, ptr %11, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [100000005 x i32], ptr @st, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = call noundef i32 @_Z6countxiiii(i32 noundef %24, i32 noundef 1, i32 noundef %25, i32 noundef %29)
  store i32 %30, ptr %6, align 4
  br label %58

31:                                               ; preds = %19
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = load i32, ptr %10, align 4, !tbaa !5
  %37 = add nsw i32 %35, %36
  %38 = sdiv i32 %37, 2
  %39 = load i32, ptr %11, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100000005 x i32], ptr @lc, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = call noundef i32 @_Z5countiiiii(i32 noundef %32, i32 noundef %33, i32 noundef %34, i32 noundef %38, i32 noundef %42)
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = load i32, ptr %9, align 4, !tbaa !5
  %47 = load i32, ptr %10, align 4, !tbaa !5
  %48 = add nsw i32 %46, %47
  %49 = sdiv i32 %48, 2
  %50 = add nsw i32 %49, 1
  %51 = load i32, ptr %10, align 4, !tbaa !5
  %52 = load i32, ptr %11, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100000005 x i32], ptr @rc, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = call noundef i32 @_Z5countiiiii(i32 noundef %44, i32 noundef %45, i32 noundef %50, i32 noundef %51, i32 noundef %55)
  %57 = add nsw i32 %43, %56
  store i32 %57, ptr %6, align 4
  br label %58

58:                                               ; preds = %31, %23, %18
  %59 = load i32, ptr %6, align 4
  ret i32 %59
}

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"

@n = 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 uwtable
declare dso_local noundef i32 @_Z6countxiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5countiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %.not32 = icmp eq i32 %4, 0
  %6 = icmp slt i32 %1, %2
  %or.cond33 = or i1 %6, %.not32
  br i1 %or.cond33, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %.not24 = icmp sgt i32 %3, %1
  br i1 %.not24, label %tailrecurse.us, label %.lr.ph.split

tailrecurse.us:                                   ; preds = %.lr.ph, %tailrecurse.us
  %.tr2836.us = phi i32 [ %15, %tailrecurse.us ], [ %4, %.lr.ph ]
  %.tr2635.us = phi i32 [ %13, %tailrecurse.us ], [ %2, %.lr.ph ]
  %accumulator.tr34.us = phi i32 [ %16, %tailrecurse.us ], [ 0, %.lr.ph ]
  %7 = add nsw i32 %.tr2635.us, %3
  %8 = sdiv i32 %7, 2
  %9 = sext i32 %.tr2836.us to i64
  %10 = getelementptr inbounds [100000005 x i32], ptr @lc, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = tail call noundef i32 @_Z5countiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %.tr2635.us, i32 noundef %8, i32 noundef %11)
  %13 = add nsw i32 %8, 1
  %14 = getelementptr inbounds [100000005 x i32], ptr @rc, i64 0, i64 %9
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = add nsw i32 %12, %accumulator.tr34.us
  %.not.us = icmp eq i32 %15, 0
  %17 = icmp sge i32 %8, %1
  %or.cond.us = or i1 %17, %.not.us
  br i1 %or.cond.us, label %.loopexit, label %tailrecurse.us

.lr.ph.split:                                     ; preds = %.lr.ph
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = sext i32 %4 to i64
  %20 = getelementptr inbounds [100000005 x i32], ptr @st, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = tail call noundef i32 @_Z6countxiiii(i32 noundef %0, i32 noundef 1, i32 noundef %18, i32 noundef %21)
  br label %.loopexit

.loopexit:                                        ; preds = %tailrecurse.us, %5, %.lr.ph.split
  %accumulator.ret.tr = phi i32 [ %22, %.lr.ph.split ], [ 0, %5 ], [ %16, %tailrecurse.us ]
  ret i32 %accumulator.ret.tr
}

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass