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

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

@n = external dso_local global i32, align 4
@l = external dso_local global i32, align 4
@f = external dso_local global [1000001 x i32], align 16
@g = external dso_local global [1001 x i32], align 16
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 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
  store i32 0, ptr %1, align 4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @l)
  br label %7

7:                                                ; preds = %83, %0
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = add nsw i32 %8, -1
  store i32 %9, ptr @n, align 4, !tbaa !5
  %10 = icmp ne i32 %8, 0
  br i1 %10, label %11, label %84

11:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr @g, align 16, !tbaa !5
  store i32 0, ptr %3, align 4, !tbaa !5
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %2)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %61, %11
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = mul nsw i32 %14, %15
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = icmp sle i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %64

20:                                               ; preds = %13
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = srem i32 %21, %22
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %60

25:                                               ; preds = %20
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = load i32, ptr @g, align 16, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr @g, align 16, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [1001 x i32], ptr @g, i64 0, i64 %29
  store i32 %26, ptr %30, align 4, !tbaa !5
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = load i32, ptr @l, align 4, !tbaa !5
  %33 = icmp sge i32 %31, %32
  br i1 %33, label %34, label %39

34:                                               ; preds = %25
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  call void @_Z6updateRii(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef %38)
  br label %39

39:                                               ; preds = %34, %25
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sdiv i32 %40, %41
  %43 = load i32, ptr @g, align 16, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr @g, align 16, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1001 x i32], ptr @g, i64 0, i64 %45
  store i32 %42, ptr %46, align 4, !tbaa !5
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = sdiv i32 %47, %48
  %50 = load i32, ptr @l, align 4, !tbaa !5
  %51 = icmp sge i32 %49, %50
  br i1 %51, label %52, label %59

52:                                               ; preds = %39
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = sdiv i32 %53, %54
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  call void @_Z6updateRii(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef %58)
  br label %59

59:                                               ; preds = %52, %39
  br label %60

60:                                               ; preds = %59, %20
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %4, align 4, !tbaa !5
  br label %13, !llvm.loop !9

64:                                               ; preds = %19
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %3, align 4, !tbaa !5
  call void @_Z6updateRii(ptr noundef nonnull align 4 dereferenceable(4) @ans, i32 noundef %66)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %67

67:                                               ; preds = %80, %64
  %68 = load i32, ptr %5, align 4, !tbaa !5
  %69 = load i32, ptr @g, align 16, !tbaa !5
  %70 = icmp sle i32 %68, %69
  br i1 %70, label %72, label %71

71:                                               ; preds = %67
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %83

72:                                               ; preds = %67
  %73 = load i32, ptr %5, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [1001 x i32], ptr @g, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %77
  %79 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z6updateRii(ptr noundef nonnull align 4 dereferenceable(4) %78, i32 noundef %79)
  br label %80

80:                                               ; preds = %72
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %5, align 4, !tbaa !5
  br label %67, !llvm.loop !11

83:                                               ; preds = %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %7, !llvm.loop !12

84:                                               ; preds = %7
  %85 = load i32, ptr @ans, align 4, !tbaa !5
  %86 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %85)
  ret i32 0
}

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z6updateRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #3

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

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

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 = { "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 willreturn memory(argmem: readwrite) }
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" }
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 = !{!"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"

@n = external dso_local global i32, align 4
@l = external dso_local global i32, align 4
@f = external dso_local global [1000001 x i32], align 16
@g = external dso_local local_unnamed_addr global [1001 x i32], align 16
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @l)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr @n, align 4, !tbaa !5
  %.not28 = icmp eq i32 %4, 0
  br i1 %.not28, label %._crit_edge31, label %.lr.ph30

.lr.ph30:                                         ; preds = %0, %._crit_edge27
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  store i32 0, ptr @g, align 16, !tbaa !5
  store i32 0, ptr %2, align 4, !tbaa !5
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %.not1620 = icmp slt i32 %7, 1
  br i1 %.not1620, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %37, %.lr.ph30
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr %2, align 4, !tbaa !5
  call void @_Z6updateRii(ptr noundef nonnull align 4 dereferenceable(4) @ans, i32 noundef %9)
  %10 = load i32, ptr @g, align 16, !tbaa !5
  %.not1723 = icmp slt i32 %10, 1
  br i1 %.not1723, label %._crit_edge27, label %.lr.ph26

.lr.ph:                                           ; preds = %.lr.ph30, %37
  %11 = phi i32 [ %38, %37 ], [ %7, %.lr.ph30 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %37 ], [ 1, %.lr.ph30 ]
  %12 = trunc nuw nsw i64 %indvars.iv to i32
  %13 = srem i32 %11, %12
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %37

15:                                               ; preds = %.lr.ph
  %16 = load i32, ptr @g, align 16, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr @g, align 16, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1001 x i32], ptr @g, i64 0, i64 %18
  store i32 %12, ptr %19, align 4, !tbaa !5
  %20 = load i32, ptr @l, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %.not18 = icmp slt i64 %indvars.iv, %21
  br i1 %.not18, label %25, label %22

22:                                               ; preds = %15
  %23 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %indvars.iv
  %24 = load i32, ptr %23, align 4, !tbaa !5
  call void @_Z6updateRii(ptr noundef nonnull align 4 dereferenceable(4) %2, i32 noundef %24)
  %.pre = load i32, ptr %1, align 4, !tbaa !5
  %.pre36 = load i32, ptr @l, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %22, %15
  %26 = phi i32 [ %.pre36, %22 ], [ %20, %15 ]
  %27 = phi i32 [ %.pre, %22 ], [ %11, %15 ]
  %28 = sdiv i32 %27, %12
  %29 = load i32, ptr @g, align 16, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr @g, align 16, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1001 x i32], ptr @g, i64 0, i64 %31
  store i32 %28, ptr %32, align 4, !tbaa !5
  %.not19 = icmp slt i32 %28, %26
  br i1 %.not19, label %37, label %33

33:                                               ; preds = %25
  %34 = sext i32 %28 to i64
  %35 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  call void @_Z6updateRii(ptr noundef nonnull align 4 dereferenceable(4) %2, i32 noundef %36)
  %.pre37 = load i32, ptr %1, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %.lr.ph, %33, %25
  %38 = phi i32 [ %11, %.lr.ph ], [ %.pre37, %33 ], [ %27, %25 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %39 = mul nuw nsw i64 %indvars.iv.next, %indvars.iv.next
  %40 = trunc nuw i64 %39 to i32
  %.not16 = icmp slt i32 %38, %40
  br i1 %.not16, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge27:                                    ; preds = %.lr.ph26, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  %41 = load i32, ptr @n, align 4, !tbaa !5
  %42 = add nsw i32 %41, -1
  store i32 %42, ptr @n, align 4, !tbaa !5
  %.not = icmp eq i32 %41, 0
  br i1 %.not, label %._crit_edge31, label %.lr.ph30, !llvm.loop !11

.lr.ph26:                                         ; preds = %._crit_edge, %.lr.ph26
  %indvars.iv33 = phi i64 [ %indvars.iv.next34, %.lr.ph26 ], [ 1, %._crit_edge ]
  %43 = getelementptr inbounds [1001 x i32], ptr @g, i64 0, i64 %indvars.iv33
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1000001 x i32], ptr @f, i64 0, i64 %45
  %47 = load i32, ptr %2, align 4, !tbaa !5
  call void @_Z6updateRii(ptr noundef nonnull align 4 dereferenceable(4) %46, i32 noundef %47)
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %48 = load i32, ptr @g, align 16, !tbaa !5
  %49 = sext i32 %48 to i64
  %.not17.not = icmp slt i64 %indvars.iv33, %49
  br i1 %.not17.not, label %.lr.ph26, label %._crit_edge27, !llvm.loop !12

._crit_edge31:                                    ; preds = %._crit_edge27, %0
  %50 = load i32, ptr @ans, align 4, !tbaa !5
  %51 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %50)
  ret i32 0
}

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z6updateRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #3

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

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

attributes #0 = { mustprogress 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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = !{!"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: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass