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

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

@c = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@a = external dso_local global [600000 x i32], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 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
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @c, ptr noundef @m, ptr noundef @n)
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %8, label %10

8:                                                ; preds = %0
  %9 = call i32 @puts(ptr noundef @.str.1)
  store i32 0, ptr %1, align 4
  br label %87

10:                                               ; preds = %0
  %11 = load i32, ptr @c, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = load i32, ptr @c, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = mul nsw i64 %12, %14
  %16 = load i32, ptr @m, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = srem i64 %15, %17
  %19 = trunc i64 %18 to i32
  store i32 %19, ptr @c, align 4, !tbaa !5
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = mul nsw i32 %20, 2
  %22 = sub nsw i32 %21, 3
  store i32 %22, ptr @n, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %23 = load i32, ptr @c, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = mul nsw i64 8, %24
  %26 = load i32, ptr @m, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = srem i64 %25, %27
  %29 = trunc i64 %28 to i32
  store i32 %29, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %30 = load i32, ptr @c, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = mul nsw i64 13, %31
  %33 = load i32, ptr @m, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = srem i64 %32, %34
  %36 = trunc i64 %35 to i32
  store i32 %36, ptr %4, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %69, %10
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = load i32, ptr @n, align 4, !tbaa !5
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %72

42:                                               ; preds = %37
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [600000 x i32], ptr @a, i64 0, i64 %45
  store i32 %43, ptr %46, align 4, !tbaa !5
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = add nsw i32 %48, %47
  store i32 %49, ptr %3, align 4, !tbaa !5
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = load i32, ptr @m, align 4, !tbaa !5
  %52 = icmp sge i32 %50, %51
  br i1 %52, label %53, label %57

53:                                               ; preds = %42
  %54 = load i32, ptr @m, align 4, !tbaa !5
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = sub nsw i32 %55, %54
  store i32 %56, ptr %3, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %53, %42
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = add nsw i32 %59, %58
  store i32 %60, ptr %4, align 4, !tbaa !5
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = load i32, ptr @m, align 4, !tbaa !5
  %63 = icmp sge i32 %61, %62
  br i1 %63, label %64, label %68

64:                                               ; preds = %57
  %65 = load i32, ptr @m, align 4, !tbaa !5
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = sub nsw i32 %66, %65
  store i32 %67, ptr %4, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %64, %57
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %2, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %2, align 4, !tbaa !5
  br label %37, !llvm.loop !9

72:                                               ; preds = %41
  %73 = load i32, ptr @n, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds i32, ptr @a, i64 %74
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @a, ptr noundef %75)
  %76 = load i32, ptr @n, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i32, ptr @a, i64 %77
  %79 = call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef @a, ptr noundef %78)
  %80 = ptrtoint ptr %79 to i64
  %81 = sub i64 %80, ptrtoint (ptr @a to i64)
  %82 = sdiv exact i64 %81, 4
  %83 = load i32, ptr @m, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = srem i64 %82, %84
  %86 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %85)
  store i32 0, ptr %1, align 4
  br label %87

87:                                               ; preds = %72, %8
  %88 = load i32, ptr %1, align 4
  ret i32 %88
}

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

declare i32 @puts(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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef, ptr noundef) #3

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


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

@c = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@a = external dso_local global [600000 x i32], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 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() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @c, ptr noundef nonnull @m, ptr noundef nonnull @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp eq i32 %2, 1
  br i1 %3, label %4, label %6

4:                                                ; preds = %0
  %5 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %50

6:                                                ; preds = %0
  %7 = load i32, ptr @c, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = mul nsw i64 %8, %8
  %10 = load i32, ptr @m, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = srem i64 %9, %11
  %13 = trunc nsw i64 %12 to i32
  store i32 %13, ptr @c, align 4, !tbaa !5
  %14 = shl i32 %2, 1
  %15 = add i32 %14, -3
  store i32 %15, ptr @n, align 4, !tbaa !5
  %16 = icmp sgt i32 %2, 1
  br i1 %16, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %6
  %17 = mul nuw nsw i64 %12, 13
  %18 = srem i64 %17, %11
  %19 = trunc nsw i64 %18 to i32
  %20 = icmp slt i32 %15, 2
  br i1 %20, label %.lr.ph.epil, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %wide.trip.count = zext nneg i32 %15 to i64
  %21 = shl nsw i64 %12, 3
  %22 = and i64 %21, 34359738360
  %23 = srem i64 %22, %11
  %24 = trunc nuw nsw i64 %23 to i32
  %25 = add nsw i64 %wide.trip.count, -3
  br label %.lr.ph

.lr.ph.epil:                                      ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %.lr.ph ]
  %.027.unr = phi i32 [ %19, %.lr.ph.preheader ], [ %.1.1, %.lr.ph ]
  %26 = getelementptr inbounds [600000 x i32], ptr @a, i64 0, i64 %indvars.iv.unr
  store i32 %.027.unr, ptr %26, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %6
  %27 = sext i32 %15 to i64
  %28 = getelementptr inbounds i32, ptr @a, i64 %27
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @a, ptr noundef nonnull %28)
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr @a, i64 %30
  %32 = tail call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef nonnull @a, ptr noundef nonnull %31)
  %33 = ptrtoint ptr %32 to i64
  %34 = sub i64 %33, ptrtoint (ptr @a to i64)
  %35 = ashr exact i64 %34, 2
  %36 = load i32, ptr @m, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = srem i64 %35, %37
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %38)
  br label %50

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %.027 = phi i32 [ %19, %.lr.ph.preheader.new ], [ %.1.1, %.lr.ph ]
  %.01326 = phi i32 [ %24, %.lr.ph.preheader.new ], [ %spec.select.1, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %40 = getelementptr inbounds [600000 x i32], ptr @a, i64 0, i64 %indvars.iv
  store i32 %.027, ptr %40, align 8, !tbaa !5
  %41 = add nsw i32 %.027, %.01326
  %.not = icmp slt i32 %41, %10
  %42 = select i1 %.not, i32 0, i32 %10
  %spec.select = sub nsw i32 %41, %42
  %43 = add nsw i32 %spec.select, %.027
  %.not24 = icmp slt i32 %43, %10
  %44 = select i1 %.not24, i32 0, i32 %10
  %.1 = sub nsw i32 %43, %44
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %45 = getelementptr inbounds [600000 x i32], ptr @a, i64 0, i64 %indvars.iv.next
  store i32 %.1, ptr %45, align 4, !tbaa !5
  %46 = add nsw i32 %.1, %spec.select
  %.not.1 = icmp slt i32 %46, %10
  %47 = select i1 %.not.1, i32 0, i32 %10
  %spec.select.1 = sub nsw i32 %46, %47
  %48 = add nsw i32 %spec.select.1, %.1
  %.not24.1 = icmp slt i32 %48, %10
  %49 = select i1 %.not24.1, i32 0, i32 %10
  %.1.1 = sub nsw i32 %48, %49
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter, %25
  br i1 %niter.ncmp.1, label %.lr.ph.epil, label %.lr.ph, !llvm.loop !9

50:                                               ; preds = %._crit_edge, %4
  ret i32 0
}

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

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef, ptr noundef) local_unnamed_addr #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 = { 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 = { 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" }

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass