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

; 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 i32, align 4
@mx = external dso_local global i32, align 4
@f = external dso_local global [100001 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 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 [3 x i8], align 1
  %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) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %51, %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) #4
  br label %54

12:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 3, ptr %3) #4
  %13 = getelementptr inbounds [3 x i8], ptr %3, i64 0, i64 0
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %13)
  %15 = getelementptr inbounds [3 x i8], ptr %3, i64 0, i64 0
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = sext i8 %16 to i32
  %18 = icmp eq i32 %17, 75
  br i1 %18, label %19, label %43

19:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %21 = load i32, ptr @mx, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr @f, i64 %22
  %24 = getelementptr inbounds i32, ptr %23, i64 1
  %25 = load i32, ptr @m, align 4, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sub nsw i32 %26, %25
  store i32 %27, ptr %4, align 4, !tbaa !5
  %28 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef getelementptr inbounds (i32, ptr @f, i64 1), ptr noundef %24, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %29 = ptrtoint ptr %28 to i64
  %30 = sub i64 %29, ptrtoint (ptr @f to i64)
  %31 = sdiv exact i64 %30, 4
  %32 = trunc i64 %31 to i32
  store i32 %32, ptr %5, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %35
  store i32 %33, ptr %36, align 4, !tbaa !5
  %37 = load i32, ptr @mx, align 4, !tbaa !5
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  %40 = zext i1 %39 to i32
  %41 = load i32, ptr @mx, align 4, !tbaa !5
  %42 = add nsw i32 %41, %40
  store i32 %42, ptr @mx, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %50

43:                                               ; preds = %12
  %44 = load i32, ptr @m, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr @m, align 4, !tbaa !5
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = add nsw i32 %46, -1
  store i32 %47, ptr %2, align 4, !tbaa !5
  %48 = load i32, ptr @n, align 4, !tbaa !5
  %49 = add nsw i32 %48, -1
  store i32 %49, ptr @n, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %43, %19
  call void @llvm.lifetime.end.p0(i64 3, ptr %3) #4
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !10

54:                                               ; preds = %11
  %55 = load i32, ptr @mx, align 4, !tbaa !5
  %56 = load i32, ptr @m, align 4, !tbaa !5
  %57 = add nsw i32 %55, %56
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %57)
  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: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) #3

; 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 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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"

@n = external dso_local global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@mx = external dso_local local_unnamed_addr global i32, align 4
@f = external dso_local global [100001 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 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 = alloca [3 x i8], align 1
  %2 = alloca i32, align 4
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %38, %0
  %6 = load i32, ptr @mx, align 4, !tbaa !5
  %7 = load i32, ptr @m, align 4, !tbaa !5
  %8 = add nsw i32 %7, %6
  %9 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %8)
  ret i32 0

.lr.ph:                                           ; preds = %0, %38
  %.05 = phi i32 [ %40, %38 ], [ 0, %0 ]
  call void @llvm.lifetime.start.p0(i64 3, ptr nonnull %1) #4
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %11 = load i8, ptr %1, align 1, !tbaa !9
  %12 = icmp eq i8 %11, 75
  br i1 %12, label %13, label %32

13:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %15 = load i32, ptr @mx, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %gep = getelementptr i32, ptr getelementptr inbounds (i8, ptr @f, i64 4), i64 %16
  %17 = load i32, ptr @m, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sub nsw i32 %18, %17
  store i32 %19, ptr %2, align 4, !tbaa !5
  %20 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull getelementptr inbounds (i8, ptr @f, i64 4), ptr noundef nonnull %gep, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %21 = ptrtoint ptr %20 to i64
  %22 = sub i64 %21, ptrtoint (ptr @f to i64)
  %23 = lshr exact i64 %22, 2
  %24 = trunc i64 %23 to i32
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %sext = shl i64 %22, 30
  %26 = ashr i64 %sext, 32
  %27 = getelementptr inbounds [100001 x i32], ptr @f, i64 0, i64 %26
  store i32 %25, ptr %27, align 4, !tbaa !5
  %28 = load i32, ptr @mx, align 4, !tbaa !5
  %29 = icmp slt i32 %28, %24
  %30 = zext i1 %29 to i32
  %31 = add nsw i32 %28, %30
  store i32 %31, ptr @mx, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %38

32:                                               ; preds = %.lr.ph
  %33 = load i32, ptr @m, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr @m, align 4, !tbaa !5
  %35 = add nsw i32 %.05, -1
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %37 = add nsw i32 %36, -1
  store i32 %37, ptr @n, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %32, %13
  %39 = phi i32 [ %.pre, %13 ], [ %37, %32 ]
  %.1 = phi i32 [ %.05, %13 ], [ %35, %32 ]
  call void @llvm.lifetime.end.p0(i64 3, ptr nonnull %1) #4
  %40 = add nsw i32 %.1, 1
  %41 = icmp slt i32 %40, %39
  br i1 %41, label %.lr.ph, label %._crit_edge, !llvm.loop !10
}

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass