; LLVM IR from tangjz/acm-icpc :: lydsy/1443.ll (Z5checkii)

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

%struct.Edge = type { i32, i32, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@lnk = external dso_local global [10201 x i32], align 16
@str = external dso_local global [101 x [101 x i8]], align 16
@e = external dso_local global [61206 x %struct.Edge], align 16
@vis = external dso_local global [10201 x i8], align 16

; 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
define dso_local void @_Z5checkii(i32 noundef %0, i32 noundef %1) #1 {
  %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
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [10201 x i8], ptr @vis, i64 0, i64 %9
  store i8 1, ptr %10, align 1, !tbaa !9
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = load i32, ptr @m, align 4, !tbaa !5
  %14 = mul nsw i32 %12, %13
  %15 = icmp slt i32 %11, %14
  br i1 %15, label %16, label %33

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %17 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z4ridxiRiS_(i32 noundef %17, ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = and i32 %18, 1
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = and i32 %20, 1
  %22 = xor i32 %19, %21
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = icmp eq i32 %22, %23
  br i1 %24, label %25, label %32

25:                                               ; preds = %16
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [101 x [101 x i8]], ptr @str, i64 0, i64 %27
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [101 x i8], ptr %28, i64 0, i64 %30
  store i8 42, ptr %31, align 1, !tbaa !11
  br label %32

32:                                               ; preds = %25, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %33

33:                                               ; preds = %32, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [10201 x i32], ptr @lnk, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  store i32 %37, ptr %7, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %69, %33
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = icmp ne i32 %39, -1
  br i1 %40, label %42, label %41

41:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %75

42:                                               ; preds = %38
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = xor i32 %43, %44
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [61206 x %struct.Edge], ptr @e, i64 0, i64 %46
  %48 = getelementptr inbounds %struct.Edge, ptr %47, i32 0, i32 2
  %49 = load i32, ptr %48, align 4, !tbaa !12
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %68

51:                                               ; preds = %42
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [61206 x %struct.Edge], ptr @e, i64 0, i64 %53
  %55 = getelementptr inbounds %struct.Edge, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 4, !tbaa !14
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [10201 x i8], ptr @vis, i64 0, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !9, !range !15, !noundef !16
  %60 = trunc i8 %59 to i1
  br i1 %60, label %68, label %61

61:                                               ; preds = %51
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [61206 x %struct.Edge], ptr @e, i64 0, i64 %63
  %65 = getelementptr inbounds %struct.Edge, ptr %64, i32 0, i32 1
  %66 = load i32, ptr %65, align 4, !tbaa !14
  %67 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z5checkii(i32 noundef %66, i32 noundef %67)
  br label %68

68:                                               ; preds = %61, %51, %42
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [61206 x %struct.Edge], ptr @e, i64 0, i64 %71
  %73 = getelementptr inbounds %struct.Edge, ptr %72, i32 0, i32 0
  %74 = load i32, ptr %73, align 4, !tbaa !17
  store i32 %74, ptr %7, align 4, !tbaa !5
  br label %38, !llvm.loop !18

75:                                               ; preds = %41
  ret void
}

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

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 = { 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 #3 = { 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 = !{!"bool", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 8}
!13 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !6, i64 8}
!14 = !{!13, !6, i64 4}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!13, !6, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%struct.Edge = type { i32, i32, i32 }

@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@lnk = external dso_local local_unnamed_addr global [10201 x i32], align 16
@str = external dso_local local_unnamed_addr global [101 x [101 x i8]], align 16
@e = external dso_local local_unnamed_addr global [61206 x %struct.Edge], align 16
@vis = external dso_local local_unnamed_addr global [10201 x i8], align 16

; 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 nounwind uwtable
define dso_local void @_Z5checkii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [10201 x i8], ptr @vis, i64 0, i64 %5
  store i8 1, ptr %6, align 1, !tbaa !5
  %7 = load i32, ptr @n, align 4, !tbaa !9
  %8 = load i32, ptr @m, align 4, !tbaa !9
  %9 = mul nsw i32 %8, %7
  %10 = icmp sgt i32 %9, %0
  br i1 %10, label %11, label %22

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  call void @_Z4ridxiRiS_(i32 noundef %0, ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = xor i32 %13, %12
  %15 = and i32 %14, 1
  %16 = icmp eq i32 %15, %1
  br i1 %16, label %17, label %21

17:                                               ; preds = %11
  %18 = sext i32 %12 to i64
  %19 = sext i32 %13 to i64
  %20 = getelementptr inbounds [101 x [101 x i8]], ptr @str, i64 0, i64 %18, i64 %19
  store i8 42, ptr %20, align 1, !tbaa !11
  br label %21

21:                                               ; preds = %17, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br label %22

22:                                               ; preds = %21, %2
  %23 = getelementptr inbounds [10201 x i32], ptr @lnk, i64 0, i64 %5
  %.014 = load i32, ptr %23, align 4, !tbaa !9
  %.not15 = icmp eq i32 %.014, -1
  br i1 %.not15, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph._crit_edge, %22
  ret void

.lr.ph:                                           ; preds = %22, %.lr.ph._crit_edge
  %.016 = phi i32 [ %.0, %.lr.ph._crit_edge ], [ %.014, %22 ]
  %24 = xor i32 %.016, %1
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [61206 x %struct.Edge], ptr @e, i64 0, i64 %25, i32 2
  %27 = load i32, ptr %26, align 4, !tbaa !12
  %.not13 = icmp eq i32 %27, 0
  %.pre = sext i32 %.016 to i64
  br i1 %.not13, label %.lr.ph._crit_edge, label %28

28:                                               ; preds = %.lr.ph
  %29 = getelementptr inbounds [61206 x %struct.Edge], ptr @e, i64 0, i64 %.pre, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !14
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [10201 x i8], ptr @vis, i64 0, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !5, !range !15, !noundef !16
  %34 = trunc nuw i8 %33 to i1
  br i1 %34, label %.lr.ph._crit_edge, label %35

35:                                               ; preds = %28
  call void @_Z5checkii(i32 noundef %30, i32 noundef %1)
  br label %.lr.ph._crit_edge

.lr.ph._crit_edge:                                ; preds = %.lr.ph, %28, %35
  %36 = getelementptr inbounds [61206 x %struct.Edge], ptr @e, i64 0, i64 %.pre
  %.0 = load i32, ptr %36, align 4, !tbaa !9
  %.not = icmp eq i32 %.0, -1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 8}
!13 = !{!"_ZTS4Edge", !10, i64 0, !10, i64 4, !10, i64 8}
!14 = !{!13, !10, i64 4}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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