; LLVM IR from kazunetakahashi/atcoder :: 2018/1215_AGC029/C.ll (Z5solvei)

; 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
@A = external dso_local global [200010 x i32], align 16
@K = external dso_local global [10000 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5solvei(i32 noundef %0) #0 {
  %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 i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %10 = load i32, ptr @A, align 16, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds i32, ptr @K, i64 %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @_ZSt4fillIPiiEvT_S1_RKT0_(ptr noundef @K, ptr noundef %12, ptr noundef nonnull align 4 dereferenceable(4) %4)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %101, %1
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = load i32, ptr @N, align 4, !tbaa !5
  %16 = sub nsw i32 %15, 1
  %17 = icmp slt i32 %14, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %13
  store i32 2, ptr %6, align 4
  br label %104

19:                                               ; preds = %13
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [200010 x i32], ptr @A, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [200010 x i32], ptr @A, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = icmp sgt i32 %23, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %19
  br label %101

31:                                               ; preds = %19
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [200010 x i32], ptr @A, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp eq i32 %35, 10000
  br i1 %36, label %37, label %38

37:                                               ; preds = %31
  br label %101

38:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  store i8 0, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [200010 x i32], ptr @A, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sub nsw i32 %42, 1
  store i32 %43, ptr %8, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %66, %38
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = icmp sge i32 %45, 0
  br i1 %46, label %48, label %47

47:                                               ; preds = %44
  store i32 5, ptr %6, align 4
  br label %69

48:                                               ; preds = %44
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [10000 x i32], ptr @K, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %51, align 4, !tbaa !5
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [10000 x i32], ptr @K, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = icmp eq i32 %57, %58
  br i1 %59, label %60, label %64

60:                                               ; preds = %48
  %61 = load i32, ptr %8, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [10000 x i32], ptr @K, i64 0, i64 %62
  store i32 0, ptr %63, align 4, !tbaa !5
  br label %65

64:                                               ; preds = %48
  store i8 1, ptr %7, align 1, !tbaa !9
  store i32 5, ptr %6, align 4
  br label %69

65:                                               ; preds = %60
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %8, align 4, !tbaa !5
  %68 = add nsw i32 %67, -1
  store i32 %68, ptr %8, align 4, !tbaa !5
  br label %44, !llvm.loop !11

69:                                               ; preds = %64, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %70

70:                                               ; preds = %69
  %71 = load i8, ptr %7, align 1, !tbaa !9, !range !13, !noundef !14
  %72 = trunc i8 %71 to i1
  br i1 %72, label %74, label %73

73:                                               ; preds = %70
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %96

74:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %75 = load i32, ptr %5, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [200010 x i32], ptr @A, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  store i32 %78, ptr %9, align 4, !tbaa !5
  br label %79

79:                                               ; preds = %92, %74
  %80 = load i32, ptr %9, align 4, !tbaa !5
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [200010 x i32], ptr @A, i64 0, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = icmp slt i32 %80, %85
  br i1 %86, label %88, label %87

87:                                               ; preds = %79
  store i32 8, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %95

88:                                               ; preds = %79
  %89 = load i32, ptr %9, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [10000 x i32], ptr @K, i64 0, i64 %90
  store i32 0, ptr %91, align 4, !tbaa !5
  br label %92

92:                                               ; preds = %88
  %93 = load i32, ptr %9, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %9, align 4, !tbaa !5
  br label %79, !llvm.loop !15

95:                                               ; preds = %87
  store i32 0, ptr %6, align 4
  br label %96

96:                                               ; preds = %95, %73
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  %97 = load i32, ptr %6, align 4
  switch i32 %97, label %104 [
    i32 0, label %98
  ]

98:                                               ; preds = %96
  br label %99

99:                                               ; preds = %98
  br label %100

100:                                              ; preds = %99
  br label %101

101:                                              ; preds = %100, %37, %30
  %102 = load i32, ptr %5, align 4, !tbaa !5
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr %5, align 4, !tbaa !5
  br label %13, !llvm.loop !16

104:                                              ; preds = %96, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %105 = load i32, ptr %6, align 4
  switch i32 %105, label %109 [
    i32 2, label %106
    i32 1, label %107
  ]

106:                                              ; preds = %104
  store i1 true, ptr %2, align 1
  br label %107

107:                                              ; preds = %106, %104
  %108 = load i1, ptr %2, align 1
  ret i1 %108

109:                                              ; preds = %104
  unreachable
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPiiEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) #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 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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


; 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
@A = external dso_local local_unnamed_addr global [200010 x i32], align 16
@K = external dso_local global [10000 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5solvei(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i32, align 4
  %3 = load i32, ptr @A, align 16, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds i32, ptr @K, i64 %4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @_ZSt4fillIPiiEvT_S1_RKT0_(ptr noundef nonnull @K, ptr noundef nonnull %5, ptr noundef nonnull align 4 dereferenceable(4) %2)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  %6 = load i32, ptr @N, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 2
  br i1 %7, label %.critedge28, label %.lr.ph38.preheader

.lr.ph38.preheader:                               ; preds = %1
  %8 = add nsw i32 %6, -1
  %9 = zext nneg i32 %8 to i64
  %wide.trip.count = zext nneg i32 %8 to i64
  %.pre = load i32, ptr @A, align 16, !tbaa !5
  br label %.lr.ph38

.lr.ph38:                                         ; preds = %.lr.ph38.preheader, %.critedge
  %10 = phi i32 [ %.pre, %.lr.ph38.preheader ], [ %13, %.critedge ]
  %indvars.iv46 = phi i64 [ 0, %.lr.ph38.preheader ], [ %indvars.iv.next47, %.critedge ]
  %11 = phi i1 [ false, %.lr.ph38.preheader ], [ %31, %.critedge ]
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %12 = getelementptr inbounds [200010 x i32], ptr @A, i64 0, i64 %indvars.iv.next47
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp sgt i32 %10, %13
  %15 = icmp eq i32 %10, 10000
  %or.cond = or i1 %15, %14
  br i1 %or.cond, label %.critedge, label %.preheader29

.preheader29:                                     ; preds = %.lr.ph38
  %16 = icmp sgt i32 %10, 0
  br i1 %16, label %.lr.ph.preheader, label %.critedge28

.lr.ph.preheader:                                 ; preds = %.preheader29
  %17 = zext nneg i32 %10 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %29
  %indvars.iv = phi i64 [ %17, %.lr.ph.preheader ], [ %indvars.iv.next, %29 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %18 = getelementptr inbounds [10000 x i32], ptr @K, i64 0, i64 %indvars.iv.next
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %18, align 4, !tbaa !5
  %21 = icmp eq i32 %20, %0
  br i1 %21, label %29, label %.preheader

.preheader:                                       ; preds = %.lr.ph
  %22 = icmp slt i32 %10, %13
  br i1 %22, label %.lr.ph36.preheader, label %.critedge

.lr.ph36.preheader:                               ; preds = %.preheader
  %23 = shl nuw nsw i64 %17, 2
  %scevgep = getelementptr i8, ptr @K, i64 %23
  %24 = xor i32 %10, -1
  %25 = add i32 %13, %24
  %26 = zext i32 %25 to i64
  %27 = shl nuw nsw i64 %26, 2
  %28 = add nuw nsw i64 %27, 4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1) %scevgep, i8 0, i64 %28, i1 false), !tbaa !5
  br label %.critedge

29:                                               ; preds = %.lr.ph
  store i32 0, ptr %18, align 4, !tbaa !5
  %30 = icmp ugt i64 %indvars.iv, 1
  br i1 %30, label %.lr.ph, label %.critedge28, !llvm.loop !9

.critedge:                                        ; preds = %.lr.ph36.preheader, %.preheader, %.lr.ph38
  %31 = icmp uge i64 %indvars.iv.next47, %9
  %exitcond = icmp eq i64 %indvars.iv.next47, %wide.trip.count
  br i1 %exitcond, label %.critedge28, label %.lr.ph38, !llvm.loop !11

.critedge28:                                      ; preds = %.critedge, %.preheader29, %29, %1
  %32 = phi i1 [ true, %1 ], [ %11, %29 ], [ %11, %.preheader29 ], [ %31, %.critedge ]
  ret i1 %32
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPiiEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass