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

; 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, i64 }

@n = external dso_local global i32, align 4
@pos = external dso_local global [61 x i32], align 16
@ans = external dso_local global i32, align 4
@a = external dso_local global [1001 x %"struct.std::pair"], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 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)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %7

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

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

12:                                               ; preds = %7
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [1001 x %"struct.std::pair"], ptr @a, i64 0, i64 %14
  %16 = getelementptr inbounds %"struct.std::pair", ptr %15, i32 0, i32 1
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1001 x %"struct.std::pair"], ptr @a, i64 0, i64 %18
  %20 = getelementptr inbounds %"struct.std::pair", ptr %19, i32 0, i32 0
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %16, ptr noundef %20)
  br label %22

22:                                               ; preds = %12
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

25:                                               ; preds = %11
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds %"struct.std::pair", ptr @a, i64 %27
  call void @_ZSt4sortIPSt4pairIixEEvT_S3_(ptr noundef @a, ptr noundef %28)
  call void @llvm.memset.p0.i64(ptr align 16 @pos, i8 -1, i64 244, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = sub nsw i32 %29, 1
  store i32 %30, ptr %3, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %91, %25
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = icmp sge i32 %32, 0
  br i1 %33, label %35, label %34

34:                                               ; preds = %31
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %94

35:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 60, ptr %5, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %86, %35
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = icmp sge i32 %37, 0
  br i1 %38, label %40, label %39

39:                                               ; preds = %36
  store i32 8, ptr %4, align 4
  br label %89

40:                                               ; preds = %36
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1001 x %"struct.std::pair"], ptr @a, i64 0, i64 %42
  %44 = getelementptr inbounds %"struct.std::pair", ptr %43, i32 0, i32 1
  %45 = load i64, ptr %44, align 8, !tbaa !11
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = zext i32 %46 to i64
  %48 = ashr i64 %45, %47
  %49 = and i64 %48, 1
  %50 = icmp ne i64 %49, 0
  br i1 %50, label %52, label %51

51:                                               ; preds = %40
  br label %86

52:                                               ; preds = %40
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [61 x i32], ptr @pos, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = icmp eq i32 %56, -1
  br i1 %57, label %58, label %70

58:                                               ; preds = %52
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [61 x i32], ptr @pos, i64 0, i64 %61
  store i32 %59, ptr %62, align 4, !tbaa !5
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [1001 x %"struct.std::pair"], ptr @a, i64 0, i64 %64
  %66 = getelementptr inbounds %"struct.std::pair", ptr %65, i32 0, i32 0
  %67 = load i32, ptr %66, align 16, !tbaa !14
  %68 = load i32, ptr @ans, align 4, !tbaa !5
  %69 = add nsw i32 %68, %67
  store i32 %69, ptr @ans, align 4, !tbaa !5
  store i32 8, ptr %4, align 4
  br label %89

70:                                               ; preds = %52
  %71 = load i32, ptr %5, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [61 x i32], ptr @pos, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [1001 x %"struct.std::pair"], ptr @a, i64 0, i64 %75
  %77 = getelementptr inbounds %"struct.std::pair", ptr %76, i32 0, i32 1
  %78 = load i64, ptr %77, align 8, !tbaa !11
  %79 = load i32, ptr %3, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [1001 x %"struct.std::pair"], ptr @a, i64 0, i64 %80
  %82 = getelementptr inbounds %"struct.std::pair", ptr %81, i32 0, i32 1
  %83 = load i64, ptr %82, align 8, !tbaa !11
  %84 = xor i64 %83, %78
  store i64 %84, ptr %82, align 8, !tbaa !11
  br label %85

85:                                               ; preds = %70
  br label %86

86:                                               ; preds = %85, %51
  %87 = load i32, ptr %5, align 4, !tbaa !5
  %88 = add nsw i32 %87, -1
  store i32 %88, ptr %5, align 4, !tbaa !5
  br label %36, !llvm.loop !15

89:                                               ; preds = %58, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %90

90:                                               ; preds = %89
  br label %91

91:                                               ; preds = %90
  %92 = load i32, ptr %3, align 4, !tbaa !5
  %93 = add nsw i32 %92, -1
  store i32 %93, ptr %3, align 4, !tbaa !5
  br label %31, !llvm.loop !16

94:                                               ; preds = %34
  %95 = load i32, ptr @ans, align 4, !tbaa !5
  %96 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %95)
  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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!12, !13, i64 8}
!12 = !{!"_ZTSSt4pairIixE", !6, i64 0, !13, i64 8}
!13 = !{!"long long", !7, i64 0}
!14 = !{!12, !6, i64 0}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !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"

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

@n = external dso_local global i32, align 4
@pos = external dso_local local_unnamed_addr global [61 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local global [1001 x %"struct.std::pair"], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 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 @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre = sext i32 %2 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.._crit_edge_crit_edge ], [ %12, %.lr.ph ]
  %4 = getelementptr inbounds %"struct.std::pair", ptr @a, i64 %.pre-phi
  tail call void @_ZSt4sortIPSt4pairIixEEvT_S3_(ptr noundef nonnull @a, ptr noundef nonnull %4)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(244) @pos, i8 -1, i64 244, i1 false)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %ans.promoted = load i32, ptr @ans, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.preheader.preheader, label %._crit_edge27

.preheader.preheader:                             ; preds = %._crit_edge
  %7 = zext nneg i32 %5 to i64
  br label %.preheader

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %8 = getelementptr inbounds [1001 x %"struct.std::pair"], ptr @a, i64 0, i64 %indvars.iv
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  %10 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %9, ptr noundef nonnull %8)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = icmp slt i64 %indvars.iv.next, %12
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.preheader:                                       ; preds = %.preheader.preheader, %.loopexit
  %indvars.iv34 = phi i64 [ %7, %.preheader.preheader ], [ %indvars.iv.next35, %.loopexit ]
  %14 = phi i32 [ %ans.promoted, %.preheader.preheader ], [ %53, %.loopexit ]
  %indvars.iv.next35 = add nsw i64 %indvars.iv34, -1
  %15 = getelementptr inbounds [1001 x %"struct.std::pair"], ptr @a, i64 0, i64 %indvars.iv.next35
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %.promoted = load i64, ptr %16, align 8, !tbaa !11
  br label %19

._crit_edge27:                                    ; preds = %.loopexit, %._crit_edge
  %17 = phi i32 [ %ans.promoted, %._crit_edge ], [ %53, %.loopexit ]
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %17)
  ret i32 0

19:                                               ; preds = %51, %.preheader
  %indvars.iv31 = phi i64 [ 60, %.preheader ], [ %indvars.iv.next32.1, %51 ]
  %20 = phi i64 [ %.promoted, %.preheader ], [ %52, %51 ]
  %21 = shl nuw i64 1, %indvars.iv31
  %22 = and i64 %20, %21
  %.not = icmp eq i64 %22, 0
  br i1 %.not, label %37, label %23

23:                                               ; preds = %19
  %24 = getelementptr inbounds [61 x i32], ptr @pos, i64 0, i64 %indvars.iv31
  %25 = load i32, ptr %24, align 8, !tbaa !5
  %26 = icmp eq i32 %25, -1
  br i1 %26, label %27, label %32

27:                                               ; preds = %42, %23
  %indvars.iv31.lcssa = phi i64 [ %indvars.iv31, %23 ], [ %indvars.iv.next32, %42 ]
  %28 = getelementptr inbounds [61 x i32], ptr @pos, i64 0, i64 %indvars.iv31.lcssa
  %29 = trunc nuw nsw i64 %indvars.iv.next35 to i32
  store i32 %29, ptr %28, align 4, !tbaa !5
  %30 = load i32, ptr %15, align 16, !tbaa !14
  %31 = add nsw i32 %14, %30
  store i32 %31, ptr @ans, align 4, !tbaa !5
  br label %.loopexit

32:                                               ; preds = %23
  %33 = sext i32 %25 to i64
  %34 = getelementptr inbounds [1001 x %"struct.std::pair"], ptr @a, i64 0, i64 %33, i32 1
  %35 = load i64, ptr %34, align 8, !tbaa !11
  %36 = xor i64 %35, %20
  store i64 %36, ptr %16, align 8, !tbaa !11
  br label %37

37:                                               ; preds = %19, %32
  %38 = phi i64 [ %20, %19 ], [ %36, %32 ]
  %indvars.iv.next32 = add nsw i64 %indvars.iv31, -1
  %.not37 = icmp eq i64 %indvars.iv31, 0
  br i1 %.not37, label %.loopexit, label %39, !llvm.loop !15

39:                                               ; preds = %37
  %40 = shl nuw i64 1, %indvars.iv.next32
  %41 = and i64 %38, %40
  %.not.1 = icmp eq i64 %41, 0
  br i1 %.not.1, label %51, label %42

42:                                               ; preds = %39
  %43 = getelementptr inbounds [61 x i32], ptr @pos, i64 0, i64 %indvars.iv.next32
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = icmp eq i32 %44, -1
  br i1 %45, label %27, label %46

46:                                               ; preds = %42
  %47 = sext i32 %44 to i64
  %48 = getelementptr inbounds [1001 x %"struct.std::pair"], ptr @a, i64 0, i64 %47, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !11
  %50 = xor i64 %49, %38
  store i64 %50, ptr %16, align 8, !tbaa !11
  br label %51

51:                                               ; preds = %46, %39
  %52 = phi i64 [ %38, %39 ], [ %50, %46 ]
  %indvars.iv.next32.1 = add nsw i64 %indvars.iv31, -2
  br label %19

.loopexit:                                        ; preds = %37, %27
  %53 = phi i32 [ %31, %27 ], [ %14, %37 ]
  %54 = icmp sgt i64 %indvars.iv34, 1
  br i1 %54, label %.preheader, label %._crit_edge27, !llvm.loop !16
}

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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" }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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, !13, i64 8}
!12 = !{!"_ZTSSt4pairIixE", !6, i64 0, !13, i64 8}
!13 = !{!"long long", !7, i64 0}
!14 = !{!12, !6, i64 0}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}


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