; LLVM IR from tangjz/acm-icpc :: self_training/2015-09-22/B.ll (Z5wfilpiiii)

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

@wseg = external dso_local global [200010 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5wfilpiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %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
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  %10 = load i32, ptr %7, align 4, !tbaa !5
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = icmp sle i32 %10, %11
  br i1 %12, label %13, label %25

13:                                               ; preds = %4
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = load i32, ptr %8, align 4, !tbaa !5
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %17, label %25

17:                                               ; preds = %13
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = call noundef i32 @_Z7seg_idxii(i32 noundef %18, i32 noundef %19)
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [200010 x i32], ptr @wseg, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = xor i32 %23, 1
  store i32 %24, ptr %22, align 4, !tbaa !5
  br label %49

25:                                               ; preds = %13, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = add nsw i32 %26, %27
  %29 = ashr i32 %28, 1
  store i32 %29, ptr %9, align 4, !tbaa !5
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = load i32, ptr %9, align 4, !tbaa !5
  %32 = icmp sle i32 %30, %31
  br i1 %32, label %33, label %38

33:                                               ; preds = %25
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z5wfilpiiii(i32 noundef %34, i32 noundef %35, i32 noundef %36, i32 noundef %37)
  br label %38

38:                                               ; preds = %33, %25
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = load i32, ptr %9, align 4, !tbaa !5
  %41 = icmp sgt i32 %39, %40
  br i1 %41, label %42, label %48

42:                                               ; preds = %38
  %43 = load i32, ptr %9, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z5wfilpiiii(i32 noundef %44, i32 noundef %45, i32 noundef %46, i32 noundef %47)
  br label %48

48:                                               ; preds = %42, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %49

49:                                               ; preds = %48, %17
  ret void
}

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

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

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

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

@wseg = external dso_local local_unnamed_addr global [200010 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5wfilpiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %.not24 = icmp sgt i32 %1, %3
  %.not30 = icmp sgt i32 %2, %0
  %or.cond31 = or i1 %.not24, %.not30
  br i1 %or.cond31, label %.lr.ph, label %tailrecurse._crit_edge

.lr.ph:                                           ; preds = %4
  br i1 %.not24, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %tailrecurse.us
  %.tr32.us = phi i32 [ %9, %tailrecurse.us ], [ %0, %.lr.ph ]
  %5 = add nsw i32 %.tr32.us, %1
  %6 = ashr i32 %5, 1
  %.not25.us = icmp slt i32 %6, %2
  br i1 %.not25.us, label %tailrecurse.us, label %7

7:                                                ; preds = %.lr.ph.split.us
  tail call void @_Z5wfilpiiii(i32 noundef %.tr32.us, i32 noundef %6, i32 noundef %2, i32 noundef %3)
  br label %tailrecurse.us

tailrecurse.us:                                   ; preds = %7, %.lr.ph.split.us
  %8 = icmp slt i32 %6, %3
  %9 = add nsw i32 %6, 1
  br i1 %8, label %.lr.ph.split.us, label %.loopexit

tailrecurse:                                      ; preds = %19
  %10 = add nsw i32 %17, 1
  %.not = icmp slt i32 %10, %2
  br i1 %.not, label %.lr.ph.split, label %tailrecurse._crit_edge

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %4
  %.tr.lcssa = phi i32 [ %0, %4 ], [ %10, %tailrecurse ]
  %11 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %.tr.lcssa, i32 noundef %1)
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [200010 x i32], ptr @wseg, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = xor i32 %14, 1
  store i32 %15, ptr %13, align 4, !tbaa !5
  br label %.loopexit

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr32 = phi i32 [ %10, %tailrecurse ], [ %0, %.lr.ph ]
  %16 = add nsw i32 %.tr32, %1
  %17 = ashr i32 %16, 1
  %.not25 = icmp slt i32 %17, %2
  br i1 %.not25, label %19, label %18

18:                                               ; preds = %.lr.ph.split
  tail call void @_Z5wfilpiiii(i32 noundef %.tr32, i32 noundef %17, i32 noundef %2, i32 noundef %3)
  br label %19

19:                                               ; preds = %18, %.lr.ph.split
  %20 = icmp slt i32 %17, %3
  br i1 %20, label %tailrecurse, label %.loopexit

.loopexit:                                        ; preds = %19, %tailrecurse.us, %tailrecurse._crit_edge
  ret void
}

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

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

!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: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass