; LLVM IR from tangjz/acm-icpc :: hdu/5709.ll (Z7seg_queiiii)

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

@lch = external dso_local global [10200103 x i32], align 16
@rch = external dso_local global [10200103 x i32], align 16
@val = external dso_local global [10200103 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_queiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %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
  %11 = load i32, ptr %8, align 4, !tbaa !5
  %12 = load i32, ptr %9, align 4, !tbaa !5
  %13 = icmp sle i32 %11, %12
  br i1 %13, label %14, label %19

14:                                               ; preds = %4
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  store i32 %18, ptr %5, align 4
  br label %49

19:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = add nsw i32 %20, %21
  %23 = ashr i32 %22, 1
  store i32 %23, ptr %10, align 4, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = load i32, ptr %10, align 4, !tbaa !5
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = call noundef i32 @_Z7seg_queiiii(i32 noundef %27, i32 noundef %28, i32 noundef %29, i32 noundef %30)
  %32 = load i32, ptr %10, align 4, !tbaa !5
  %33 = load i32, ptr %9, align 4, !tbaa !5
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %35, label %45

35:                                               ; preds = %19
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = load i32, ptr %10, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = load i32, ptr %9, align 4, !tbaa !5
  %44 = call noundef i32 @_Z7seg_queiiii(i32 noundef %39, i32 noundef %41, i32 noundef %42, i32 noundef %43)
  br label %46

45:                                               ; preds = %19
  br label %46

46:                                               ; preds = %45, %35
  %47 = phi i32 [ %44, %35 ], [ 0, %45 ]
  %48 = add nsw i32 %31, %47
  store i32 %48, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %49

49:                                               ; preds = %46, %14
  %50 = load i32, ptr %5, align 4
  ret i32 %50
}

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"

@lch = external dso_local local_unnamed_addr global [10200103 x i32], align 16
@rch = external dso_local local_unnamed_addr global [10200103 x i32], align 16
@val = external dso_local local_unnamed_addr global [10200103 x i32], align 16

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z7seg_queiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %.not = icmp sgt i32 %2, %3
  br i1 %.not, label %9, label %5

5:                                                ; preds = %4
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds [10200103 x i32], ptr @val, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  br label %25

9:                                                ; preds = %4
  %10 = add nsw i32 %2, %1
  %11 = ashr i32 %10, 1
  %12 = sext i32 %0 to i64
  %13 = getelementptr inbounds [10200103 x i32], ptr @lch, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = tail call noundef i32 @_Z7seg_queiiii(i32 noundef %14, i32 noundef %1, i32 noundef %11, i32 noundef %3)
  %16 = icmp slt i32 %11, %3
  br i1 %16, label %17, label %22

17:                                               ; preds = %9
  %18 = getelementptr inbounds [10200103 x i32], ptr @rch, i64 0, i64 %12
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = add nsw i32 %11, 1
  %21 = tail call noundef i32 @_Z7seg_queiiii(i32 noundef %19, i32 noundef %20, i32 noundef %2, i32 noundef %3)
  br label %22

22:                                               ; preds = %9, %17
  %23 = phi i32 [ %21, %17 ], [ 0, %9 ]
  %24 = add nsw i32 %23, %15
  br label %25

25:                                               ; preds = %22, %5
  %.0 = phi i32 [ %8, %5 ], [ %24, %22 ]
  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