; LLVM IR from tangjz/acm-icpc :: hdu/5261.ll (Z5get_liiii)

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

@resL = external dso_local global [262144 x i32], align 16
@seg = external dso_local global [262144 x i64], align 16

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5get_liiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #2 {
  %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
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = 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
  %14 = load i32, ptr %8, align 4, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %17, label %28

17:                                               ; preds = %4
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %19 = load i32, ptr %9, align 4, !tbaa !5
  %20 = icmp sle i32 %18, %19
  br i1 %20, label %21, label %28

21:                                               ; preds = %17
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = call noundef i32 @_Z2idii(i32 noundef %22, i32 noundef %23)
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [262144 x i32], ptr @resL, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  store i32 %27, ptr %5, align 4
  br label %84

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

36:                                               ; preds = %28
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = load i32, ptr %10, align 4, !tbaa !5
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = load i32, ptr %9, align 4, !tbaa !5
  %41 = call noundef i32 @_Z5get_liiii(i32 noundef %37, i32 noundef %38, i32 noundef %39, i32 noundef %40)
  store i32 %41, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %83

42:                                               ; preds = %28
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = icmp sgt i32 %43, %44
  br i1 %45, label %46, label %53

46:                                               ; preds = %42
  %47 = load i32, ptr %10, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = load i32, ptr %8, align 4, !tbaa !5
  %51 = load i32, ptr %9, align 4, !tbaa !5
  %52 = call noundef i32 @_Z5get_liiii(i32 noundef %48, i32 noundef %49, i32 noundef %50, i32 noundef %51)
  store i32 %52, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %83

53:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = load i32, ptr %10, align 4, !tbaa !5
  %56 = load i32, ptr %8, align 4, !tbaa !5
  %57 = load i32, ptr %9, align 4, !tbaa !5
  %58 = call noundef i32 @_Z5get_liiii(i32 noundef %54, i32 noundef %55, i32 noundef %56, i32 noundef %57)
  store i32 %58, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %59 = load i32, ptr %10, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = load i32, ptr %9, align 4, !tbaa !5
  %64 = call noundef i32 @_Z5get_liiii(i32 noundef %60, i32 noundef %61, i32 noundef %62, i32 noundef %63)
  store i32 %64, ptr %13, align 4, !tbaa !5
  %65 = load i32, ptr %12, align 4, !tbaa !5
  %66 = load i32, ptr %12, align 4, !tbaa !5
  %67 = call noundef i32 @_Z2idii(i32 noundef %65, i32 noundef %66)
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [262144 x i64], ptr @seg, i64 0, i64 %68
  %70 = load i64, ptr %69, align 8, !tbaa !9
  %71 = load i32, ptr %13, align 4, !tbaa !5
  %72 = load i32, ptr %13, align 4, !tbaa !5
  %73 = call noundef i32 @_Z2idii(i32 noundef %71, i32 noundef %72)
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [262144 x i64], ptr @seg, i64 0, i64 %74
  %76 = load i64, ptr %75, align 8, !tbaa !9
  %77 = icmp sge i64 %70, %76
  br i1 %77, label %78, label %80

78:                                               ; preds = %53
  %79 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %79, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %82

80:                                               ; preds = %53
  %81 = load i32, ptr %13, align 4, !tbaa !5
  store i32 %81, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %82

82:                                               ; preds = %80, %78
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %83

83:                                               ; preds = %82, %46, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %84

84:                                               ; preds = %83, %21
  %85 = load i32, ptr %5, align 4
  ret i32 %85
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}


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

@resL = external dso_local local_unnamed_addr global [262144 x i32], align 16
@seg = external dso_local local_unnamed_addr global [262144 x i64], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z5get_liiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  br label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %15, %4
  %.tr.ph = phi i32 [ %16, %15 ], [ %0, %4 ]
  %.tr46.ph = phi i32 [ %.us-phi51, %15 ], [ %1, %4 ]
  %.not = icmp slt i32 %.tr.ph, %2
  br i1 %.not, label %tailrecurse.us, label %tailrecurse

tailrecurse.us:                                   ; preds = %tailrecurse.outer, %tailrecurse.us
  %.tr46.us = phi i32 [ %6, %tailrecurse.us ], [ %.tr46.ph, %tailrecurse.outer ]
  %5 = add i32 %.tr46.us, %.tr.ph
  %6 = ashr i32 %5, 1
  %.not44.us = icmp slt i32 %6, %3
  br i1 %.not44.us, label %.split.us, label %tailrecurse.us

tailrecurse:                                      ; preds = %tailrecurse.outer, %11
  %.tr46 = phi i32 [ %13, %11 ], [ %.tr46.ph, %tailrecurse.outer ]
  %.not43 = icmp sgt i32 %.tr46, %3
  br i1 %.not43, label %11, label %common.ret

common.ret:                                       ; preds = %tailrecurse
  %7 = tail call noundef i32 @_Z2idii(i32 noundef %.tr.ph, i32 noundef %.tr46)
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [262144 x i32], ptr @resL, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  br label %common.ret71

11:                                               ; preds = %tailrecurse
  %12 = add i32 %.tr46, %.tr.ph
  %13 = ashr i32 %12, 1
  %.not44 = icmp slt i32 %13, %3
  br i1 %.not44, label %.split.us, label %tailrecurse

.split.us:                                        ; preds = %11, %tailrecurse.us
  %.us-phi = phi i32 [ %6, %tailrecurse.us ], [ %13, %11 ]
  %.us-phi51 = phi i32 [ %.tr46.us, %tailrecurse.us ], [ %.tr46, %11 ]
  %14 = icmp slt i32 %.us-phi, %2
  br i1 %14, label %15, label %17

15:                                               ; preds = %.split.us
  %16 = add nsw i32 %.us-phi, 1
  br label %tailrecurse.outer

common.ret71:                                     ; preds = %17, %common.ret
  %common.ret71.op = phi i32 [ %10, %common.ret ], [ %., %17 ]
  ret i32 %common.ret71.op

17:                                               ; preds = %.split.us
  %18 = tail call noundef i32 @_Z5get_liiii(i32 noundef %.tr.ph, i32 noundef %.us-phi, i32 noundef %2, i32 noundef %3)
  %19 = add nsw i32 %.us-phi, 1
  %20 = tail call noundef i32 @_Z5get_liiii(i32 noundef %19, i32 noundef %.us-phi51, i32 noundef %2, i32 noundef %3)
  %21 = tail call noundef i32 @_Z2idii(i32 noundef %18, i32 noundef %18)
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [262144 x i64], ptr @seg, i64 0, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !9
  %25 = tail call noundef i32 @_Z2idii(i32 noundef %20, i32 noundef %20)
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [262144 x i64], ptr @seg, i64 0, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %.not45 = icmp slt i64 %24, %28
  %. = select i1 %.not45, i32 %20, i32 %18
  br label %common.ret71
}

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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass