; LLVM IR from tangjz/acm-icpc :: lydsy/4772.ll (Z5solvei)

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

@p = external dso_local global [2001 x i32], align 16
@dx = external dso_local global i32, align 4
@dy = external dso_local global i32, align 4
@c = external dso_local global [2001 x i32], align 16
@st = external dso_local global i32, align 4
@tim = external dso_local global [2001 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5solvei(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [2001 x i32], ptr @tim, i64 0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = load i32, ptr @st, align 4, !tbaa !5
  %9 = icmp eq i32 %7, %8
  br i1 %9, label %10, label %15

10:                                               ; preds = %1
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [2001 x i32], ptr @c, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  store i32 %14, ptr %2, align 4
  br label %79

15:                                               ; preds = %1
  %16 = load i32, ptr @st, align 4, !tbaa !5
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [2001 x i32], ptr @tim, i64 0, i64 %18
  store i32 %16, ptr %19, align 4, !tbaa !5
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [2001 x i32], ptr @c, i64 0, i64 %21
  store i32 0, ptr %22, align 4, !tbaa !5
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = load i32, ptr @dx, align 4, !tbaa !5
  %25 = icmp sge i32 %23, %24
  br i1 %25, label %26, label %34

26:                                               ; preds = %15
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [2001 x i32], ptr @c, i64 0, i64 %28
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = load i32, ptr @dx, align 4, !tbaa !5
  %32 = sub nsw i32 %30, %31
  %33 = call noundef i32 @_Z5solvei(i32 noundef %32)
  call void @_Z7mod_incRiii(ptr noundef nonnull align 4 dereferenceable(4) %29, i32 noundef %33, i32 noundef 1000000007)
  br label %34

34:                                               ; preds = %26, %15
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = load i32, ptr @dy, align 4, !tbaa !5
  %37 = icmp sge i32 %35, %36
  br i1 %37, label %38, label %46

38:                                               ; preds = %34
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [2001 x i32], ptr @c, i64 0, i64 %40
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = load i32, ptr @dy, align 4, !tbaa !5
  %44 = sub nsw i32 %42, %43
  %45 = call noundef i32 @_Z5solvei(i32 noundef %44)
  call void @_Z7mod_incRiii(ptr noundef nonnull align 4 dereferenceable(4) %41, i32 noundef %45, i32 noundef 1000000007)
  br label %46

46:                                               ; preds = %38, %34
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = load i32, ptr @dx, align 4, !tbaa !5
  %49 = load i32, ptr @dy, align 4, !tbaa !5
  %50 = add nsw i32 %48, %49
  %51 = icmp sge i32 %47, %50
  br i1 %51, label %52, label %74

52:                                               ; preds = %46
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [2001 x i32], ptr @c, i64 0, i64 %54
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = load i32, ptr @dx, align 4, !tbaa !5
  %58 = sub nsw i32 %56, %57
  %59 = load i32, ptr @dy, align 4, !tbaa !5
  %60 = sub nsw i32 %58, %59
  %61 = call noundef i32 @_Z5solvei(i32 noundef %60)
  %62 = sub nsw i32 1000000007, %61
  call void @_Z7mod_incRiii(ptr noundef nonnull align 4 dereferenceable(4) %55, i32 noundef %62, i32 noundef 1000000007)
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [2001 x i32], ptr @c, i64 0, i64 %64
  %66 = load i32, ptr %3, align 4, !tbaa !5
  %67 = load i32, ptr @dx, align 4, !tbaa !5
  %68 = sub nsw i32 %66, %67
  %69 = load i32, ptr @dy, align 4, !tbaa !5
  %70 = sub nsw i32 %68, %69
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [2001 x i32], ptr @p, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !5
  call void @_Z7mod_incRiii(ptr noundef nonnull align 4 dereferenceable(4) %65, i32 noundef %73, i32 noundef 1000000007)
  br label %74

74:                                               ; preds = %52, %46
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [2001 x i32], ptr @c, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  store i32 %78, ptr %2, align 4
  br label %79

79:                                               ; preds = %74, %10
  %80 = load i32, ptr %2, align 4
  ret i32 %80
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z7mod_incRiii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef) #1

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

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


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

@p = external dso_local local_unnamed_addr global [2001 x i32], align 16
@dx = external dso_local local_unnamed_addr global i32, align 4
@dy = external dso_local local_unnamed_addr global i32, align 4
@c = external dso_local global [2001 x i32], align 16
@st = external dso_local local_unnamed_addr global i32, align 4
@tim = external dso_local local_unnamed_addr global [2001 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z5solvei(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [2001 x i32], ptr @tim, i64 0, i64 %2
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = load i32, ptr @st, align 4, !tbaa !5
  %6 = icmp eq i32 %4, %5
  br i1 %6, label %7, label %9

7:                                                ; preds = %1
  %8 = getelementptr inbounds [2001 x i32], ptr @c, i64 0, i64 %2
  br label %35

9:                                                ; preds = %1
  store i32 %5, ptr %3, align 4, !tbaa !5
  %10 = getelementptr inbounds [2001 x i32], ptr @c, i64 0, i64 %2
  store i32 0, ptr %10, align 4, !tbaa !5
  %11 = load i32, ptr @dx, align 4, !tbaa !5
  %.not = icmp sgt i32 %11, %0
  br i1 %.not, label %15, label %12

12:                                               ; preds = %9
  %13 = sub nsw i32 %0, %11
  %14 = tail call noundef i32 @_Z5solvei(i32 noundef %13)
  tail call void @_Z7mod_incRiii(ptr noundef nonnull align 4 dereferenceable(4) %10, i32 noundef %14, i32 noundef 1000000007)
  br label %15

15:                                               ; preds = %12, %9
  %16 = load i32, ptr @dy, align 4, !tbaa !5
  %.not21 = icmp sgt i32 %16, %0
  br i1 %.not21, label %20, label %17

17:                                               ; preds = %15
  %18 = sub nsw i32 %0, %16
  %19 = tail call noundef i32 @_Z5solvei(i32 noundef %18)
  tail call void @_Z7mod_incRiii(ptr noundef nonnull align 4 dereferenceable(4) %10, i32 noundef %19, i32 noundef 1000000007)
  %.pre = load i32, ptr @dy, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %17, %15
  %21 = phi i32 [ %.pre, %17 ], [ %16, %15 ]
  %22 = load i32, ptr @dx, align 4, !tbaa !5
  %23 = add nsw i32 %21, %22
  %.not22 = icmp sgt i32 %23, %0
  br i1 %.not22, label %35, label %24

24:                                               ; preds = %20
  %25 = sub i32 %0, %23
  %26 = tail call noundef i32 @_Z5solvei(i32 noundef %25)
  %27 = sub nsw i32 1000000007, %26
  tail call void @_Z7mod_incRiii(ptr noundef nonnull align 4 dereferenceable(4) %10, i32 noundef %27, i32 noundef 1000000007)
  %28 = load i32, ptr @dx, align 4, !tbaa !5
  %29 = load i32, ptr @dy, align 4, !tbaa !5
  %30 = add i32 %28, %29
  %31 = sub i32 %0, %30
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [2001 x i32], ptr @p, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  tail call void @_Z7mod_incRiii(ptr noundef nonnull align 4 dereferenceable(4) %10, i32 noundef %34, i32 noundef 1000000007)
  br label %35

35:                                               ; preds = %20, %24, %7
  %.0.in = phi ptr [ %8, %7 ], [ %10, %24 ], [ %10, %20 ]
  %.0 = load i32, ptr %.0.in, align 4, !tbaa !5
  ret i32 %.0
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z7mod_incRiii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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" }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass