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

; 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
@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
declare dso_local void @_Z4addxiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3addiiiii(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
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  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
  %11 = load i32, ptr %7, align 4, !tbaa !5
  %12 = load i32, ptr %8, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %18, label %14

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

18:                                               ; preds = %14, %5
  br label %83

19:                                               ; preds = %14
  %20 = load i32, ptr %10, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100000005 x i32], ptr @st, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %31, label %25

25:                                               ; preds = %19
  %26 = load i32, ptr @k, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr @k, align 4, !tbaa !5
  %28 = load i32, ptr %10, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100000005 x i32], ptr @st, i64 0, i64 %29
  store i32 %27, ptr %30, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %25, %19
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = load i32, ptr %10, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100000005 x i32], ptr @st, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  call void @_Z4addxiiii(i32 noundef %32, i32 noundef 1, i32 noundef %33, i32 noundef %37)
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = icmp eq i32 %38, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %31
  br label %83

42:                                               ; preds = %31
  %43 = load i32, ptr %10, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [100000005 x i32], ptr @rc, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %59, label %48

48:                                               ; preds = %42
  %49 = load i32, ptr @k, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr @k, align 4, !tbaa !5
  %51 = load i32, ptr %10, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100000005 x i32], ptr @rc, i64 0, i64 %52
  store i32 %50, ptr %53, align 4, !tbaa !5
  %54 = load i32, ptr @k, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr @k, align 4, !tbaa !5
  %56 = load i32, ptr %10, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [100000005 x i32], ptr @lc, i64 0, i64 %57
  store i32 %55, ptr %58, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %48, %42
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = load i32, ptr %8, align 4, !tbaa !5
  %64 = load i32, ptr %9, align 4, !tbaa !5
  %65 = add nsw i32 %63, %64
  %66 = sdiv i32 %65, 2
  %67 = load i32, ptr %10, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [100000005 x i32], ptr @lc, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  call void @_Z3addiiiii(i32 noundef %60, i32 noundef %61, i32 noundef %62, i32 noundef %66, i32 noundef %70)
  %71 = load i32, ptr %6, align 4, !tbaa !5
  %72 = load i32, ptr %7, align 4, !tbaa !5
  %73 = load i32, ptr %8, align 4, !tbaa !5
  %74 = load i32, ptr %9, align 4, !tbaa !5
  %75 = add nsw i32 %73, %74
  %76 = sdiv i32 %75, 2
  %77 = add nsw i32 %76, 1
  %78 = load i32, ptr %9, align 4, !tbaa !5
  %79 = load i32, ptr %10, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [100000005 x i32], ptr @rc, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  call void @_Z3addiiiii(i32 noundef %71, i32 noundef %72, i32 noundef %77, i32 noundef %78, i32 noundef %82)
  br label %83

83:                                               ; preds = %59, %41, %18
  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"

@n = external dso_local local_unnamed_addr global i32, align 4
@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 uwtable
declare dso_local void @_Z4addxiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3addiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = icmp slt i32 %3, %1
  %7 = icmp slt i32 %1, %2
  %or.cond32 = or i1 %6, %7
  br i1 %or.cond32, label %._crit_edge, label %.lr.ph.split

.lr.ph.split:                                     ; preds = %5, %tailrecurse
  %.tr3134 = phi i32 [ %30, %tailrecurse ], [ %4, %5 ]
  %.tr2933 = phi i32 [ %29, %tailrecurse ], [ %2, %5 ]
  %8 = sext i32 %.tr3134 to i64
  %9 = getelementptr inbounds [100000005 x i32], ptr @st, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %11, label %14

11:                                               ; preds = %.lr.ph.split
  %12 = load i32, ptr @k, align 4, !tbaa !5
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr @k, align 4, !tbaa !5
  store i32 %13, ptr %9, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %11, %.lr.ph.split
  %15 = phi i32 [ %13, %11 ], [ %10, %.lr.ph.split ]
  %16 = load i32, ptr @n, align 4, !tbaa !5
  tail call void @_Z4addxiiii(i32 noundef %0, i32 noundef 1, i32 noundef %16, i32 noundef %15)
  %17 = icmp eq i32 %.tr2933, %3
  br i1 %17, label %._crit_edge, label %18

18:                                               ; preds = %14
  %19 = getelementptr inbounds [100000005 x i32], ptr @rc, i64 0, i64 %8
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %.not27 = icmp eq i32 %20, 0
  br i1 %.not27, label %21, label %.tailrecurse_crit_edge

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

21:                                               ; preds = %18
  %22 = load i32, ptr @k, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %19, align 4, !tbaa !5
  %24 = add nsw i32 %22, 2
  store i32 %24, ptr @k, align 4, !tbaa !5
  %25 = getelementptr inbounds [100000005 x i32], ptr @lc, i64 0, i64 %8
  store i32 %24, ptr %25, align 4, !tbaa !5
  br label %tailrecurse

tailrecurse:                                      ; preds = %.tailrecurse_crit_edge, %21
  %26 = phi i32 [ %.pre, %.tailrecurse_crit_edge ], [ %24, %21 ]
  %27 = add nsw i32 %.tr2933, %3
  %28 = sdiv i32 %27, 2
  tail call void @_Z3addiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %.tr2933, i32 noundef %28, i32 noundef %26)
  %29 = add nsw i32 %28, 1
  %30 = load i32, ptr %19, align 4, !tbaa !5
  %.not35 = icmp slt i32 %28, %1
  br i1 %.not35, label %.lr.ph.split, label %._crit_edge

._crit_edge:                                      ; preds = %tailrecurse, %14, %5
  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"}


; Effective O3 passes: BDCEPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass