; LLVM IR from tangjz/acm-icpc :: 51nod (1661)

; 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
@m = external dso_local global i64, align 8
@a = external dso_local global [100000 x i64], align 16
@SG = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [7 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
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z2sgxx(i64 noundef, i64 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
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %10

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

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

15:                                               ; preds = %10
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i64, ptr @a, i64 %17
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %18)
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100000 x i64], ptr @a, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = load i64, ptr @m, align 8, !tbaa !9
  %25 = call noundef i64 @_Z2sgxx(i64 noundef %23, i64 noundef %24)
  %26 = load i64, ptr @SG, align 8, !tbaa !9
  %27 = xor i64 %26, %25
  store i64 %27, ptr @SG, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %15
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !11

31:                                               ; preds = %14
  %32 = load i64, ptr @SG, align 8, !tbaa !9
  %33 = icmp ne i64 %32, 0
  br i1 %33, label %36, label %34

34:                                               ; preds = %31
  %35 = call i32 @puts(ptr noundef @.str.2)
  store i32 0, ptr %1, align 4
  br label %125

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

37:                                               ; preds = %119, %36
  %38 = load i32, ptr %3, 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
  store i32 5, ptr %4, align 4
  br label %122

42:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %43 = load i64, ptr @SG, align 8, !tbaa !9
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100000 x i64], ptr @a, i64 0, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !9
  %48 = load i64, ptr @m, align 8, !tbaa !9
  %49 = call noundef i64 @_Z2sgxx(i64 noundef %47, i64 noundef %48)
  %50 = xor i64 %43, %49
  store i64 %50, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %51 = load i64, ptr %5, align 8, !tbaa !9
  %52 = icmp ne i64 %51, 0
  br i1 %52, label %53, label %68

53:                                               ; preds = %42
  %54 = load i64, ptr %5, align 8, !tbaa !9
  %55 = sub nsw i64 %54, 1
  %56 = load i64, ptr @m, align 8, !tbaa !9
  %57 = sub nsw i64 %56, 1
  %58 = sdiv i64 %55, %57
  %59 = load i64, ptr @m, align 8, !tbaa !9
  %60 = mul nsw i64 %58, %59
  %61 = load i64, ptr %5, align 8, !tbaa !9
  %62 = sub nsw i64 %61, 1
  %63 = load i64, ptr @m, align 8, !tbaa !9
  %64 = sub nsw i64 %63, 1
  %65 = srem i64 %62, %64
  %66 = add nsw i64 %60, %65
  %67 = add nsw i64 %66, 2
  br label %69

68:                                               ; preds = %42
  br label %69

69:                                               ; preds = %68, %53
  %70 = phi i64 [ %67, %53 ], [ 1, %68 ]
  store i64 %70, ptr %6, align 8, !tbaa !9
  %71 = load i64, ptr %6, align 8, !tbaa !9
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [100000 x i64], ptr @a, i64 0, i64 %73
  %75 = load i64, ptr %74, align 8, !tbaa !9
  %76 = icmp sgt i64 %71, %75
  br i1 %76, label %77, label %78

77:                                               ; preds = %69
  store i32 7, ptr %4, align 4
  br label %116

78:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %79 = load i32, ptr %3, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [100000 x i64], ptr @a, i64 0, i64 %80
  %82 = load i64, ptr %81, align 8, !tbaa !9
  %83 = sub nsw i64 %82, 2
  %84 = load i64, ptr @m, align 8, !tbaa !9
  %85 = sdiv i64 %83, %84
  store i64 %85, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %86 = load i32, ptr %3, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [100000 x i64], ptr @a, i64 0, i64 %87
  %89 = load i64, ptr %88, align 8, !tbaa !9
  %90 = sub nsw i64 %89, 1
  %91 = load i64, ptr @m, align 8, !tbaa !9
  %92 = sdiv i64 %90, %91
  %93 = add nsw i64 %92, 1
  store i64 %93, ptr %8, align 8, !tbaa !9
  br label %94

94:                                               ; preds = %109, %78
  br label %95

95:                                               ; preds = %94
  %96 = load i64, ptr %6, align 8, !tbaa !9
  %97 = load i64, ptr %8, align 8, !tbaa !9
  %98 = icmp sge i64 %96, %97
  br i1 %98, label %99, label %104

99:                                               ; preds = %95
  %100 = load i32, ptr %3, align 4, !tbaa !5
  %101 = add nsw i32 %100, 1
  %102 = load i64, ptr %6, align 8, !tbaa !9
  %103 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %101, i64 noundef %102)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %115

104:                                              ; preds = %95
  %105 = load i64, ptr %6, align 8, !tbaa !9
  %106 = load i64, ptr %7, align 8, !tbaa !9
  %107 = icmp sgt i64 %105, %106
  br i1 %107, label %108, label %109

108:                                              ; preds = %104
  br label %114

109:                                              ; preds = %104
  %110 = load i64, ptr %6, align 8, !tbaa !9
  %111 = load i64, ptr @m, align 8, !tbaa !9
  %112 = mul nsw i64 %110, %111
  %113 = add nsw i64 %112, 1
  store i64 %113, ptr %6, align 8, !tbaa !9
  br label %94, !llvm.loop !13

114:                                              ; preds = %108
  store i32 0, ptr %4, align 4
  br label %115

115:                                              ; preds = %114, %99
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %116

116:                                              ; preds = %115, %77
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %117 = load i32, ptr %4, align 4
  switch i32 %117, label %122 [
    i32 0, label %118
    i32 7, label %119
  ]

118:                                              ; preds = %116
  br label %119

119:                                              ; preds = %118, %116
  %120 = load i32, ptr %3, align 4, !tbaa !5
  %121 = add nsw i32 %120, 1
  store i32 %121, ptr %3, align 4, !tbaa !5
  br label %37, !llvm.loop !14

122:                                              ; preds = %116, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  %123 = load i32, ptr %4, align 4
  switch i32 %123, label %127 [
    i32 5, label %124
    i32 1, label %125
  ]

124:                                              ; preds = %122
  store i32 -1, ptr %1, align 4
  br label %125

125:                                              ; preds = %124, %122, %34
  %126 = load i32, ptr %1, align 4
  ret i32 %126

127:                                              ; preds = %122
  unreachable
}

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

declare i32 @puts(ptr noundef) #3

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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; 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
@m = external dso_local global i64, align 8
@a = external dso_local global [100000 x i64], align 16
@SG = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [7 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
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z2sgxx(i64 noundef, i64 noundef) local_unnamed_addr #0

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

._crit_edge:                                      ; preds = %.lr.ph
  %.not = icmp eq i64 %10, %9
  br i1 %.not, label %15, label %.preheader

._crit_edge.thread:                               ; preds = %0
  %.pre = load i64, ptr @SG, align 8, !tbaa !9
  %.not73 = icmp eq i64 %.pre, 0
  br i1 %.not73, label %15, label %.loopexit37

.preheader:                                       ; preds = %._crit_edge
  %4 = icmp slt i32 %12, 1
  br i1 %4, label %.loopexit37, label %.lr.ph57

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %5 = getelementptr inbounds i64, ptr @a, i64 %indvars.iv
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %5)
  %7 = load i64, ptr %5, align 8, !tbaa !9
  %8 = load i64, ptr @m, align 8, !tbaa !9
  %9 = tail call noundef i64 @_Z2sgxx(i64 noundef %7, i64 noundef %8)
  %10 = load i64, ptr @SG, align 8, !tbaa !9
  %11 = xor i64 %10, %9
  store i64 %11, ptr @SG, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = icmp slt i64 %indvars.iv.next, %13
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !11

15:                                               ; preds = %._crit_edge.thread, %._crit_edge
  %16 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %.loopexit37

.lr.ph57:                                         ; preds = %.preheader, %.loopexit
  %indvars.iv70 = phi i64 [ %indvars.iv.next71, %.loopexit ], [ 0, %.preheader ]
  %17 = load i64, ptr @SG, align 8, !tbaa !9
  %18 = getelementptr inbounds [100000 x i64], ptr @a, i64 0, i64 %indvars.iv70
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = load i64, ptr @m, align 8, !tbaa !9
  %21 = tail call noundef i64 @_Z2sgxx(i64 noundef %19, i64 noundef %20)
  %.not33 = icmp eq i64 %17, %21
  br i1 %.not33, label %32, label %22

22:                                               ; preds = %.lr.ph57
  %23 = xor i64 %21, %17
  %24 = add nsw i64 %23, -1
  %25 = load i64, ptr @m, align 8, !tbaa !9
  %26 = add nsw i64 %25, -1
  %27 = sdiv i64 %24, %26
  %28 = mul nsw i64 %27, %25
  %29 = srem i64 %24, %26
  %30 = add i64 %29, 2
  %31 = add i64 %30, %28
  br label %32

32:                                               ; preds = %.lr.ph57, %22
  %33 = phi i64 [ %31, %22 ], [ 1, %.lr.ph57 ]
  %34 = load i64, ptr %18, align 8, !tbaa !9
  %35 = icmp sgt i64 %33, %34
  br i1 %35, label %.loopexit, label %36

36:                                               ; preds = %32
  %37 = add nsw i64 %34, -2
  %38 = load i64, ptr @m, align 8, !tbaa !9
  %39 = sdiv i64 %37, %38
  %40 = add nsw i64 %34, -1
  %41 = sdiv i64 %40, %38
  %.not34.not43 = icmp sgt i64 %33, %41
  br i1 %.not34.not43, label %._crit_edge47, label %.lr.ph46

.lr.ph46:                                         ; preds = %36, %43
  %.02544 = phi i64 [ %45, %43 ], [ %33, %36 ]
  %42 = icmp sgt i64 %.02544, %39
  br i1 %42, label %.loopexit, label %43

43:                                               ; preds = %.lr.ph46
  %44 = mul nsw i64 %.02544, %38
  %45 = add nsw i64 %44, 1
  %.not34.not.not = icmp slt i64 %44, %41
  br i1 %.not34.not.not, label %.lr.ph46, label %._crit_edge47, !llvm.loop !13

._crit_edge47:                                    ; preds = %36, %43
  %.025.lcssa = phi i64 [ %45, %43 ], [ %33, %36 ]
  %.0265562 = trunc i64 %indvars.iv70 to i32
  %46 = add nuw nsw i32 %.0265562, 1
  %47 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %46, i64 noundef %.025.lcssa)
  br label %.loopexit37

.loopexit:                                        ; preds = %.lr.ph46, %32
  %indvars.iv.next71 = add nuw nsw i64 %indvars.iv70, 1
  %48 = load i32, ptr @n, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %.not36.not = icmp slt i64 %indvars.iv.next71, %49
  br i1 %.not36.not, label %.lr.ph57, label %.loopexit37, !llvm.loop !14

.loopexit37:                                      ; preds = %.loopexit, %._crit_edge.thread, %._crit_edge47, %.preheader, %15
  %.4 = phi i32 [ 0, %15 ], [ 0, %._crit_edge47 ], [ -1, %.preheader ], [ -1, %._crit_edge.thread ], [ -1, %.loopexit ]
  ret i32 %.4
}

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

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

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

!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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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