; LLVM IR from tangjz/acm-icpc :: TDL_training/2016-04-10/D - Archer in Archery - lzy.ll (Z5checki)

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

@n = external dso_local global i32, align 4
@o = external dso_local global [10009 x i32], align 16
@h = external dso_local global [10009 x i32], align 16
@s = external dso_local global [10009 x i32], align 16
@t = external dso_local global [10009 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3cmpii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5checki(i32 noundef %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %41, %1
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  store i32 2, ptr %5, align 4
  br label %44

14:                                               ; preds = %9
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [10009 x i32], ptr @o, i64 0, i64 %17
  store i32 %15, ptr %18, align 4, !tbaa !5
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [10009 x i32], ptr @h, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = icmp slt i32 %19, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %14
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %44

26:                                               ; preds = %14
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [10009 x i32], ptr @h, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = sub nsw i32 %27, %31
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [10009 x i32], ptr @s, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sdiv i32 %32, %36
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [10009 x i32], ptr @t, i64 0, i64 %39
  store i32 %37, ptr %40, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %26
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %4, align 4, !tbaa !5
  br label %9, !llvm.loop !9

44:                                               ; preds = %25, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %45 = load i32, ptr %5, align 4
  switch i32 %45, label %100 [
    i32 2, label %46
    i32 1, label %98
  ]

46:                                               ; preds = %44
  %47 = load i32, ptr @n, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i32, ptr @o, i64 %48
  call void @_ZSt4sortIPiPFbiiEEvT_S3_T0_(ptr noundef @o, ptr noundef %49, ptr noundef @_Z3cmpii)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %50 = load i32, ptr @o, align 16, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [10009 x i32], ptr @t, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %6, align 4, !tbaa !5
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = icmp slt i32 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %46
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %97

58:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %91, %58
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = load i32, ptr @n, align 4, !tbaa !5
  %62 = icmp slt i32 %60, %61
  br i1 %62, label %64, label %63

63:                                               ; preds = %59
  store i32 5, ptr %5, align 4
  br label %94

64:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %65 = load i32, ptr %7, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [10009 x i32], ptr @o, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  store i32 %68, ptr %8, align 4, !tbaa !5
  %69 = load i32, ptr %8, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [10009 x i32], ptr @t, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = load i32, ptr %6, align 4, !tbaa !5
  %74 = icmp slt i32 %72, %73
  br i1 %74, label %75, label %80

75:                                               ; preds = %64
  %76 = load i32, ptr %8, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [10009 x i32], ptr @t, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  store i32 %79, ptr %6, align 4, !tbaa !5
  br label %83

80:                                               ; preds = %64
  %81 = load i32, ptr %6, align 4, !tbaa !5
  %82 = add nsw i32 %81, -1
  store i32 %82, ptr %6, align 4, !tbaa !5
  br label %83

83:                                               ; preds = %80, %75
  %84 = load i32, ptr %6, align 4, !tbaa !5
  %85 = icmp slt i32 %84, 0
  br i1 %85, label %86, label %87

86:                                               ; preds = %83
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %88

87:                                               ; preds = %83
  store i32 0, ptr %5, align 4
  br label %88

88:                                               ; preds = %87, %86
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %89 = load i32, ptr %5, align 4
  switch i32 %89, label %94 [
    i32 0, label %90
  ]

90:                                               ; preds = %88
  br label %91

91:                                               ; preds = %90
  %92 = load i32, ptr %7, align 4, !tbaa !5
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %7, align 4, !tbaa !5
  br label %59, !llvm.loop !11

94:                                               ; preds = %88, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  %95 = load i32, ptr %5, align 4
  switch i32 %95, label %97 [
    i32 5, label %96
  ]

96:                                               ; preds = %94
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %97

97:                                               ; preds = %96, %94, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %98

98:                                               ; preds = %97, %44
  %99 = load i1, ptr %2, align 1
  ret i1 %99

100:                                              ; preds = %44
  unreachable
}

; 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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiPFbiiEEvT_S3_T0_(ptr noundef, ptr noundef, ptr noundef) #3

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@o = external dso_local global [10009 x i32], align 16
@h = external dso_local local_unnamed_addr global [10009 x i32], align 16
@s = external dso_local local_unnamed_addr global [10009 x i32], align 16
@t = external dso_local local_unnamed_addr global [10009 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z3cmpii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5checki(i32 noundef %0) local_unnamed_addr #1 {
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %1
  %wide.trip.count = zext nneg i32 %2 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %9
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %9 ]
  %4 = getelementptr inbounds [10009 x i32], ptr @o, i64 0, i64 %indvars.iv
  %5 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %5, ptr %4, align 4, !tbaa !5
  %6 = getelementptr inbounds [10009 x i32], ptr @h, i64 0, i64 %indvars.iv
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, %0
  br i1 %8, label %.loopexit, label %9

9:                                                ; preds = %.lr.ph
  %10 = sub nsw i32 %0, %7
  %11 = getelementptr inbounds [10009 x i32], ptr @s, i64 0, i64 %indvars.iv
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sdiv i32 %10, %12
  %14 = getelementptr inbounds [10009 x i32], ptr @t, i64 0, i64 %indvars.iv
  store i32 %13, ptr %14, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %9, %1
  %15 = sext i32 %2 to i64
  %16 = getelementptr inbounds i32, ptr @o, i64 %15
  tail call void @_ZSt4sortIPiPFbiiEEvT_S3_T0_(ptr noundef nonnull @o, ptr noundef nonnull %16, ptr noundef nonnull @_Z3cmpii)
  %17 = load i32, ptr @o, align 16, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [10009 x i32], ptr @t, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = icmp slt i32 %20, -1
  br i1 %21, label %.loopexit, label %22

22:                                               ; preds = %._crit_edge
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %.not39 = icmp slt i32 %23, 1
  br i1 %.not39, label %.loopexit, label %.lr.ph43.preheader

.lr.ph43.preheader:                               ; preds = %22
  %24 = add nsw i32 %20, 1
  %25 = zext nneg i32 %23 to i64
  %wide.trip.count52 = zext nneg i32 %23 to i64
  br label %.lr.ph43

26:                                               ; preds = %.lr.ph43
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %exitcond53 = icmp eq i64 %indvars.iv.next50, %wide.trip.count52
  br i1 %exitcond53, label %.loopexit.loopexit.split.loop.exit55, label %.lr.ph43, !llvm.loop !11

.lr.ph43:                                         ; preds = %.lr.ph43.preheader, %26
  %indvars.iv49 = phi i64 [ 0, %.lr.ph43.preheader ], [ %indvars.iv.next50, %26 ]
  %.02440 = phi i32 [ %24, %.lr.ph43.preheader ], [ %.125, %26 ]
  %27 = getelementptr inbounds [10009 x i32], ptr @o, i64 0, i64 %indvars.iv49
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [10009 x i32], ptr @t, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = icmp slt i32 %31, %.02440
  %33 = add nsw i32 %.02440, -1
  %.125 = select i1 %32, i32 %31, i32 %33
  %34 = icmp sgt i32 %.125, -1
  br i1 %34, label %26, label %.loopexit

.loopexit.loopexit.split.loop.exit55:             ; preds = %26
  %.not.le = icmp uge i64 %indvars.iv.next50, %25
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph43, %.loopexit.loopexit.split.loop.exit55, %22, %._crit_edge
  %.5 = phi i1 [ false, %._crit_edge ], [ true, %22 ], [ %.not.le, %.loopexit.loopexit.split.loop.exit55 ], [ false, %.lr.ph43 ], [ false, %.lr.ph ]
  ret i1 %.5
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiPFbiiEEvT_S3_T0_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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 = { 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 = { inlinehint 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass