; LLVM IR from tangjz/acm-icpc :: codeforces/complete (756A)

; 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 [200001 x i32], align 16
@ctr = external dso_local global [200001 x i32], align 16
@ans1 = external dso_local global i32, align 4
@ans2 = external dso_local global i32, align 4
@vis = external dso_local global [200001 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = 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
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %8

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

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

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

18:                                               ; preds = %13
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !9

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

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

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

27:                                               ; preds = %22
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i32, ptr @ctr, i64 %29
  %31 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %30)
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [200001 x i32], ptr @ctr, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = load i32, ptr @ans1, align 4, !tbaa !5
  %37 = xor i32 %36, %35
  store i32 %37, ptr @ans1, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %27
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %3, align 4, !tbaa !5
  br label %22, !llvm.loop !11

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

42:                                               ; preds = %79, %41
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = load i32, ptr @n, align 4, !tbaa !5
  %45 = icmp sle i32 %43, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %42
  store i32 8, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %82

47:                                               ; preds = %42
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [200001 x i8], ptr @vis, i64 0, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !12, !range !14, !noundef !15
  %52 = trunc i8 %51 to i1
  br i1 %52, label %53, label %54

53:                                               ; preds = %47
  br label %79

54:                                               ; preds = %47
  %55 = load i32, ptr @ans2, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr @ans2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [200001 x i32], ptr @perm, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  store i32 %60, ptr %6, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %70, %54
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [200001 x i8], ptr @vis, i64 0, i64 %63
  %65 = load i8, ptr %64, align 1, !tbaa !12, !range !14, !noundef !15
  %66 = trunc i8 %65 to i1
  %67 = xor i1 %66, true
  br i1 %67, label %69, label %68

68:                                               ; preds = %61
  store i32 11, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %78

69:                                               ; preds = %61
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %6, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [200001 x i8], ptr @vis, i64 0, i64 %72
  store i8 1, ptr %73, align 1, !tbaa !12
  %74 = load i32, ptr %6, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [200001 x i32], ptr @perm, i64 0, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !5
  store i32 %77, ptr %6, align 4, !tbaa !5
  br label %61, !llvm.loop !16

78:                                               ; preds = %68
  br label %79

79:                                               ; preds = %78, %53
  %80 = load i32, ptr %4, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %4, align 4, !tbaa !5
  br label %42, !llvm.loop !17

82:                                               ; preds = %46
  %83 = load i32, ptr @ans2, align 4, !tbaa !5
  %84 = icmp eq i32 %83, 1
  br i1 %84, label %85, label %86

85:                                               ; preds = %82
  store i32 0, ptr @ans2, align 4, !tbaa !5
  br label %86

86:                                               ; preds = %85, %82
  %87 = load i32, ptr @ans1, align 4, !tbaa !5
  %88 = load i32, ptr @ans2, align 4, !tbaa !5
  %89 = add nsw i32 %87, %88
  %90 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %89)
  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: 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 = { 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 = !{!"bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !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 [200001 x i32], align 16
@ctr = external dso_local global [200001 x i32], align 16
@ans1 = external dso_local local_unnamed_addr global i32, align 4
@ans2 = external dso_local local_unnamed_addr global i32, align 4
@vis = external dso_local local_unnamed_addr global [200001 x i8], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = 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 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not19 = icmp slt i32 %2, 1
  br i1 %.not19, label %._crit_edge.thread, label %.lr.ph

._crit_edge.thread:                               ; preds = %0
  store i32 1, ptr @ans1, align 4, !tbaa !5
  br label %.preheader.thread

._crit_edge:                                      ; preds = %.lr.ph
  store i32 1, ptr @ans1, align 4, !tbaa !5
  %.not1721 = icmp slt i32 %5, 1
  br i1 %.not1721, label %.preheader.thread, label %.lr.ph24

.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 %._crit_edge, !llvm.loop !9

.preheader.thread:                                ; preds = %._crit_edge, %._crit_edge.thread
  %ans2.promoted43 = load i32, ptr @ans2, align 4, !tbaa !5
  br label %._crit_edge32

.preheader:                                       ; preds = %.lr.ph24
  %ans2.promoted = load i32, ptr @ans2, align 4, !tbaa !5
  %.not1829 = icmp slt i32 %13, 1
  br i1 %.not1829, label %._crit_edge32, label %.lr.ph31.preheader

.lr.ph31.preheader:                               ; preds = %.preheader
  %7 = add nuw i32 %13, 1
  %wide.trip.count = zext i32 %7 to i64
  br label %.lr.ph31

.lr.ph24:                                         ; preds = %._crit_edge, %.lr.ph24
  %indvars.iv35 = phi i64 [ %indvars.iv.next36, %.lr.ph24 ], [ 1, %._crit_edge ]
  %8 = getelementptr inbounds i32, ptr @ctr, i64 %indvars.iv35
  %9 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %8)
  %10 = load i32, ptr %8, align 4, !tbaa !5
  %11 = load i32, ptr @ans1, align 4, !tbaa !5
  %12 = xor i32 %11, %10
  store i32 %12, ptr @ans1, align 4, !tbaa !5
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %.not17.not = icmp slt i64 %indvars.iv35, %14
  br i1 %.not17.not, label %.lr.ph24, label %.preheader, !llvm.loop !11

._crit_edge32:                                    ; preds = %.loopexit, %.preheader.thread, %.preheader
  %15 = phi i32 [ %12, %.preheader ], [ 1, %.preheader.thread ], [ %12, %.loopexit ]
  %16 = phi i32 [ %ans2.promoted, %.preheader ], [ %ans2.promoted43, %.preheader.thread ], [ %34, %.loopexit ]
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %35, label %36

.lr.ph31:                                         ; preds = %.lr.ph31.preheader, %.loopexit
  %indvars.iv38 = phi i64 [ 1, %.lr.ph31.preheader ], [ %indvars.iv.next39, %.loopexit ]
  %18 = phi i32 [ %ans2.promoted, %.lr.ph31.preheader ], [ %34, %.loopexit ]
  %19 = getelementptr inbounds [200001 x i8], ptr @vis, i64 0, i64 %indvars.iv38
  %20 = load i8, ptr %19, align 1, !tbaa !12, !range !14, !noundef !15
  %21 = trunc nuw i8 %20 to i1
  br i1 %21, label %.loopexit, label %22

22:                                               ; preds = %.lr.ph31
  %23 = add nsw i32 %18, 1
  store i32 %23, ptr @ans2, align 4, !tbaa !5
  %.0.in25 = getelementptr inbounds [200001 x i32], ptr @perm, i64 0, i64 %indvars.iv38
  %.026 = load i32, ptr %.0.in25, align 4, !tbaa !5
  %24 = sext i32 %.026 to i64
  %25 = getelementptr inbounds [200001 x i8], ptr @vis, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !12, !range !14, !noundef !15
  %27 = trunc nuw i8 %26 to i1
  br i1 %27, label %.loopexit, label %.lr.ph28

.lr.ph28:                                         ; preds = %22, %.lr.ph28
  %28 = phi ptr [ %31, %.lr.ph28 ], [ %25, %22 ]
  %29 = phi i64 [ %30, %.lr.ph28 ], [ %24, %22 ]
  store i8 1, ptr %28, align 1, !tbaa !12
  %.0.in = getelementptr inbounds [200001 x i32], ptr @perm, i64 0, i64 %29
  %.0 = load i32, ptr %.0.in, align 4, !tbaa !5
  %30 = sext i32 %.0 to i64
  %31 = getelementptr inbounds [200001 x i8], ptr @vis, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !12, !range !14, !noundef !15
  %33 = trunc nuw i8 %32 to i1
  br i1 %33, label %.loopexit, label %.lr.ph28, !llvm.loop !16

.loopexit:                                        ; preds = %.lr.ph28, %22, %.lr.ph31
  %34 = phi i32 [ %18, %.lr.ph31 ], [ %23, %22 ], [ %23, %.lr.ph28 ]
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next39, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge32, label %.lr.ph31, !llvm.loop !17

35:                                               ; preds = %._crit_edge32
  store i32 0, ptr @ans2, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %35, %._crit_edge32
  %37 = phi i32 [ 0, %35 ], [ %16, %._crit_edge32 ]
  %38 = add nsw i32 %37, %15
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %38)
  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 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

!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 = !{!"bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !10}


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