; LLVM IR from tangjz/acm-icpc :: hdu (6114)

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

@fact = external dso_local global [1001 x i32], align 16
@iact = external dso_local global [1001 x i32], align 16
@.str = external hidden unnamed_addr constant [3 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 norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %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 i32, align 4
  store i32 0, ptr %1, align 4
  store i32 1, ptr getelementptr inbounds ([1001 x i32], ptr @iact, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  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, 1001
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  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 [1001 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 = trunc i64 %22 to i32
  %24 = sub nsw i32 1000000007, %23
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [1001 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
  store i32 1, ptr @fact, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %32

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

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

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 [1001 x i32], ptr @fact, 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 = mul nsw i64 %42, %44
  %46 = srem i64 %45, 1000000007
  %47 = trunc i64 %46 to i32
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1001 x i32], ptr @fact, i64 0, i64 %49
  store i32 %47, ptr %50, align 4, !tbaa !5
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = sub nsw i32 %51, 1
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [1001 x i32], ptr @iact, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [1001 x i32], ptr @iact, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = mul nsw i64 %56, %61
  %63 = srem i64 %62, 1000000007
  %64 = trunc i64 %63 to i32
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [1001 x i32], ptr @iact, i64 0, i64 %66
  store i32 %64, ptr %67, align 4, !tbaa !5
  br label %68

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

71:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %72 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %4)
  br label %73

73:                                               ; preds = %92, %71
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = add nsw i32 %74, -1
  store i32 %75, ptr %4, align 4, !tbaa !5
  %76 = icmp ne i32 %74, 0
  br i1 %76, label %77, label %116

77:                                               ; preds = %73
  %78 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %5, ptr noundef %6)
  %79 = load i32, ptr %5, align 4, !tbaa !5
  %80 = load i32, ptr %6, align 4, !tbaa !5
  %81 = icmp slt i32 %79, %80
  br i1 %81, label %82, label %92

82:                                               ; preds = %77
  %83 = load i32, ptr %5, align 4, !tbaa !5
  %84 = load i32, ptr %6, align 4, !tbaa !5
  %85 = add nsw i32 %83, %84
  store i32 %85, ptr %5, align 4, !tbaa !5
  %86 = load i32, ptr %5, align 4, !tbaa !5
  %87 = load i32, ptr %6, align 4, !tbaa !5
  %88 = sub nsw i32 %86, %87
  store i32 %88, ptr %6, align 4, !tbaa !5
  %89 = load i32, ptr %5, align 4, !tbaa !5
  %90 = load i32, ptr %6, align 4, !tbaa !5
  %91 = sub nsw i32 %89, %90
  store i32 %91, ptr %5, align 4, !tbaa !5
  br label %92

92:                                               ; preds = %82, %77
  %93 = load i32, ptr %5, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [1001 x i32], ptr @fact, i64 0, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = load i32, ptr %6, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [1001 x i32], ptr @iact, i64 0, i64 %99
  %101 = load i32, ptr %100, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = mul nsw i64 %97, %102
  %104 = srem i64 %103, 1000000007
  %105 = load i32, ptr %5, align 4, !tbaa !5
  %106 = load i32, ptr %6, align 4, !tbaa !5
  %107 = sub nsw i32 %105, %106
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [1001 x i32], ptr @iact, i64 0, i64 %108
  %110 = load i32, ptr %109, align 4, !tbaa !5
  %111 = sext i32 %110 to i64
  %112 = mul nsw i64 %104, %111
  %113 = srem i64 %112, 1000000007
  %114 = trunc i64 %113 to i32
  %115 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %114)
  br label %73, !llvm.loop !12

116:                                              ; preds = %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  ret i32 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

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 }

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


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

@fact = external dso_local local_unnamed_addr global [1001 x i32], align 16
@iact = external dso_local local_unnamed_addr global [1001 x i32], align 16
@.str = external hidden unnamed_addr constant [3 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 nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 1, ptr getelementptr inbounds (i8, ptr @iact, i64 4), align 4, !tbaa !5
  br label %5

4:                                                ; preds = %5
  store i32 1, ptr @iact, align 16, !tbaa !5
  store i32 1, ptr @fact, align 16, !tbaa !5
  br label %23

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

19:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = add nsw i32 %21, -1
  store i32 %22, ptr %1, align 4, !tbaa !5
  %.not18 = icmp eq i32 %21, 0
  br i1 %.not18, label %._crit_edge, label %.lr.ph

23:                                               ; preds = %4, %23
  %24 = phi i64 [ 1, %4 ], [ %34, %23 ]
  %25 = phi i64 [ 1, %4 ], [ %27, %23 ]
  %indvars.iv20 = phi i64 [ 1, %4 ], [ %indvars.iv.next21, %23 ]
  %26 = mul nsw i64 %25, %indvars.iv20
  %27 = srem i64 %26, 1000000007
  %28 = trunc nsw i64 %27 to i32
  %29 = getelementptr inbounds [1001 x i32], ptr @fact, i64 0, i64 %indvars.iv20
  store i32 %28, ptr %29, align 4, !tbaa !5
  %30 = getelementptr inbounds [1001 x i32], ptr @iact, i64 0, i64 %indvars.iv20
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = mul nsw i64 %24, %32
  %34 = srem i64 %33, 1000000007
  %35 = trunc nsw i64 %34 to i32
  store i32 %35, ptr %30, align 4, !tbaa !5
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %exitcond23.not = icmp eq i64 %indvars.iv.next21, 1001
  br i1 %exitcond23.not, label %19, label %23, !llvm.loop !11

.lr.ph:                                           ; preds = %19, %41
  %36 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %.lr.ph
  store i32 %37, ptr %3, align 4, !tbaa !5
  store i32 %38, ptr %2, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %40, %.lr.ph
  %42 = phi i32 [ %37, %40 ], [ %38, %.lr.ph ]
  %43 = phi i32 [ %38, %40 ], [ %37, %.lr.ph ]
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1001 x i32], ptr @fact, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = sext i32 %42 to i64
  %49 = getelementptr inbounds [1001 x i32], ptr @iact, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = mul nsw i64 %51, %47
  %53 = srem i64 %52, 1000000007
  %54 = sub nsw i32 %43, %42
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [1001 x i32], ptr @iact, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = mul nsw i64 %53, %58
  %60 = srem i64 %59, 1000000007
  %61 = trunc nsw i64 %60 to i32
  %62 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %61)
  %63 = load i32, ptr %1, align 4, !tbaa !5
  %64 = add nsw i32 %63, -1
  store i32 %64, ptr %1, align 4, !tbaa !5
  %.not = icmp eq i32 %63, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %41, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret i32 0
}

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

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

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

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

attributes #0 = { mustprogress nofree norecurse 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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" }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: BDCEPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass