; LLVM IR from tangjz/acm-icpc :: 51nod/1297.ll (Z3bfsi)

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

@lnk = external dso_local global [100001 x i32], align 16
@e = external dso_local global [200003 x %struct.Edge], align 16
@ban = external dso_local global [100001 x i8], align 16
@tot = external dso_local global i32, align 4
@ord = external dso_local global [100001 x i32], align 16
@fa = external dso_local global [100001 x i32], align 16
@dep = external dso_local global [100001 x i32], 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 nounwind uwtable
define dso_local void @_Z3bfsi(i32 noundef %0) #1 {
  %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
  store i32 %0, ptr %2, align 4, !tbaa !5
  store i32 0, ptr @tot, align 4, !tbaa !5
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr @tot, align 4, !tbaa !5
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr @tot, align 4, !tbaa !5
  %11 = sext i32 %9 to i64
  %12 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %11
  store i32 %8, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %78, %1
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = load i32, ptr @tot, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %81

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  store i32 %22, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100001 x i32], ptr @lnk, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  store i32 %26, ptr %6, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %71, %18
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = icmp ne i32 %28, -1
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %77

31:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.Edge, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !9
  store i32 %36, ptr %7, align 4, !tbaa !5
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100001 x i32], ptr @fa, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = icmp eq i32 %37, %41
  br i1 %42, label %49, label %43

43:                                               ; preds = %31
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100001 x i8], ptr @ban, i64 0, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !11, !range !13, !noundef !14
  %48 = trunc i8 %47 to i1
  br i1 %48, label %49, label %50

49:                                               ; preds = %43, %31
  store i32 7, ptr %4, align 4
  br label %68

50:                                               ; preds = %43
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100001 x i32], ptr @fa, i64 0, i64 %53
  store i32 %51, ptr %54, align 4, !tbaa !5
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100001 x i32], ptr @dep, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [100001 x i32], ptr @dep, i64 0, i64 %61
  store i32 %59, ptr %62, align 4, !tbaa !5
  %63 = load i32, ptr %7, align 4, !tbaa !5
  %64 = load i32, ptr @tot, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr @tot, align 4, !tbaa !5
  %66 = sext i32 %64 to i64
  %67 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %66
  store i32 %63, ptr %67, align 4, !tbaa !5
  store i32 0, ptr %4, align 4
  br label %68

68:                                               ; preds = %50, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  %69 = load i32, ptr %4, align 4
  switch i32 %69, label %82 [
    i32 0, label %70
    i32 7, label %71
  ]

70:                                               ; preds = %68
  br label %71

71:                                               ; preds = %70, %68
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %73
  %75 = getelementptr inbounds %struct.Edge, ptr %74, i32 0, i32 0
  %76 = load i32, ptr %75, align 8, !tbaa !15
  store i32 %76, ptr %6, align 4, !tbaa !5
  br label %27, !llvm.loop !16

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

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

81:                                               ; preds = %17
  ret void

82:                                               ; preds = %68
  unreachable
}

attributes #0 = { 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 = { 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, !6, i64 4}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!10, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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

@lnk = external dso_local local_unnamed_addr global [100001 x i32], align 16
@e = external dso_local local_unnamed_addr global [200003 x %struct.Edge], align 16
@ban = external dso_local local_unnamed_addr global [100001 x i8], align 16
@tot = external dso_local local_unnamed_addr global i32, align 4
@ord = external dso_local local_unnamed_addr global [100001 x i32], align 16
@fa = external dso_local local_unnamed_addr global [100001 x i32], align 16
@dep = external dso_local local_unnamed_addr global [100001 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3bfsi(i32 noundef %0) local_unnamed_addr #0 {
.lr.ph29.preheader:
  store i32 1, ptr @tot, align 4, !tbaa !5
  store i32 %0, ptr @ord, align 16, !tbaa !5
  br label %.lr.ph29

._crit_edge30:                                    ; preds = %._crit_edge
  ret void

.lr.ph29:                                         ; preds = %.lr.ph29.preheader, %._crit_edge
  %indvars.iv = phi i64 [ 0, %.lr.ph29.preheader ], [ %indvars.iv.next, %._crit_edge ]
  %tot.promoted2526 = phi i32 [ 1, %.lr.ph29.preheader ], [ %tot.promoted24, %._crit_edge ]
  %1 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %indvars.iv
  %2 = load i32, ptr %1, align 4, !tbaa !5
  %3 = sext i32 %2 to i64
  %4 = getelementptr inbounds [100001 x i32], ptr @lnk, i64 0, i64 %3
  %.01618 = load i32, ptr %4, align 4, !tbaa !5
  %.not19 = icmp eq i32 %.01618, -1
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph29
  %5 = getelementptr inbounds [100001 x i32], ptr @fa, i64 0, i64 %3
  %6 = getelementptr inbounds [100001 x i32], ptr @dep, i64 0, i64 %3
  br label %9

._crit_edge:                                      ; preds = %30, %.lr.ph29
  %tot.promoted24 = phi i32 [ %tot.promoted2526, %.lr.ph29 ], [ %tot.promoted22, %30 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %7 = sext i32 %tot.promoted24 to i64
  %8 = icmp slt i64 %indvars.iv.next, %7
  br i1 %8, label %.lr.ph29, label %._crit_edge30, !llvm.loop !9

9:                                                ; preds = %.lr.ph, %30
  %tot.promoted23 = phi i32 [ %tot.promoted2526, %.lr.ph ], [ %tot.promoted22, %30 ]
  %.01620 = phi i32 [ %.01618, %.lr.ph ], [ %.016, %30 ]
  %10 = phi i32 [ %tot.promoted2526, %.lr.ph ], [ %31, %30 ]
  %11 = sext i32 %.01620 to i64
  %12 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %11
  %13 = getelementptr inbounds i8, ptr %12, i64 4
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = icmp eq i32 %14, %15
  br i1 %16, label %30, label %17

17:                                               ; preds = %9
  %18 = sext i32 %14 to i64
  %19 = getelementptr inbounds [100001 x i8], ptr @ban, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !13, !range !15, !noundef !16
  %21 = trunc nuw i8 %20 to i1
  br i1 %21, label %30, label %22

22:                                               ; preds = %17
  %23 = getelementptr inbounds [100001 x i32], ptr @fa, i64 0, i64 %18
  store i32 %2, ptr %23, align 4, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  %26 = getelementptr inbounds [100001 x i32], ptr @dep, i64 0, i64 %18
  store i32 %25, ptr %26, align 4, !tbaa !5
  %27 = add nsw i32 %10, 1
  store i32 %27, ptr @tot, align 4, !tbaa !5
  %28 = sext i32 %10 to i64
  %29 = getelementptr inbounds [100001 x i32], ptr @ord, i64 0, i64 %28
  store i32 %14, ptr %29, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %9, %17, %22
  %tot.promoted22 = phi i32 [ %tot.promoted23, %9 ], [ %tot.promoted23, %17 ], [ %27, %22 ]
  %31 = phi i32 [ %10, %9 ], [ %10, %17 ], [ %27, %22 ]
  %.016 = load i32, ptr %12, align 8, !tbaa !5
  %.not = icmp eq i32 %.016, -1
  br i1 %.not, label %._crit_edge, label %9, !llvm.loop !17
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 4}
!12 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!13 = !{!14, !14, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass