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

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

%"struct.std::pair" = type { i32, i32 }

@n = external dso_local global i32, align 4
@cnt = external dso_local global i32, align 4
@pp = external dso_local global [9 x i32], align 16
@sum = external dso_local global i32, align 4
@ans = external dso_local global [1024 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca %"struct.std::pair", align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %44, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sdiv i32 %10, %11
  %13 = icmp sle i32 %9, %12
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %8
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = srem i32 %16, %17
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %43

20:                                               ; preds = %15
  %21 = load i32, ptr @cnt, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [9 x i32], ptr @pp, i64 0, i64 %22
  store i32 1, ptr %23, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %36, %20
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = srem i32 %25, %26
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %40

29:                                               ; preds = %24
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = load i32, ptr @cnt, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [9 x i32], ptr @pp, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = mul nsw i32 %34, %30
  store i32 %35, ptr %33, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %29
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = sdiv i32 %38, %37
  store i32 %39, ptr @n, align 4, !tbaa !5
  br label %24, !llvm.loop !9

40:                                               ; preds = %24
  %41 = load i32, ptr @cnt, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr @cnt, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %40, %15
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !11

47:                                               ; preds = %14
  %48 = load i32, ptr @n, align 4, !tbaa !5
  %49 = icmp sgt i32 %48, 1
  br i1 %49, label %50, label %56

50:                                               ; preds = %47
  %51 = load i32, ptr @n, align 4, !tbaa !5
  %52 = load i32, ptr @cnt, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr @cnt, align 4, !tbaa !5
  %54 = sext i32 %52 to i64
  %55 = getelementptr inbounds [9 x i32], ptr @pp, i64 0, i64 %54
  store i32 %51, ptr %55, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %50, %47
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 1, ptr %5, align 4, !tbaa !5
  %57 = call i64 @_ZSt9make_pairIiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS1_INS2_IT0_E4typeEE6__typeEEOS3_OS8_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %5)
  store i64 %57, ptr %3, align 4
  %58 = load i64, ptr %3, align 4
  call void @_Z3dfsiSt4pairIiiE(i32 noundef 0, i64 %58)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  %59 = load i32, ptr @sum, align 4, !tbaa !5
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %63, label %61

61:                                               ; preds = %56
  %62 = call i32 @puts(ptr noundef @.str.1)
  br label %82

63:                                               ; preds = %56
  %64 = load i32, ptr @sum, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i32, ptr @ans, i64 %65
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @ans, ptr noundef %66)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %67

67:                                               ; preds = %78, %63
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = load i32, ptr @sum, align 4, !tbaa !5
  %70 = icmp slt i32 %68, %69
  br i1 %70, label %72, label %71

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

72:                                               ; preds = %67
  %73 = load i32, ptr %6, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [1024 x i32], ptr @ans, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %76)
  br label %78

78:                                               ; preds = %72
  %79 = load i32, ptr %6, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %6, align 4, !tbaa !5
  br label %67, !llvm.loop !12

81:                                               ; preds = %71
  br label %82

82:                                               ; preds = %81, %61
  ret i32 0
}

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

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZSt9make_pairIiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS1_INS2_IT0_E4typeEE6__typeEEOS3_OS8_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #1

declare i32 @puts(ptr noundef) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) #4

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

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


; 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
@cnt = external dso_local local_unnamed_addr global i32, align 4
@pp = external dso_local local_unnamed_addr global [9 x i32], align 16
@sum = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local global [1024 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %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)
  %n.promoted16 = load i32, ptr @n, align 4, !tbaa !5
  %cnt.promoted = load i32, ptr @cnt, align 4, !tbaa !5
  %.not20 = icmp slt i32 %n.promoted16, 4
  br i1 %.not20, label %._crit_edge26, label %.lr.ph25

._crit_edge26:                                    ; preds = %20, %0
  %4 = phi i32 [ %cnt.promoted, %0 ], [ %21, %20 ]
  %.lcssa = phi i32 [ %n.promoted16, %0 ], [ %.lcssa1517, %20 ]
  %5 = icmp sgt i32 %.lcssa, 1
  br i1 %5, label %24, label %28

.lr.ph25:                                         ; preds = %0, %20
  %.01022 = phi i32 [ %22, %20 ], [ 2, %0 ]
  %.lcssa151921 = phi i32 [ %.lcssa1517, %20 ], [ %n.promoted16, %0 ]
  %6 = phi i32 [ %21, %20 ], [ %cnt.promoted, %0 ]
  %7 = srem i32 %.lcssa151921, %.01022
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %.lr.ph, label %20

.lr.ph:                                           ; preds = %.lr.ph25
  %9 = sext i32 %6 to i64
  %10 = getelementptr inbounds [9 x i32], ptr @pp, i64 0, i64 %9
  br label %11

11:                                               ; preds = %.lr.ph, %11
  %12 = phi i32 [ 1, %.lr.ph ], [ %14, %11 ]
  %13 = phi i32 [ %.lcssa151921, %.lr.ph ], [ %15, %11 ]
  %14 = mul nuw nsw i32 %12, %.01022
  %15 = sdiv i32 %13, %.01022
  %16 = srem i32 %15, %.01022
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %11, label %18, !llvm.loop !9

18:                                               ; preds = %11
  store i32 %14, ptr %10, align 4, !tbaa !5
  store i32 %15, ptr @n, align 4, !tbaa !5
  %19 = add nsw i32 %6, 1
  store i32 %19, ptr @cnt, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %.lr.ph25, %18
  %21 = phi i32 [ %6, %.lr.ph25 ], [ %19, %18 ]
  %.lcssa1517 = phi i32 [ %.lcssa151921, %.lr.ph25 ], [ %15, %18 ]
  %22 = add nuw nsw i32 %.01022, 1
  %23 = sdiv i32 %.lcssa1517, %22
  %.not.not = icmp slt i32 %.01022, %23
  br i1 %.not.not, label %.lr.ph25, label %._crit_edge26, !llvm.loop !11

24:                                               ; preds = %._crit_edge26
  %25 = add nsw i32 %4, 1
  store i32 %25, ptr @cnt, align 4, !tbaa !5
  %26 = sext i32 %4 to i64
  %27 = getelementptr inbounds [9 x i32], ptr @pp, i64 0, i64 %26
  store i32 %.lcssa, ptr %27, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %24, %._crit_edge26
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  %29 = call i64 @_ZSt9make_pairIiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS1_INS2_IT0_E4typeEE6__typeEEOS3_OS8_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2)
  call void @_Z3dfsiSt4pairIiiE(i32 noundef 0, i64 %29)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  %30 = load i32, ptr @sum, align 4, !tbaa !5
  %.not13 = icmp eq i32 %30, 0
  br i1 %.not13, label %31, label %33

31:                                               ; preds = %28
  %32 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %.loopexit

33:                                               ; preds = %28
  %34 = sext i32 %30 to i64
  %35 = getelementptr inbounds i32, ptr @ans, i64 %34
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @ans, ptr noundef nonnull %35)
  %36 = load i32, ptr @sum, align 4, !tbaa !5
  %37 = icmp sgt i32 %36, 0
  br i1 %37, label %.lr.ph29, label %.loopexit

.lr.ph29:                                         ; preds = %33, %.lr.ph29
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph29 ], [ 0, %33 ]
  %38 = getelementptr inbounds [1024 x i32], ptr @ans, i64 0, i64 %indvars.iv
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %39)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %41 = load i32, ptr @sum, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = icmp slt i64 %indvars.iv.next, %42
  br i1 %43, label %.lr.ph29, label %.loopexit, !llvm.loop !12

.loopexit:                                        ; preds = %.lr.ph29, %33, %31
  ret i32 0
}

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

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZSt9make_pairIiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS1_INS2_IT0_E4typeEE6__typeEEOS3_OS8_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #4

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

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


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass