; LLVM IR from tangjz/acm-icpc :: lydsy (4588)

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

@iact = external dso_local global [50 x i32], align 16
@deg = external dso_local global i32, align 4
@val = external dso_local global [50 x i32], align 16
@n = external dso_local global i32, align 4
@sum = external dso_local global i64, align 8
@values = external dso_local global [50 x i64], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5valuei(i32 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 uwtable
declare dso_local void @_Z5transii(i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  store i32 0, ptr @iact, align 16, !tbaa !5
  store i32 1, ptr getelementptr inbounds ([50 x i32], ptr @iact, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %28, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 50
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %31

11:                                               ; preds = %7
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sdiv i32 1000000007, %12
  %14 = sext i32 %13 to i64
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = srem i32 1000000007, %15
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [50 x i32], ptr @iact, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = mul nsw i64 %14, %20
  %22 = srem i64 %21, 1000000007
  %23 = sub nsw i64 1000000007, %22
  %24 = trunc i64 %23 to i32
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [50 x i32], ptr @iact, i64 0, i64 %26
  store i32 %24, ptr %27, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %11
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

31:                                               ; preds = %10
  store i32 1, ptr @iact, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %54, %31
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = icmp slt i32 %33, 50
  br i1 %34, label %36, label %35

35:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %57

36:                                               ; preds = %32
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sub nsw i32 %37, 1
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [50 x i32], ptr @iact, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [50 x i32], ptr @iact, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = mul nsw i64 %42, %47
  %49 = srem i64 %48, 1000000007
  %50 = trunc i64 %49 to i32
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [50 x i32], ptr @iact, i64 0, i64 %52
  store i32 %50, ptr %53, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %36
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %3, align 4, !tbaa !5
  br label %32, !llvm.loop !11

57:                                               ; preds = %35
  br label %58

58:                                               ; preds = %106, %57
  %59 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @sum)
  %60 = icmp eq i32 %59, 2
  br i1 %60, label %61, label %112

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

62:                                               ; preds = %72, %61
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = load i32, ptr @n, align 4, !tbaa !5
  %65 = icmp slt i32 %63, %64
  br i1 %65, label %67, label %66

66:                                               ; preds = %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %75

67:                                               ; preds = %62
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i64, ptr @values, i64 %69
  %71 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %70)
  br label %72

72:                                               ; preds = %67
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %4, align 4, !tbaa !5
  br label %62, !llvm.loop !12

75:                                               ; preds = %66
  store i32 1, ptr @val, align 16, !tbaa !5
  store i32 1, ptr @deg, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %76

76:                                               ; preds = %103, %75
  %77 = load i32, ptr %5, align 4, !tbaa !5
  %78 = load i32, ptr @n, align 4, !tbaa !5
  %79 = icmp slt i32 %77, %78
  br i1 %79, label %81, label %80

80:                                               ; preds = %76
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %106

81:                                               ; preds = %76
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %82 = load i32, ptr %5, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [50 x i64], ptr @values, i64 0, i64 %83
  %85 = load i64, ptr %84, align 8, !tbaa !13
  %86 = load i32, ptr %5, align 4, !tbaa !5
  %87 = sub nsw i32 %86, 1
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [50 x i64], ptr @values, i64 0, i64 %88
  %90 = load i64, ptr %89, align 8, !tbaa !13
  %91 = sdiv i64 %85, %90
  store i64 %91, ptr %6, align 8, !tbaa !13
  %92 = load i64, ptr %6, align 8, !tbaa !13
  %93 = srem i64 %92, 1000000007
  %94 = trunc i64 %93 to i32
  %95 = load i64, ptr @sum, align 8, !tbaa !13
  %96 = load i64, ptr %6, align 8, !tbaa !13
  %97 = srem i64 %95, %96
  %98 = srem i64 %97, 1000000007
  %99 = trunc i64 %98 to i32
  call void @_Z5transii(i32 noundef %94, i32 noundef %99)
  %100 = load i64, ptr %6, align 8, !tbaa !13
  %101 = load i64, ptr @sum, align 8, !tbaa !13
  %102 = sdiv i64 %101, %100
  store i64 %102, ptr @sum, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %103

103:                                              ; preds = %81
  %104 = load i32, ptr %5, align 4, !tbaa !5
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %5, align 4, !tbaa !5
  br label %76, !llvm.loop !15

106:                                              ; preds = %80
  %107 = load i64, ptr @sum, align 8, !tbaa !13
  %108 = srem i64 %107, 1000000007
  %109 = trunc i64 %108 to i32
  %110 = call noundef i32 @_Z5valuei(i32 noundef %109)
  %111 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %110)
  br label %58, !llvm.loop !16

112:                                              ; preds = %58
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #4

declare i32 @printf(ptr noundef, ...) #4

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { mustprogress norecurse 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 = { "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 = !{!"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}
!12 = distinct !{!12, !10}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !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"

@iact = external dso_local local_unnamed_addr global [50 x i32], align 16
@deg = external dso_local local_unnamed_addr global i32, align 4
@val = external dso_local local_unnamed_addr global [50 x i32], align 16
@n = external dso_local global i32, align 4
@sum = external dso_local global i64, align 8
@values = external dso_local global [50 x i64], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5valuei(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5transii(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  store i32 0, ptr @iact, align 16, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @iact, i64 4), align 4, !tbaa !5
  br label %2

1:                                                ; preds = %2
  store i32 1, ptr @iact, align 16, !tbaa !5
  br label %18

2:                                                ; preds = %0, %2
  %indvars.iv = phi i64 [ 2, %0 ], [ %indvars.iv.next, %2 ]
  %3 = trunc nuw nsw i64 %indvars.iv to i32
  %4 = udiv i32 1000000007, %3
  %5 = zext nneg i32 %4 to i64
  %6 = urem i32 1000000007, %3
  %7 = zext nneg i32 %6 to i64
  %8 = getelementptr inbounds [50 x i32], ptr @iact, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = mul nsw i64 %10, %5
  %12 = srem i64 %11, 1000000007
  %13 = trunc nsw i64 %12 to i32
  %14 = sub nsw i32 1000000007, %13
  %15 = getelementptr inbounds [50 x i32], ptr @iact, i64 0, i64 %indvars.iv
  store i32 %14, ptr %15, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 50
  br i1 %exitcond.not, label %1, label %2, !llvm.loop !9

.preheader23:                                     ; preds = %18
  %16 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @sum)
  %17 = icmp eq i32 %16, 2
  br i1 %17, label %.preheader, label %._crit_edge31

18:                                               ; preds = %26, %1
  %19 = phi i64 [ 1, %1 ], [ %31, %26 ]
  %indvars.iv33 = phi i64 [ 1, %1 ], [ %indvars.iv.next34.1, %26 ]
  %20 = getelementptr inbounds [50 x i32], ptr @iact, i64 0, i64 %indvars.iv33
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = mul nsw i64 %19, %22
  %24 = srem i64 %23, 1000000007
  %25 = trunc nsw i64 %24 to i32
  store i32 %25, ptr %20, align 4, !tbaa !5
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %exitcond36.not = icmp eq i64 %indvars.iv.next34, 50
  br i1 %exitcond36.not, label %.preheader23, label %26, !llvm.loop !11

26:                                               ; preds = %18
  %27 = getelementptr inbounds [50 x i32], ptr @iact, i64 0, i64 %indvars.iv.next34
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = mul nsw i64 %24, %29
  %31 = srem i64 %30, 1000000007
  %32 = trunc nsw i64 %31 to i32
  store i32 %32, ptr %27, align 4, !tbaa !5
  %indvars.iv.next34.1 = add nuw nsw i64 %indvars.iv33, 2
  br label %18

.preheader:                                       ; preds = %.preheader23, %._crit_edge30
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = icmp sgt i32 %33, 0
  br i1 %34, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %.preheader
  store i32 1, ptr @val, align 16, !tbaa !5
  store i32 1, ptr @deg, align 4, !tbaa !5
  %.pre4344 = load i64, ptr @sum, align 8, !tbaa !12
  br label %._crit_edge30

._crit_edge:                                      ; preds = %.lr.ph
  store i32 1, ptr @val, align 16, !tbaa !5
  store i32 1, ptr @deg, align 4, !tbaa !5
  %35 = icmp sgt i32 %38, 1
  %.pre43 = load i64, ptr @sum, align 8, !tbaa !12
  br i1 %35, label %.lr.ph29, label %._crit_edge30

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv37 = phi i64 [ %indvars.iv.next38, %.lr.ph ], [ 0, %.preheader ]
  %36 = getelementptr inbounds i64, ptr @values, i64 %indvars.iv37
  %37 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %36)
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = icmp slt i64 %indvars.iv.next38, %39
  br i1 %40, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge30:                                    ; preds = %.lr.ph29, %._crit_edge.thread, %._crit_edge
  %41 = phi i64 [ %.pre43, %._crit_edge ], [ %.pre4344, %._crit_edge.thread ], [ %61, %.lr.ph29 ]
  %42 = srem i64 %41, 1000000007
  %43 = trunc nsw i64 %42 to i32
  %44 = tail call noundef i32 @_Z5valuei(i32 noundef %43)
  %45 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %44)
  %46 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @sum)
  %47 = icmp eq i32 %46, 2
  br i1 %47, label %.preheader, label %._crit_edge31, !llvm.loop !15

.lr.ph29:                                         ; preds = %._crit_edge, %.lr.ph29
  %48 = phi i64 [ %61, %.lr.ph29 ], [ %.pre43, %._crit_edge ]
  %indvars.iv40 = phi i64 [ %indvars.iv.next41, %.lr.ph29 ], [ 1, %._crit_edge ]
  %49 = getelementptr inbounds [50 x i64], ptr @values, i64 0, i64 %indvars.iv40
  %50 = load i64, ptr %49, align 8, !tbaa !12
  %51 = add nsw i64 %indvars.iv40, -1
  %52 = getelementptr inbounds [50 x i64], ptr @values, i64 0, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !12
  %54 = sdiv i64 %50, %53
  %55 = srem i64 %54, 1000000007
  %56 = trunc nsw i64 %55 to i32
  %57 = srem i64 %48, %54
  %58 = srem i64 %57, 1000000007
  %59 = trunc nsw i64 %58 to i32
  tail call void @_Z5transii(i32 noundef %56, i32 noundef %59)
  %60 = load i64, ptr @sum, align 8, !tbaa !12
  %61 = sdiv i64 %60, %54
  store i64 %61, ptr @sum, align 8, !tbaa !12
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %62 = load i32, ptr @n, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = icmp slt i64 %indvars.iv.next41, %63
  br i1 %64, label %.lr.ph29, label %._crit_edge30, !llvm.loop !16

._crit_edge31:                                    ; preds = %._crit_edge30, %.preheader23
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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 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 norecurse 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 = { nofree 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" }

!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}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}


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