; LLVM IR from tangjz/acm-icpc :: lydsy/4299.ll (Z7seg_queiiiii)

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

@que = external dso_local global [100001 x i32], align 16
@lch = external dso_local global [1700017 x i32], align 16
@rch = external dso_local global [1700017 x i32], align 16
@sum = external dso_local global [1700017 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 uwtable
define dso_local noundef i32 @_Z7seg_queiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %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
  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
  %13 = load i32, ptr %10, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = load i32, ptr %11, align 4, !tbaa !5
  %18 = icmp sle i32 %16, %17
  br i1 %18, label %19, label %29

19:                                               ; preds = %5
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [1700017 x i32], ptr @sum, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [1700017 x i32], ptr @sum, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = sub nsw i32 %23, %27
  store i32 %28, ptr %6, align 4
  br label %71

29:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = load i32, ptr %10, align 4, !tbaa !5
  %32 = add nsw i32 %30, %31
  %33 = ashr i32 %32, 1
  store i32 %33, ptr %12, align 4, !tbaa !5
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [1700017 x i32], ptr @lch, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [1700017 x i32], ptr @lch, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = load i32, ptr %9, align 4, !tbaa !5
  %43 = load i32, ptr %12, align 4, !tbaa !5
  %44 = load i32, ptr %11, align 4, !tbaa !5
  %45 = call noundef i32 @_Z7seg_queiiiii(i32 noundef %37, i32 noundef %41, i32 noundef %42, i32 noundef %43, i32 noundef %44)
  %46 = load i32, ptr %12, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = load i32, ptr %11, align 4, !tbaa !5
  %52 = icmp sle i32 %50, %51
  br i1 %52, label %53, label %67

53:                                               ; preds = %29
  %54 = load i32, ptr %7, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [1700017 x i32], ptr @rch, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [1700017 x i32], ptr @rch, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = load i32, ptr %12, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  %64 = load i32, ptr %10, align 4, !tbaa !5
  %65 = load i32, ptr %11, align 4, !tbaa !5
  %66 = call noundef i32 @_Z7seg_queiiiii(i32 noundef %57, i32 noundef %61, i32 noundef %63, i32 noundef %64, i32 noundef %65)
  br label %68

67:                                               ; preds = %29
  br label %68

68:                                               ; preds = %67, %53
  %69 = phi i32 [ %66, %53 ], [ 0, %67 ]
  %70 = add nsw i32 %45, %69
  store i32 %70, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  br label %71

71:                                               ; preds = %68, %19
  %72 = load i32, ptr %6, align 4
  ret i32 %72
}

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

@que = external dso_local local_unnamed_addr global [100001 x i32], align 16
@lch = external dso_local local_unnamed_addr global [1700017 x i32], align 16
@rch = external dso_local local_unnamed_addr global [1700017 x i32], align 16
@sum = external dso_local local_unnamed_addr global [1700017 x i32], align 16

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z7seg_queiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = sext i32 %3 to i64
  %7 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %.not = icmp sgt i32 %8, %4
  br i1 %.not, label %17, label %9

9:                                                ; preds = %5
  %10 = sext i32 %1 to i64
  %11 = getelementptr inbounds [1700017 x i32], ptr @sum, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sext i32 %0 to i64
  %14 = getelementptr inbounds [1700017 x i32], ptr @sum, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = sub nsw i32 %12, %15
  br label %40

17:                                               ; preds = %5
  %18 = add nsw i32 %3, %2
  %19 = ashr i32 %18, 1
  %20 = sext i32 %0 to i64
  %21 = getelementptr inbounds [1700017 x i32], ptr @lch, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = sext i32 %1 to i64
  %24 = getelementptr inbounds [1700017 x i32], ptr @lch, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = tail call noundef i32 @_Z7seg_queiiiii(i32 noundef %22, i32 noundef %25, i32 noundef %2, i32 noundef %19, i32 noundef %4)
  %27 = add nsw i32 %19, 1
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %.not20 = icmp sgt i32 %30, %4
  br i1 %.not20, label %37, label %31

31:                                               ; preds = %17
  %32 = getelementptr inbounds [1700017 x i32], ptr @rch, i64 0, i64 %20
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = getelementptr inbounds [1700017 x i32], ptr @rch, i64 0, i64 %23
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = tail call noundef i32 @_Z7seg_queiiiii(i32 noundef %33, i32 noundef %35, i32 noundef %27, i32 noundef %3, i32 noundef %4)
  br label %37

37:                                               ; preds = %17, %31
  %38 = phi i32 [ %36, %31 ], [ 0, %17 ]
  %39 = add nsw i32 %38, %26
  br label %40

40:                                               ; preds = %37, %9
  %.0 = phi i32 [ %16, %9 ], [ %39, %37 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(read, 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: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass