; LLVM IR from kazunetakahashi/atcoder :: 2019/0504_AGC033/D.ll (Z8fill_dp2i)

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

@dp1 = external dso_local global [17 x [186 x [186 x [186 x i16]]]], align 16
@dp2 = external dso_local global [17 x [186 x [186 x [186 x i16]]]], align 16
@H = external dso_local global i16, align 2
@W = external dso_local global i16, align 2
@.str.3 = external hidden unnamed_addr constant [80 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [9 x i8], align 1
@__PRETTY_FUNCTION__._Z8fill_dp2i = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr 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 nounwind uwtable
define dso_local void @_Z8fill_dp2i(i32 noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i16, align 2
  %7 = alloca i16, align 2
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %126, %1
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = load i16, ptr @W, align 2, !tbaa !9
  %11 = sext i16 %10 to i32
  %12 = icmp sle i32 %9, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %8
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %129

14:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %15 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %15, ptr %5, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %122, %14
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = load i16, ptr @W, align 2, !tbaa !9
  %19 = sext i16 %18 to i32
  %20 = icmp sle i32 %17, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %125

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #3
  %23 = load i16, ptr @H, align 2, !tbaa !9
  store i16 %23, ptr %6, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #3
  %24 = load i16, ptr @H, align 2, !tbaa !9
  store i16 %24, ptr %7, align 2, !tbaa !9
  br label %25

25:                                               ; preds = %120, %22
  %26 = load i16, ptr %6, align 2, !tbaa !9
  %27 = sext i16 %26 to i32
  %28 = icmp sge i32 %27, 0
  br i1 %28, label %29, label %121

29:                                               ; preds = %25
  %30 = load i16, ptr %6, align 2, !tbaa !9
  %31 = sext i16 %30 to i32
  %32 = load i16, ptr %7, align 2, !tbaa !9
  %33 = sext i16 %32 to i32
  %34 = icmp sle i32 %31, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %29
  br label %38

36:                                               ; preds = %29
  call void @__assert_fail(ptr noundef @.str.9, ptr noundef @.str.3, i32 noundef 379, ptr noundef @__PRETTY_FUNCTION__._Z8fill_dp2i) #4
  unreachable

37:                                               ; No predecessors!
  br label %38

38:                                               ; preds = %37, %35
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sub nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [17 x [186 x [186 x [186 x i16]]]], ptr @dp2, i64 0, i64 %41
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [186 x [186 x [186 x i16]]], ptr %42, i64 0, i64 %44
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [186 x [186 x i16]], ptr %45, i64 0, i64 %47
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = sub nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [17 x [186 x [186 x [186 x i16]]]], ptr @dp2, i64 0, i64 %51
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [186 x [186 x [186 x i16]]], ptr %52, i64 0, i64 %54
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [186 x [186 x i16]], ptr %55, i64 0, i64 %57
  %59 = load i16, ptr %6, align 2, !tbaa !9
  %60 = sext i16 %59 to i64
  %61 = getelementptr inbounds [186 x i16], ptr %58, i64 0, i64 %60
  %62 = load i16, ptr %61, align 2, !tbaa !9
  %63 = sext i16 %62 to i64
  %64 = getelementptr inbounds [186 x i16], ptr %48, i64 0, i64 %63
  %65 = load i16, ptr %64, align 2, !tbaa !9
  %66 = sext i16 %65 to i32
  %67 = load i16, ptr %7, align 2, !tbaa !9
  %68 = sext i16 %67 to i32
  %69 = icmp sge i32 %66, %68
  br i1 %69, label %101, label %70

70:                                               ; preds = %38
  %71 = load i32, ptr %2, align 4, !tbaa !5
  %72 = sub nsw i32 %71, 1
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [17 x [186 x [186 x [186 x i16]]]], ptr @dp1, i64 0, i64 %73
  %75 = load i16, ptr %6, align 2, !tbaa !9
  %76 = sext i16 %75 to i64
  %77 = getelementptr inbounds [186 x [186 x [186 x i16]]], ptr %74, i64 0, i64 %76
  %78 = load i16, ptr %7, align 2, !tbaa !9
  %79 = sext i16 %78 to i64
  %80 = getelementptr inbounds [186 x [186 x i16]], ptr %77, i64 0, i64 %79
  %81 = load i32, ptr %2, align 4, !tbaa !5
  %82 = sub nsw i32 %81, 1
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [17 x [186 x [186 x [186 x i16]]]], ptr @dp1, i64 0, i64 %83
  %85 = load i16, ptr %6, align 2, !tbaa !9
  %86 = sext i16 %85 to i64
  %87 = getelementptr inbounds [186 x [186 x [186 x i16]]], ptr %84, i64 0, i64 %86
  %88 = load i16, ptr %7, align 2, !tbaa !9
  %89 = sext i16 %88 to i64
  %90 = getelementptr inbounds [186 x [186 x i16]], ptr %87, i64 0, i64 %89
  %91 = load i32, ptr %3, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [186 x i16], ptr %90, i64 0, i64 %92
  %94 = load i16, ptr %93, align 2, !tbaa !9
  %95 = sext i16 %94 to i64
  %96 = getelementptr inbounds [186 x i16], ptr %80, i64 0, i64 %95
  %97 = load i16, ptr %96, align 2, !tbaa !9
  %98 = sext i16 %97 to i32
  %99 = load i32, ptr %5, align 4, !tbaa !5
  %100 = icmp sge i32 %98, %99
  br i1 %100, label %101, label %117

101:                                              ; preds = %70, %38
  %102 = load i16, ptr %7, align 2, !tbaa !9
  %103 = load i32, ptr %2, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [17 x [186 x [186 x [186 x i16]]]], ptr @dp2, i64 0, i64 %104
  %106 = load i32, ptr %3, align 4, !tbaa !5
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds [186 x [186 x [186 x i16]]], ptr %105, i64 0, i64 %107
  %109 = load i32, ptr %5, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [186 x [186 x i16]], ptr %108, i64 0, i64 %110
  %112 = load i16, ptr %6, align 2, !tbaa !9
  %113 = sext i16 %112 to i64
  %114 = getelementptr inbounds [186 x i16], ptr %111, i64 0, i64 %113
  store i16 %102, ptr %114, align 2, !tbaa !9
  %115 = load i16, ptr %6, align 2, !tbaa !9
  %116 = add i16 %115, -1
  store i16 %116, ptr %6, align 2, !tbaa !9
  br label %120

117:                                              ; preds = %70
  %118 = load i16, ptr %7, align 2, !tbaa !9
  %119 = add i16 %118, -1
  store i16 %119, ptr %7, align 2, !tbaa !9
  br label %120

120:                                              ; preds = %117, %101
  br label %25, !llvm.loop !11

121:                                              ; preds = %25
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #3
  br label %122

122:                                              ; preds = %121
  %123 = load i32, ptr %5, align 4, !tbaa !5
  %124 = add nsw i32 %123, 1
  store i32 %124, ptr %5, align 4, !tbaa !5
  br label %16, !llvm.loop !13

125:                                              ; preds = %21
  br label %126

126:                                              ; preds = %125
  %127 = load i32, ptr %3, align 4, !tbaa !5
  %128 = add nsw i32 %127, 1
  store i32 %128, ptr %3, align 4, !tbaa !5
  br label %8, !llvm.loop !14

129:                                              ; preds = %13
  ret void
}

attributes #0 = { noreturn nounwind "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 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 #3 = { nounwind }
attributes #4 = { noreturn 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 = !{!"short", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !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"

@dp1 = external dso_local local_unnamed_addr global [17 x [186 x [186 x [186 x i16]]]], align 16
@dp2 = external dso_local local_unnamed_addr global [17 x [186 x [186 x [186 x i16]]]], align 16
@H = external dso_local local_unnamed_addr global i16, align 2
@W = external dso_local local_unnamed_addr global i16, align 2
@.str.3 = external hidden unnamed_addr constant [80 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [9 x i8], align 1
@__PRETTY_FUNCTION__._Z8fill_dp2i = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z8fill_dp2i(i32 noundef %0) local_unnamed_addr #1 {
  %2 = load i16, ptr @W, align 2, !tbaa !5
  %3 = sext i16 %2 to i32
  %.not46 = icmp slt i16 %2, 0
  br i1 %.not46, label %._crit_edge, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %1
  %4 = load i16, ptr @H, align 2, !tbaa !5
  %5 = icmp sgt i16 %4, -1
  %6 = add nsw i32 %0, -1
  %7 = sext i32 %6 to i64
  %8 = sext i32 %0 to i64
  br i1 %5, label %.preheader.us.preheader, label %._crit_edge

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %9 = add nuw nsw i32 %3, 1
  %wide.trip.count53 = zext nneg i32 %9 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %.split.us.us
  %indvars.iv = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next, %.split.us.us ]
  %10 = trunc nuw nsw i64 %indvars.iv to i32
  %smax = tail call i32 @llvm.smax.i32(i32 %10, i32 %3)
  %11 = add nuw nsw i32 %smax, 1
  %wide.trip.count = zext nneg i32 %11 to i64
  br label %.lr.ph.us.us

.lr.ph.us.us:                                     ; preds = %._crit_edge.us.us, %.preheader.us
  %indvars.iv49 = phi i64 [ %indvars.iv.next50, %._crit_edge.us.us ], [ %indvars.iv, %.preheader.us ]
  br label %12

12:                                               ; preds = %33, %.lr.ph.us.us
  %.042.us.us = phi i16 [ %4, %.lr.ph.us.us ], [ %.1.us.us, %33 ]
  %.03141.us.us = phi i16 [ %4, %.lr.ph.us.us ], [ %.132.us.us, %33 ]
  %.not38.us.us = icmp sgt i16 %.03141.us.us, %.042.us.us
  br i1 %.not38.us.us, label %.split45.us, label %13

13:                                               ; preds = %12
  %14 = zext nneg i16 %.03141.us.us to i64
  %15 = getelementptr inbounds [17 x [186 x [186 x [186 x i16]]]], ptr @dp2, i64 0, i64 %7, i64 %indvars.iv, i64 %indvars.iv49, i64 %14
  %16 = load i16, ptr %15, align 2, !tbaa !5
  %17 = sext i16 %16 to i64
  %18 = getelementptr inbounds [17 x [186 x [186 x [186 x i16]]]], ptr @dp2, i64 0, i64 %7, i64 %indvars.iv, i64 %indvars.iv49, i64 %17
  %19 = load i16, ptr %18, align 2, !tbaa !5
  %.not39.us.us = icmp slt i16 %19, %.042.us.us
  br i1 %.not39.us.us, label %20, label %28

20:                                               ; preds = %13
  %21 = zext nneg i16 %.042.us.us to i64
  %22 = getelementptr inbounds [17 x [186 x [186 x [186 x i16]]]], ptr @dp1, i64 0, i64 %7, i64 %14, i64 %21, i64 %indvars.iv
  %23 = load i16, ptr %22, align 2, !tbaa !5
  %24 = sext i16 %23 to i64
  %25 = getelementptr inbounds [17 x [186 x [186 x [186 x i16]]]], ptr @dp1, i64 0, i64 %7, i64 %14, i64 %21, i64 %24
  %26 = load i16, ptr %25, align 2, !tbaa !5
  %27 = sext i16 %26 to i64
  %.not40.us.us = icmp sgt i64 %indvars.iv49, %27
  br i1 %.not40.us.us, label %31, label %28

28:                                               ; preds = %20, %13
  %29 = getelementptr inbounds [17 x [186 x [186 x [186 x i16]]]], ptr @dp2, i64 0, i64 %8, i64 %indvars.iv, i64 %indvars.iv49, i64 %14
  store i16 %.042.us.us, ptr %29, align 2, !tbaa !5
  %30 = add nsw i16 %.03141.us.us, -1
  br label %33

31:                                               ; preds = %20
  %32 = add nsw i16 %.042.us.us, -1
  br label %33

33:                                               ; preds = %31, %28
  %.132.us.us = phi i16 [ %30, %28 ], [ %.03141.us.us, %31 ]
  %.1.us.us = phi i16 [ %.042.us.us, %28 ], [ %32, %31 ]
  %34 = icmp sgt i16 %.132.us.us, -1
  br i1 %34, label %12, label %._crit_edge.us.us, !llvm.loop !9

._crit_edge.us.us:                                ; preds = %33
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next50, %wide.trip.count
  br i1 %exitcond.not, label %.split.us.us, label %.lr.ph.us.us, !llvm.loop !11

.split.us.us:                                     ; preds = %._crit_edge.us.us
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond54.not = icmp eq i64 %indvars.iv.next, %wide.trip.count53
  br i1 %exitcond54.not, label %._crit_edge, label %.preheader.us, !llvm.loop !12

._crit_edge:                                      ; preds = %.split.us.us, %.preheader.lr.ph, %1
  ret void

.split45.us:                                      ; preds = %12
  tail call void @__assert_fail(ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.3, i32 noundef 379, ptr noundef nonnull @__PRETTY_FUNCTION__._Z8fill_dp2i) #3
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

attributes #0 = { noreturn nounwind "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" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { noreturn 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 = !{!"short", !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}
!12 = distinct !{!12, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass