; LLVM IR from tangjz/acm-icpc :: 51nod/1151.ll (Z8poly_mulPxS_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
@pw = external dso_local global [19 x i64], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8poly_mulPxS_S_(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load i32, ptr @sz, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = mul i64 %14, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 8 %12, i64 %15, i1 false)
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load i32, ptr @sz, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = mul i64 %18, 8
  call void @llvm.memset.p0.i64(ptr align 8 %16, i8 0, i64 %19, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %20

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

24:                                               ; preds = %20
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %91

25:                                               ; preds = %20
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i64, ptr %26, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !11
  %31 = icmp ne i64 %30, 0
  br i1 %31, label %33, label %32

32:                                               ; preds = %25
  br label %88

33:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %34 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %34, ptr %10, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %82, %33
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = load i32, ptr @sz, align 4, !tbaa !9
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %87

40:                                               ; preds = %35
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i64, ptr %41, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !11
  %46 = icmp ne i64 %45, 0
  br i1 %46, label %48, label %47

47:                                               ; preds = %40
  br label %82

48:                                               ; preds = %40
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i64, ptr %49, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !11
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i64, ptr %54, i64 %56
  %58 = load i64, ptr %57, align 8, !tbaa !11
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i64, ptr %59, i64 %61
  %63 = load i64, ptr %62, align 8, !tbaa !11
  %64 = load i32, ptr @sz, align 4, !tbaa !9
  %65 = load i32, ptr %10, align 4, !tbaa !9
  %66 = sub nsw i32 %64, %65
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [19 x i64], ptr @pw, i64 0, i64 %67
  %69 = load i64, ptr %68, align 8, !tbaa !11
  %70 = call noundef i64 @_Z7mod_mulxxx(i64 noundef %58, i64 noundef %63, i64 noundef %69)
  %71 = load i32, ptr @sz, align 4, !tbaa !9
  %72 = load i32, ptr %10, align 4, !tbaa !9
  %73 = sub nsw i32 %71, %72
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [19 x i64], ptr @pw, i64 0, i64 %74
  %76 = load i64, ptr %75, align 8, !tbaa !11
  %77 = call noundef i64 @_Z7mod_addxxx(i64 noundef %53, i64 noundef %70, i64 noundef %76)
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = load i32, ptr %10, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds i64, ptr %78, i64 %80
  store i64 %77, ptr %81, align 8, !tbaa !11
  br label %82

82:                                               ; preds = %48, %47
  %83 = load i32, ptr %9, align 4, !tbaa !9
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %9, align 4, !tbaa !9
  %85 = load i32, ptr %10, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %10, align 4, !tbaa !9
  br label %35, !llvm.loop !13

87:                                               ; preds = %39
  br label %88

88:                                               ; preds = %87, %32
  %89 = load i32, ptr %7, align 4, !tbaa !9
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %7, align 4, !tbaa !9
  br label %20, !llvm.loop !15

91:                                               ; preds = %24
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !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
@pw = external dso_local local_unnamed_addr global [19 x i64], align 16

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

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

.lr.ph31:                                         ; preds = %3, %.loopexit
  %12 = phi i32 [ %42, %.loopexit ], [ %10, %3 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %.loopexit ], [ 0, %3 ]
  %13 = getelementptr inbounds i64, ptr %1, i64 %indvars.iv
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %.not = icmp ne i64 %14, 0
  %15 = sext i32 %12 to i64
  %16 = icmp slt i64 %indvars.iv, %15
  %or.cond = select i1 %.not, i1 %16, i1 false
  br i1 %or.cond, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph31, %37
  %17 = phi i32 [ %38, %37 ], [ %12, %.lr.ph31 ]
  %18 = phi i32 [ %39, %37 ], [ %12, %.lr.ph31 ]
  %indvars.iv35 = phi i64 [ %indvars.iv.next36, %37 ], [ 0, %.lr.ph31 ]
  %indvars.iv33 = phi i64 [ %indvars.iv.next34, %37 ], [ %indvars.iv, %.lr.ph31 ]
  %19 = getelementptr inbounds i64, ptr %2, i64 %indvars.iv35
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %.not26 = icmp eq i64 %20, 0
  br i1 %.not26, label %37, label %21

21:                                               ; preds = %.lr.ph
  %22 = getelementptr inbounds i64, ptr %0, i64 %indvars.iv33
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = load i64, ptr %13, align 8, !tbaa !9
  %25 = trunc nuw nsw i64 %indvars.iv33 to i32
  %26 = sub nsw i32 %18, %25
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [19 x i64], ptr @pw, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %30 = tail call noundef i64 @_Z7mod_mulxxx(i64 noundef %24, i64 noundef %20, i64 noundef %29)
  %31 = load i32, ptr @sz, align 4, !tbaa !5
  %32 = sub nsw i32 %31, %25
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [19 x i64], ptr @pw, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !9
  %36 = tail call noundef i64 @_Z7mod_addxxx(i64 noundef %23, i64 noundef %30, i64 noundef %35)
  store i64 %36, ptr %22, align 8, !tbaa !9
  %.pre = load i32, ptr @sz, align 4
  br label %37

37:                                               ; preds = %.lr.ph, %21
  %38 = phi i32 [ %17, %.lr.ph ], [ %.pre, %21 ]
  %39 = phi i32 [ %18, %.lr.ph ], [ %.pre, %21 ]
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %40 = trunc nuw i64 %indvars.iv.next34 to i32
  %41 = icmp sgt i32 %39, %40
  br i1 %41, label %.lr.ph, label %.loopexit.loopexit, !llvm.loop !11

.loopexit.loopexit:                               ; preds = %37
  %.pre41 = sext i32 %38 to i64
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %.lr.ph31
  %.pre-phi = phi i64 [ %.pre41, %.loopexit.loopexit ], [ %15, %.lr.ph31 ]
  %42 = phi i32 [ %38, %.loopexit.loopexit ], [ %12, %.lr.ph31 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %43 = icmp slt i64 %indvars.iv.next, %.pre-phi
  br i1 %43, label %.lr.ph31, label %._crit_edge, !llvm.loop !13
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z7mod_mulxxx(i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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" }

!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}


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