; LLVM IR from tangjz/acm-icpc :: 51nod/1151.ll (Z8poly_valPxxS_S_)

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

@sz = external dso_local global i32, align 4
@pp = external dso_local global i64, align 8
@pw = external dso_local global [19 x i64], align 16
@c = external dso_local global [19 x [19 x i64]], align 16

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z7mod_addxxx(i64 noundef, i64 noundef, i64 noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z7mod_mulxxx(i64 noundef, i64 noundef, i64 noundef) #2

; 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 void @_Z8poly_valPxxS_S_(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = load i32, ptr @sz, align 4, !tbaa !11
  %16 = sext i32 %15 to i64
  %17 = mul i64 %16, 8
  call void @llvm.memset.p0.i64(ptr align 8 %14, i8 0, i64 %17, i1 false)
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = getelementptr inbounds i64, ptr %18, i64 0
  store i64 1, ptr %19, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 1, ptr %9, align 4, !tbaa !11
  br label %20

20:                                               ; preds = %39, %4
  %21 = load i32, ptr %9, align 4, !tbaa !11
  %22 = load i32, ptr @sz, align 4, !tbaa !11
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

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

25:                                               ; preds = %20
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load i32, ptr %9, align 4, !tbaa !11
  %28 = sub nsw i32 %27, 1
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i64, ptr %26, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !9
  %32 = load i64, ptr %6, align 8, !tbaa !9
  %33 = load i64, ptr @pp, align 8, !tbaa !9
  %34 = call noundef i64 @_Z7mod_mulxxx(i64 noundef %31, i64 noundef %32, i64 noundef %33)
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = load i32, ptr %9, align 4, !tbaa !11
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i64, ptr %35, i64 %37
  store i64 %34, ptr %38, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %25
  %40 = load i32, ptr %9, align 4, !tbaa !11
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %9, align 4, !tbaa !11
  br label %20, !llvm.loop !13

42:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %43

43:                                               ; preds = %134, %42
  %44 = load i32, ptr %10, align 4, !tbaa !11
  %45 = load i32, ptr @sz, align 4, !tbaa !11
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %43
  store i32 5, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %137

48:                                               ; preds = %43
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i32, ptr %10, align 4, !tbaa !11
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i64, ptr %49, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !9
  %54 = icmp ne i64 %53, 0
  br i1 %54, label %56, label %55

55:                                               ; preds = %48
  br label %134

56:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %57

57:                                               ; preds = %130, %56
  %58 = load i32, ptr %12, align 4, !tbaa !11
  %59 = load i32, ptr %10, align 4, !tbaa !11
  %60 = icmp sle i32 %58, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %57
  store i32 8, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %133

62:                                               ; preds = %57
  %63 = load i32, ptr %10, align 4, !tbaa !11
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [19 x [19 x i64]], ptr @c, i64 0, i64 %64
  %66 = load i32, ptr %12, align 4, !tbaa !11
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [19 x i64], ptr %65, i64 0, i64 %67
  %69 = load i64, ptr %68, align 8, !tbaa !9
  %70 = icmp ne i64 %69, 0
  br i1 %70, label %72, label %71

71:                                               ; preds = %62
  br label %130

72:                                               ; preds = %62
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = load i32, ptr %10, align 4, !tbaa !11
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds i64, ptr %73, i64 %75
  %77 = load i64, ptr %76, align 8, !tbaa !9
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = load i32, ptr %10, align 4, !tbaa !11
  %80 = load i32, ptr %12, align 4, !tbaa !11
  %81 = sub nsw i32 %79, %80
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds i64, ptr %78, i64 %82
  %84 = load i64, ptr %83, align 8, !tbaa !9
  %85 = load i32, ptr @sz, align 4, !tbaa !11
  %86 = load i32, ptr %12, align 4, !tbaa !11
  %87 = sub nsw i32 %85, %86
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [19 x i64], ptr @pw, i64 0, i64 %88
  %90 = load i64, ptr %89, align 8, !tbaa !9
  %91 = call noundef i64 @_Z7mod_mulxxx(i64 noundef %77, i64 noundef %84, i64 noundef %90)
  store i64 %91, ptr %13, align 8, !tbaa !9
  %92 = load i64, ptr %13, align 8, !tbaa !9
  %93 = icmp ne i64 %92, 0
  br i1 %93, label %95, label %94

94:                                               ; preds = %72
  store i32 10, ptr %11, align 4
  br label %127

95:                                               ; preds = %72
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %97 = load i32, ptr %12, align 4, !tbaa !11
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds i64, ptr %96, i64 %98
  %100 = load i64, ptr %99, align 8, !tbaa !9
  %101 = load i64, ptr %13, align 8, !tbaa !9
  %102 = load i32, ptr %10, align 4, !tbaa !11
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [19 x [19 x i64]], ptr @c, i64 0, i64 %103
  %105 = load i32, ptr %12, align 4, !tbaa !11
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [19 x i64], ptr %104, i64 0, i64 %106
  %108 = load i64, ptr %107, align 8, !tbaa !9
  %109 = load i32, ptr @sz, align 4, !tbaa !11
  %110 = load i32, ptr %12, align 4, !tbaa !11
  %111 = sub nsw i32 %109, %110
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [19 x i64], ptr @pw, i64 0, i64 %112
  %114 = load i64, ptr %113, align 8, !tbaa !9
  %115 = call noundef i64 @_Z7mod_mulxxx(i64 noundef %101, i64 noundef %108, i64 noundef %114)
  %116 = load i32, ptr @sz, align 4, !tbaa !11
  %117 = load i32, ptr %12, align 4, !tbaa !11
  %118 = sub nsw i32 %116, %117
  %119 = sext i32 %118 to i64
  %120 = getelementptr inbounds [19 x i64], ptr @pw, i64 0, i64 %119
  %121 = load i64, ptr %120, align 8, !tbaa !9
  %122 = call noundef i64 @_Z7mod_addxxx(i64 noundef %100, i64 noundef %115, i64 noundef %121)
  %123 = load ptr, ptr %7, align 8, !tbaa !5
  %124 = load i32, ptr %12, align 4, !tbaa !11
  %125 = sext i32 %124 to i64
  %126 = getelementptr inbounds i64, ptr %123, i64 %125
  store i64 %122, ptr %126, align 8, !tbaa !9
  store i32 0, ptr %11, align 4
  br label %127

127:                                              ; preds = %95, %94
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  %128 = load i32, ptr %11, align 4
  switch i32 %128, label %138 [
    i32 0, label %129
    i32 10, label %130
  ]

129:                                              ; preds = %127
  br label %130

130:                                              ; preds = %129, %127, %71
  %131 = load i32, ptr %12, align 4, !tbaa !11
  %132 = add nsw i32 %131, 1
  store i32 %132, ptr %12, align 4, !tbaa !11
  br label %57, !llvm.loop !15

133:                                              ; preds = %61
  br label %134

134:                                              ; preds = %133, %55
  %135 = load i32, ptr %10, align 4, !tbaa !11
  %136 = add nsw i32 %135, 1
  store i32 %136, ptr %10, align 4, !tbaa !11
  br label %43, !llvm.loop !16

137:                                              ; preds = %47
  ret void

138:                                              ; preds = %127
  unreachable
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

@sz = external dso_local local_unnamed_addr global i32, align 4
@pp = external dso_local local_unnamed_addr global i64, align 8
@pw = external dso_local local_unnamed_addr global [19 x i64], align 16
@c = external dso_local local_unnamed_addr global [19 x [19 x i64]], align 16

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z8poly_valPxxS_S_(ptr nocapture noundef readonly %0, i64 noundef %1, ptr nocapture noundef %2, ptr nocapture noundef %3) local_unnamed_addr #2 {
  %5 = load i32, ptr @sz, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = shl nsw i64 %6, 3
  tail call void @llvm.memset.p0.i64(ptr align 8 %2, i8 0, i64 %7, i1 false)
  store i64 1, ptr %3, align 8, !tbaa !9
  %8 = load i32, ptr @sz, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 1
  br i1 %9, label %.lr.ph, label %.preheader39

.preheader39:                                     ; preds = %.lr.ph, %4
  %10 = phi i32 [ %8, %4 ], [ %17, %.lr.ph ]
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph43, label %._crit_edge

.lr.ph:                                           ; preds = %4, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %4 ]
  %12 = getelementptr i64, ptr %3, i64 %indvars.iv
  %13 = getelementptr i8, ptr %12, i64 -8
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = load i64, ptr @pp, align 8, !tbaa !9
  %16 = tail call noundef i64 @_Z7mod_mulxxx(i64 noundef %14, i64 noundef %1, i64 noundef %15)
  store i64 %16, ptr %12, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = load i32, ptr @sz, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = icmp slt i64 %indvars.iv.next, %18
  br i1 %19, label %.lr.ph, label %.preheader39, !llvm.loop !11

._crit_edge:                                      ; preds = %.loopexit, %.preheader39
  ret void

.lr.ph43:                                         ; preds = %.preheader39, %.loopexit
  %20 = phi i32 [ %53, %.loopexit ], [ %10, %.preheader39 ]
  %indvars.iv52 = phi i64 [ %indvars.iv.next53, %.loopexit ], [ 0, %.preheader39 ]
  %indvars.iv50 = phi i64 [ %indvars.iv.next51, %.loopexit ], [ 1, %.preheader39 ]
  %21 = getelementptr inbounds i64, ptr %0, i64 %indvars.iv52
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %.not = icmp eq i64 %22, 0
  br i1 %.not, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %.lr.ph43, %52
  %indvars.iv45 = phi i64 [ %indvars.iv.next46, %52 ], [ 0, %.lr.ph43 ]
  %23 = getelementptr inbounds [19 x [19 x i64]], ptr @c, i64 0, i64 %indvars.iv52, i64 %indvars.iv45
  %24 = load i64, ptr %23, align 8, !tbaa !9
  %.not37 = icmp eq i64 %24, 0
  br i1 %.not37, label %52, label %25

25:                                               ; preds = %.preheader
  %26 = load i64, ptr %21, align 8, !tbaa !9
  %27 = sub nsw i64 %indvars.iv52, %indvars.iv45
  %28 = getelementptr inbounds i64, ptr %3, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %30 = load i32, ptr @sz, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = sub nsw i64 %31, %indvars.iv45
  %33 = getelementptr inbounds [19 x i64], ptr @pw, i64 0, i64 %32
  %34 = load i64, ptr %33, align 8, !tbaa !9
  %35 = tail call noundef i64 @_Z7mod_mulxxx(i64 noundef %26, i64 noundef %29, i64 noundef %34)
  %.not38 = icmp eq i64 %35, 0
  br i1 %.not38, label %52, label %36

36:                                               ; preds = %25
  %37 = getelementptr inbounds i64, ptr %2, i64 %indvars.iv45
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = load i64, ptr %23, align 8, !tbaa !9
  %40 = load i32, ptr @sz, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = sub nsw i64 %41, %indvars.iv45
  %43 = getelementptr inbounds [19 x i64], ptr @pw, i64 0, i64 %42
  %44 = load i64, ptr %43, align 8, !tbaa !9
  %45 = tail call noundef i64 @_Z7mod_mulxxx(i64 noundef %35, i64 noundef %39, i64 noundef %44)
  %46 = load i32, ptr @sz, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = sub nsw i64 %47, %indvars.iv45
  %49 = getelementptr inbounds [19 x i64], ptr @pw, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !9
  %51 = tail call noundef i64 @_Z7mod_addxxx(i64 noundef %38, i64 noundef %45, i64 noundef %50)
  store i64 %51, ptr %37, align 8, !tbaa !9
  br label %52

52:                                               ; preds = %36, %25, %.preheader
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next46, %indvars.iv50
  br i1 %exitcond.not, label %.loopexit.loopexit, label %.preheader, !llvm.loop !13

.loopexit.loopexit:                               ; preds = %52
  %.pre = load i32, ptr @sz, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %.lr.ph43
  %53 = phi i32 [ %.pre, %.loopexit.loopexit ], [ %20, %.lr.ph43 ]
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  %54 = sext i32 %53 to i64
  %55 = icmp slt i64 %indvars.iv.next53, %54
  %indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, 1
  br i1 %55, label %.lr.ph43, label %._crit_edge, !llvm.loop !14
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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