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

; 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
@perm = external dso_local global [100001 x i32], align 16
@ans = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5solvePiS_(ptr noundef, ptr 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 norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %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 @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %16, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp sle i32 %7, %8
  br i1 %9, label %11, label %10

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

11:                                               ; preds = %6
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds i32, ptr @perm, i64 %13
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %14)
  br label %16

16:                                               ; preds = %11
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !9

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

20:                                               ; preds = %53, %19
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = icmp sle i32 %21, %22
  br i1 %23, label %25, label %24

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

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %26 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %26, ptr %4, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %45, %25
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = add nsw i32 %28, 2
  store i32 %29, ptr %3, align 4, !tbaa !5
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = icmp sle i32 %29, %30
  br i1 %31, label %32, label %43

32:                                               ; preds = %27
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = sub nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100001 x i32], ptr @perm, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100001 x i32], ptr @perm, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = icmp sgt i32 %37, %41
  br label %43

43:                                               ; preds = %32, %27
  %44 = phi i1 [ false, %27 ], [ %42, %32 ]
  br i1 %44, label %45, label %46

45:                                               ; preds = %43
  br label %27, !llvm.loop !11

46:                                               ; preds = %43
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i32, ptr @perm, i64 %48
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i32, ptr @perm, i64 %51
  call void @_ZSt7reverseIPiEvT_S1_(ptr noundef %49, ptr noundef %52)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %53

53:                                               ; preds = %46
  %54 = load i64, ptr @ans, align 8, !tbaa !12
  %55 = add nsw i64 %54, 1
  store i64 %55, ptr @ans, align 8, !tbaa !12
  br label %20, !llvm.loop !14

56:                                               ; preds = %24
  %57 = load i32, ptr @n, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i32, ptr @perm, i64 %58
  %60 = getelementptr inbounds i32, ptr %59, i64 1
  call void @_Z5solvePiS_(ptr noundef getelementptr inbounds (i32, ptr @perm, i64 1), ptr noundef %60)
  %61 = load i64, ptr @ans, align 8, !tbaa !12
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %61)
  ret i32 0
}

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

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !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
@perm = external dso_local global [100001 x i32], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5solvePiS_(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not17 = icmp slt i32 %2, 1
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.preheader15:                                     ; preds = %.lr.ph
  %.not1319 = icmp slt i32 %5, 1
  br i1 %.not1319, label %._crit_edge, label %.preheader

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %3 = getelementptr inbounds i32, ptr @perm, i64 %indvars.iv
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %3)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %.not.not = icmp slt i64 %indvars.iv, %6
  br i1 %.not.not, label %.lr.ph, label %.preheader15, !llvm.loop !9

.preheader:                                       ; preds = %.preheader15, %.critedge
  %7 = phi i32 [ %29, %.critedge ], [ %5, %.preheader15 ]
  %.01020 = phi i64 [ %indvars.iv.next24, %.critedge ], [ 1, %.preheader15 ]
  %sext = shl i64 %.01020, 32
  %8 = ashr exact i64 %sext, 32
  %9 = sext i32 %7 to i64
  br label %15

._crit_edge:                                      ; preds = %.critedge, %0, %.preheader15
  %.lcssa16 = phi i32 [ %5, %.preheader15 ], [ %2, %0 ], [ %29, %.critedge ]
  %10 = sext i32 %.lcssa16 to i64
  %11 = getelementptr inbounds i32, ptr @perm, i64 %10
  %12 = getelementptr inbounds i8, ptr %11, i64 4
  tail call void @_Z5solvePiS_(ptr noundef nonnull getelementptr inbounds (i8, ptr @perm, i64 4), ptr noundef nonnull %12)
  %13 = load i64, ptr @ans, align 8, !tbaa !11
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %13)
  ret i32 0

15:                                               ; preds = %.preheader, %16
  %indvars.iv23 = phi i64 [ %8, %.preheader ], [ %indvars.iv.next24, %16 ]
  %indvars.iv.next24 = add nsw i64 %indvars.iv23, 2
  %.not14 = icmp sgt i64 %indvars.iv.next24, %9
  br i1 %.not14, label %.critedge, label %16

16:                                               ; preds = %15
  %17 = add nsw i64 %indvars.iv23, 1
  %18 = getelementptr inbounds [100001 x i32], ptr @perm, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = getelementptr inbounds [100001 x i32], ptr @perm, i64 0, i64 %indvars.iv.next24
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = icmp sgt i32 %19, %21
  br i1 %22, label %15, label %.critedge, !llvm.loop !13

.critedge:                                        ; preds = %15, %16
  %23 = trunc nsw i64 %indvars.iv.next24 to i32
  %24 = getelementptr inbounds i32, ptr @perm, i64 %8
  %sext26 = shl i64 %indvars.iv.next24, 32
  %25 = ashr exact i64 %sext26, 30
  %26 = getelementptr inbounds i8, ptr @perm, i64 %25
  tail call void @_ZSt7reverseIPiEvT_S1_(ptr noundef nonnull %24, ptr noundef nonnull %26)
  %27 = load i64, ptr @ans, align 8, !tbaa !11
  %28 = add nsw i64 %27, 1
  store i64 %28, ptr @ans, align 8, !tbaa !11
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %.not13 = icmp slt i32 %29, %23
  br i1 %.not13, label %._crit_edge, label %.preheader, !llvm.loop !14
}

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

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

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

attributes #0 = { 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 #1 = { 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 #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 = { 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"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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