; LLVM IR from tangjz/acm-icpc :: codechef/SNCKEL19 (ADIMAT)

; 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
@pw = external dso_local global [551 x [551 x i32]], align 16
@inv = external dso_local global [551 x i32], align 16
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

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

11:                                               ; preds = %7
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sub nsw i32 %12, 1
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [551 x i32], ptr @pw, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = shl i32 %16, 1
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [551 x i32], ptr @pw, i64 0, i64 %19
  store i32 %17, ptr %20, align 4, !tbaa !5
  %21 = icmp sge i32 %17, 1000000007
  br i1 %21, label %22, label %29

22:                                               ; preds = %11
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [551 x i32], ptr @pw, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = sub nsw i32 %26, 1000000007
  store i32 %27, ptr %25, align 4, !tbaa !5
  %28 = icmp ne i32 %27, 0
  br label %29

29:                                               ; preds = %22, %11
  %30 = phi i1 [ false, %11 ], [ %28, %22 ]
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [551 x i32], ptr @pw, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [551 x [551 x i32]], ptr @pw, i64 0, i64 %36
  %38 = getelementptr inbounds [551 x i32], ptr %37, i64 0, i64 0
  store i32 %34, ptr %38, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %29
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

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

43:                                               ; preds = %79, %42
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = icmp slt i32 %44, 551
  br i1 %45, label %47, label %46

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

47:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %48 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %48, ptr %5, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %75, %47
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = icmp slt i32 %50, 551
  br i1 %51, label %53, label %52

52:                                               ; preds = %49
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %78

53:                                               ; preds = %49
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [551 x [551 x i32]], ptr @pw, i64 0, i64 %55
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = sub nsw i32 %57, %58
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [551 x i32], ptr %56, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [551 x [551 x i32]], ptr @pw, i64 0, i64 %64
  %66 = load i32, ptr %3, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [551 x i32], ptr %65, i64 0, i64 %67
  store i32 %62, ptr %68, align 4, !tbaa !5
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [551 x [551 x i32]], ptr @pw, i64 0, i64 %70
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [551 x i32], ptr %71, i64 0, i64 %73
  store i32 %62, ptr %74, align 4, !tbaa !5
  br label %75

75:                                               ; preds = %53
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %5, align 4, !tbaa !5
  br label %49, !llvm.loop !11

78:                                               ; preds = %52
  br label %79

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

82:                                               ; preds = %46
  store i32 1, ptr getelementptr inbounds ([551 x i32], ptr @inv, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 2, ptr %6, align 4, !tbaa !5
  br label %83

83:                                               ; preds = %104, %82
  %84 = load i32, ptr %6, align 4, !tbaa !5
  %85 = icmp slt i32 %84, 551
  br i1 %85, label %87, label %86

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

87:                                               ; preds = %83
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = sdiv i32 1000000007, %88
  %90 = sext i32 %89 to i64
  %91 = load i32, ptr %6, align 4, !tbaa !5
  %92 = srem i32 1000000007, %91
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [551 x i32], ptr @inv, i64 0, i64 %93
  %95 = load i32, ptr %94, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = mul nsw i64 %90, %96
  %98 = srem i64 %97, 1000000007
  %99 = trunc i64 %98 to i32
  %100 = sub nsw i32 1000000007, %99
  %101 = load i32, ptr %6, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [551 x i32], ptr @inv, i64 0, i64 %102
  store i32 %100, ptr %103, align 4, !tbaa !5
  br label %104

104:                                              ; preds = %87
  %105 = load i32, ptr %6, align 4, !tbaa !5
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %6, align 4, !tbaa !5
  br label %83, !llvm.loop !13

107:                                              ; preds = %86
  %108 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %109 = load i32, ptr @n, align 4, !tbaa !5
  %110 = load i32, ptr @m, align 4, !tbaa !5
  %111 = icmp sgt i32 %109, %110
  br i1 %111, label %112, label %113

112:                                              ; preds = %107
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) @n, ptr noundef nonnull align 4 dereferenceable(4) @m) #5
  br label %113

113:                                              ; preds = %112, %107
  call void @_Z3dfsiiii(i32 noundef 0, i32 noundef 0, i32 noundef 1, i32 noundef 1)
  %114 = load i32, ptr @ans, align 4, !tbaa !5
  %115 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %114)
  ret i32 0
}

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

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

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 = { 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" }
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 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !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
@m = external dso_local global i32, align 4
@pw = external dso_local local_unnamed_addr global [551 x [551 x i32]], align 16
@inv = external dso_local local_unnamed_addr global [551 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  store i32 1, ptr @pw, align 16, !tbaa !5
  br label %1

1:                                                ; preds = %1, %0
  %indvars.iv = phi i64 [ 1, %0 ], [ %indvars.iv.next.1, %1 ]
  %2 = add nsw i64 %indvars.iv, -1
  %3 = getelementptr inbounds [551 x i32], ptr @pw, i64 0, i64 %2
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = shl i32 %4, 1
  %6 = getelementptr inbounds [551 x i32], ptr @pw, i64 0, i64 %indvars.iv
  %7 = icmp sgt i32 %5, 1000000006
  %8 = add nsw i32 %5, -1000000007
  %spec.select = select i1 %7, i32 %8, i32 %5
  store i32 %spec.select, ptr %6, align 4, !tbaa !5
  %9 = getelementptr inbounds [551 x [551 x i32]], ptr @pw, i64 0, i64 %indvars.iv
  store i32 %spec.select, ptr %9, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = getelementptr inbounds [551 x i32], ptr @pw, i64 0, i64 %indvars.iv
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = shl i32 %11, 1
  %13 = getelementptr inbounds [551 x i32], ptr @pw, i64 0, i64 %indvars.iv.next
  %14 = icmp sgt i32 %12, 1000000006
  %15 = add nsw i32 %12, -1000000007
  %spec.select.1 = select i1 %14, i32 %15, i32 %12
  store i32 %spec.select.1, ptr %13, align 4, !tbaa !5
  %16 = getelementptr inbounds [551 x [551 x i32]], ptr @pw, i64 0, i64 %indvars.iv.next
  store i32 %spec.select.1, ptr %16, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 551
  br i1 %exitcond.not.1, label %.preheader, label %1, !llvm.loop !9

.preheader:                                       ; preds = %1, %18
  %indvars.iv34 = phi i64 [ %indvars.iv.next35, %18 ], [ 1, %1 ]
  br label %19

17:                                               ; preds = %18
  store i32 1, ptr getelementptr inbounds (i8, ptr @inv, i64 4), align 4, !tbaa !5
  br label %30

18:                                               ; preds = %19
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond41.not = icmp eq i64 %indvars.iv.next35, 551
  br i1 %exitcond41.not, label %17, label %.preheader, !llvm.loop !11

19:                                               ; preds = %.preheader, %19
  %indvars.iv36 = phi i64 [ %indvars.iv34, %.preheader ], [ %indvars.iv.next37, %19 ]
  %20 = sub nuw nsw i64 %indvars.iv36, %indvars.iv34
  %21 = getelementptr inbounds [551 x [551 x i32]], ptr @pw, i64 0, i64 %indvars.iv34, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = getelementptr inbounds [551 x [551 x i32]], ptr @pw, i64 0, i64 %indvars.iv36, i64 %indvars.iv34
  store i32 %22, ptr %23, align 4, !tbaa !5
  %24 = getelementptr inbounds [551 x [551 x i32]], ptr @pw, i64 0, i64 %indvars.iv34, i64 %indvars.iv36
  store i32 %22, ptr %24, align 4, !tbaa !5
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %exitcond39.not = icmp eq i64 %indvars.iv.next37, 551
  br i1 %exitcond39.not, label %18, label %19, !llvm.loop !12

25:                                               ; preds = %30
  %26 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %27 = load i32, ptr @n, align 4, !tbaa !5
  %28 = load i32, ptr @m, align 4, !tbaa !5
  %29 = icmp sgt i32 %27, %28
  br i1 %29, label %44, label %45

30:                                               ; preds = %17, %30
  %indvars.iv42 = phi i64 [ 2, %17 ], [ %indvars.iv.next43, %30 ]
  %31 = trunc nuw nsw i64 %indvars.iv42 to i32
  %32 = udiv i32 1000000007, %31
  %33 = zext nneg i32 %32 to i64
  %34 = urem i32 1000000007, %31
  %35 = zext nneg i32 %34 to i64
  %36 = getelementptr inbounds [551 x i32], ptr @inv, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = mul nsw i64 %38, %33
  %40 = srem i64 %39, 1000000007
  %41 = trunc nsw i64 %40 to i32
  %42 = sub nsw i32 1000000007, %41
  %43 = getelementptr inbounds [551 x i32], ptr @inv, i64 0, i64 %indvars.iv42
  store i32 %42, ptr %43, align 4, !tbaa !5
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %exitcond45.not = icmp eq i64 %indvars.iv.next43, 551
  br i1 %exitcond45.not, label %25, label %30, !llvm.loop !13

44:                                               ; preds = %25
  tail call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) @n, ptr noundef nonnull align 4 dereferenceable(4) @m) #4
  br label %45

45:                                               ; preds = %44, %25
  tail call void @_Z3dfsiiii(i32 noundef 0, i32 noundef 0, i32 noundef 1, i32 noundef 1)
  %46 = load i32, ptr @ans, align 4, !tbaa !5
  %47 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %46)
  ret i32 0
}

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

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

; 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" }
attributes #3 = { 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" }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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