; LLVM IR from tangjz/acm-icpc :: codeforces/gym/101234A.ll (Z6segUpdiiiii)

; 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 { i32, i32, i32 }

@seg = external dso_local global [200003 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z6segIdxii(i32 noundef, i32 noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z5segUpiii(i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6segUpdiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %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
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = call noundef i32 @_Z6segIdxii(i32 noundef %16, i32 noundef %17)
  store i32 %18, ptr %11, align 4, !tbaa !5
  %19 = load i32, ptr %8, align 4, !tbaa !5
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = icmp sle i32 %19, %20
  br i1 %21, label %22, label %31

22:                                               ; preds = %5
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = load i32, ptr %9, align 4, !tbaa !5
  %25 = icmp sle i32 %23, %24
  br i1 %25, label %26, label %31

26:                                               ; preds = %22
  %27 = load i32, ptr %11, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [200003 x %struct.Node], ptr @seg, i64 0, i64 %28
  %30 = load i32, ptr %10, align 4, !tbaa !5
  call void @_ZN4Node5applyEi(ptr noundef nonnull align 4 dereferenceable(12) %29, i32 noundef %30)
  store i32 1, ptr %12, align 4
  br label %70

31:                                               ; preds = %22, %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = add nsw i32 %32, %33
  %35 = ashr i32 %34, 1
  store i32 %35, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = load i32, ptr %13, align 4, !tbaa !5
  %38 = call noundef i32 @_Z6segIdxii(i32 noundef %36, i32 noundef %37)
  store i32 %38, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %39 = load i32, ptr %13, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = call noundef i32 @_Z6segIdxii(i32 noundef %40, i32 noundef %41)
  store i32 %42, ptr %15, align 4, !tbaa !5
  %43 = load i32, ptr %11, align 4, !tbaa !5
  %44 = load i32, ptr %14, align 4, !tbaa !5
  %45 = load i32, ptr %15, align 4, !tbaa !5
  call void @_Z7segDowniii(i32 noundef %43, i32 noundef %44, i32 noundef %45)
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = load i32, ptr %13, align 4, !tbaa !5
  %48 = icmp sle i32 %46, %47
  br i1 %48, label %49, label %55

49:                                               ; preds = %31
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = load i32, ptr %13, align 4, !tbaa !5
  %52 = load i32, ptr %8, align 4, !tbaa !5
  %53 = load i32, ptr %9, align 4, !tbaa !5
  %54 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z6segUpdiiiii(i32 noundef %50, i32 noundef %51, i32 noundef %52, i32 noundef %53, i32 noundef %54)
  br label %55

55:                                               ; preds = %49, %31
  %56 = load i32, ptr %9, align 4, !tbaa !5
  %57 = load i32, ptr %13, align 4, !tbaa !5
  %58 = icmp sgt i32 %56, %57
  br i1 %58, label %59, label %66

59:                                               ; preds = %55
  %60 = load i32, ptr %13, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = load i32, ptr %8, align 4, !tbaa !5
  %64 = load i32, ptr %9, align 4, !tbaa !5
  %65 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z6segUpdiiiii(i32 noundef %61, i32 noundef %62, i32 noundef %63, i32 noundef %64, i32 noundef %65)
  br label %66

66:                                               ; preds = %59, %55
  %67 = load i32, ptr %11, align 4, !tbaa !5
  %68 = load i32, ptr %14, align 4, !tbaa !5
  %69 = load i32, ptr %15, align 4, !tbaa !5
  call void @_Z5segUpiii(i32 noundef %67, i32 noundef %68, i32 noundef %69)
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  store i32 0, ptr %12, align 4
  br label %70

70:                                               ; preds = %66, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  %71 = load i32, ptr %12, align 4
  switch i32 %71, label %73 [
    i32 0, label %72
    i32 1, label %72
  ]

72:                                               ; preds = %70, %70
  ret void

73:                                               ; preds = %70
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Node5applyEi(ptr noundef nonnull align 4 dereferenceable(12), i32 noundef) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z7segDowniii(i32 noundef, i32 noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { 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 #4 = { 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 { i32, i32, i32 }

@seg = external dso_local global [200003 x %struct.Node], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6segUpdiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = tail call noundef i32 @_Z6segIdxii(i32 noundef %0, i32 noundef %1)
  %.not = icmp sgt i32 %2, %0
  %.not36 = icmp sgt i32 %1, %3
  %or.cond = or i1 %.not, %.not36
  br i1 %or.cond, label %10, label %7

7:                                                ; preds = %5
  %8 = sext i32 %6 to i64
  %9 = getelementptr inbounds [200003 x %struct.Node], ptr @seg, i64 0, i64 %8
  tail call void @_ZN4Node5applyEi(ptr noundef nonnull align 4 dereferenceable(12) %9, i32 noundef %4)
  br label %21

10:                                               ; preds = %5
  %11 = add nsw i32 %1, %0
  %12 = ashr i32 %11, 1
  %13 = tail call noundef i32 @_Z6segIdxii(i32 noundef %0, i32 noundef %12)
  %14 = add nsw i32 %12, 1
  %15 = tail call noundef i32 @_Z6segIdxii(i32 noundef %14, i32 noundef %1)
  tail call void @_Z7segDowniii(i32 noundef %6, i32 noundef %13, i32 noundef %15)
  %.not37 = icmp slt i32 %12, %2
  br i1 %.not37, label %17, label %16

16:                                               ; preds = %10
  tail call void @_Z6segUpdiiiii(i32 noundef %0, i32 noundef %12, i32 noundef %2, i32 noundef %3, i32 noundef %4)
  br label %17

17:                                               ; preds = %16, %10
  %18 = icmp slt i32 %12, %3
  br i1 %18, label %19, label %20

19:                                               ; preds = %17
  tail call void @_Z6segUpdiiiii(i32 noundef %14, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4)
  br label %20

20:                                               ; preds = %19, %17
  tail call void @_Z5segUpiii(i32 noundef %6, i32 noundef %13, i32 noundef %15)
  br label %21

21:                                               ; preds = %20, %7
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Node5applyEi(ptr noundef nonnull align 4 dereferenceable(12), i32 noundef) local_unnamed_addr #1 align 2

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

attributes #0 = { inlinehint 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 = { 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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass