; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ (1254)

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

@map = external dso_local global [10 x [10 x i32]], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 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 [4 x i8], align 1

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

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

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

11:                                               ; preds = %78, %0
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = add nsw i32 %12, -1
  store i32 %13, ptr %4, align 4, !tbaa !5
  %14 = icmp ne i32 %12, 0
  br i1 %14, label %15, label %79

15:                                               ; preds = %11
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @m)
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %62, %15
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = icmp sle i32 %18, %19
  br i1 %20, label %21, label %65

21:                                               ; preds = %17
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %58, %21
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = load i32, ptr @m, align 4, !tbaa !5
  %25 = icmp sle i32 %23, %24
  br i1 %25, label %26, label %61

26:                                               ; preds = %22
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [10 x [10 x i32]], ptr @map, i64 0, i64 %28
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [10 x i32], ptr %29, i64 0, i64 %31
  %33 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %32)
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [10 x [10 x i32]], ptr @map, i64 0, i64 %35
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [10 x i32], ptr %36, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = icmp eq i32 %40, 2
  br i1 %41, label %42, label %45

42:                                               ; preds = %26
  %43 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %43, ptr %5, align 4, !tbaa !5
  %44 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %44, ptr %6, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %42, %26
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [10 x [10 x i32]], ptr @map, i64 0, i64 %47
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [10 x i32], ptr %48, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = icmp eq i32 %52, 4
  br i1 %53, label %54, label %57

54:                                               ; preds = %45
  %55 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %55, ptr %7, align 4, !tbaa !5
  %56 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %56, ptr %8, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %54, %45
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %3, align 4, !tbaa !5
  br label %22, !llvm.loop !9

61:                                               ; preds = %22
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %2, align 4, !tbaa !5
  br label %17, !llvm.loop !11

65:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = load i32, ptr %7, align 4, !tbaa !5
  %69 = load i32, ptr %8, align 4, !tbaa !5
  %70 = call noundef i32 @_Z3bfsiiii(i32 noundef %66, i32 noundef %67, i32 noundef %68, i32 noundef %69)
  store i32 %70, ptr %9, align 4, !tbaa !5
  %71 = load i32, ptr %9, align 4, !tbaa !5
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %75, label %73

73:                                               ; preds = %65
  %74 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %78

75:                                               ; preds = %65
  %76 = load i32, ptr %9, align 4, !tbaa !5
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %76)
  br label %78

78:                                               ; preds = %75, %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %11, !llvm.loop !12

79:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !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"

@map = external dso_local global [10 x [10 x i32]], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 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 [4 x i8], align 1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3bfsiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = add nsw i32 %3, -1
  store i32 %4, ptr %1, align 4, !tbaa !5
  %.not62 = icmp eq i32 %3, 0
  br i1 %.not62, label %._crit_edge69, label %.lr.ph68

.lr.ph68:                                         ; preds = %0, %29
  %.02066 = phi i32 [ %.1.lcssa, %29 ], [ undef, %0 ]
  %.02165 = phi i32 [ %.122.lcssa, %29 ], [ undef, %0 ]
  %.02564 = phi i32 [ %.126.lcssa, %29 ], [ undef, %0 ]
  %.02963 = phi i32 [ %.130.lcssa, %29 ], [ undef, %0 ]
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %.not3548 = icmp slt i32 %6, 1
  %7 = load i32, ptr @m, align 4
  %8 = icmp slt i32 %7, 1
  %or.cond = select i1 %.not3548, i1 true, i1 %8
  br i1 %or.cond, label %._crit_edge54, label %.preheader

.preheader:                                       ; preds = %.lr.ph68, %._crit_edge
  %9 = phi i32 [ %21, %._crit_edge ], [ %6, %.lr.ph68 ]
  %10 = phi i32 [ %22, %._crit_edge ], [ %7, %.lr.ph68 ]
  %indvars.iv72 = phi i64 [ %indvars.iv.next73, %._crit_edge ], [ 1, %.lr.ph68 ]
  %.152 = phi i32 [ %.2.lcssa, %._crit_edge ], [ %.02066, %.lr.ph68 ]
  %.12251 = phi i32 [ %.223.lcssa, %._crit_edge ], [ %.02165, %.lr.ph68 ]
  %.12650 = phi i32 [ %.227.lcssa, %._crit_edge ], [ %.02564, %.lr.ph68 ]
  %.13049 = phi i32 [ %.231.lcssa, %._crit_edge ], [ %.02963, %.lr.ph68 ]
  %.not3739 = icmp slt i32 %10, 1
  br i1 %.not3739, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %11 = trunc nuw nsw i64 %indvars.iv72 to i32
  br label %12

12:                                               ; preds = %.lr.ph, %12
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %12 ]
  %.244 = phi i32 [ %.152, %.lr.ph ], [ %.3, %12 ]
  %.22343 = phi i32 [ %.12251, %.lr.ph ], [ %.324, %12 ]
  %.22742 = phi i32 [ %.12650, %.lr.ph ], [ %spec.select38, %12 ]
  %.23141 = phi i32 [ %.13049, %.lr.ph ], [ %spec.select, %12 ]
  %13 = getelementptr inbounds [10 x [10 x i32]], ptr @map, i64 0, i64 %indvars.iv72, i64 %indvars.iv
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %13)
  %15 = load i32, ptr %13, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 2
  %spec.select = select i1 %16, i32 %11, i32 %.23141
  %17 = trunc nuw nsw i64 %indvars.iv to i32
  %spec.select38 = select i1 %16, i32 %17, i32 %.22742
  %18 = icmp eq i32 %15, 4
  %.324 = select i1 %18, i32 %11, i32 %.22343
  %.3 = select i1 %18, i32 %17, i32 %.244
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = load i32, ptr @m, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %.not37.not = icmp slt i64 %indvars.iv, %20
  br i1 %.not37.not, label %12, label %._crit_edge.loopexit, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %12
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %21 = phi i32 [ %9, %.preheader ], [ %.pre, %._crit_edge.loopexit ]
  %22 = phi i32 [ %10, %.preheader ], [ %19, %._crit_edge.loopexit ]
  %.231.lcssa = phi i32 [ %.13049, %.preheader ], [ %spec.select, %._crit_edge.loopexit ]
  %.227.lcssa = phi i32 [ %.12650, %.preheader ], [ %spec.select38, %._crit_edge.loopexit ]
  %.223.lcssa = phi i32 [ %.12251, %.preheader ], [ %.324, %._crit_edge.loopexit ]
  %.2.lcssa = phi i32 [ %.152, %.preheader ], [ %.3, %._crit_edge.loopexit ]
  %indvars.iv.next73 = add nuw nsw i64 %indvars.iv72, 1
  %23 = sext i32 %21 to i64
  %.not35.not = icmp slt i64 %indvars.iv72, %23
  br i1 %.not35.not, label %.preheader, label %._crit_edge54, !llvm.loop !11

._crit_edge54:                                    ; preds = %._crit_edge, %.lr.ph68
  %.130.lcssa = phi i32 [ %.02963, %.lr.ph68 ], [ %.231.lcssa, %._crit_edge ]
  %.126.lcssa = phi i32 [ %.02564, %.lr.ph68 ], [ %.227.lcssa, %._crit_edge ]
  %.122.lcssa = phi i32 [ %.02165, %.lr.ph68 ], [ %.223.lcssa, %._crit_edge ]
  %.1.lcssa = phi i32 [ %.02066, %.lr.ph68 ], [ %.2.lcssa, %._crit_edge ]
  %24 = call noundef i32 @_Z3bfsiiii(i32 noundef %.130.lcssa, i32 noundef %.126.lcssa, i32 noundef %.122.lcssa, i32 noundef %.1.lcssa)
  %.not36 = icmp eq i32 %24, 0
  br i1 %.not36, label %25, label %27

25:                                               ; preds = %._crit_edge54
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %29

27:                                               ; preds = %._crit_edge54
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %24)
  br label %29

29:                                               ; preds = %27, %25
  %30 = load i32, ptr %1, align 4, !tbaa !5
  %31 = add nsw i32 %30, -1
  store i32 %31, ptr %1, align 4, !tbaa !5
  %.not = icmp eq i32 %30, 0
  br i1 %.not, label %._crit_edge69, label %.lr.ph68, !llvm.loop !13

._crit_edge69:                                    ; preds = %29, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0
}

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 #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}
!12 = !{!"llvm.loop.unswitch.partial.disable"}
!13 = distinct !{!13, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass