; LLVM IR from tangjz/acm-icpc :: codeforces/gym/101471J.ll (Z3bfsv)

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

@N = external dso_local global i32, align 4
@S = external dso_local global i32, align 4
@T = external dso_local global i32, align 4
@lev = external dso_local global [201 x i32], align 16
@lnk = external dso_local global [201 x i32], align 16
@e = external dso_local global [161605 x %struct.Edge], align 16
@_ZZ3bfsvE3que = external hidden global [201 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3bfsv() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr @N, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = mul i64 %6, 4
  call void @llvm.memset.p0.i64(ptr align 16 @lev, i8 -1, i64 %7, i1 false)
  %8 = load i32, ptr @S, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [201 x i32], ptr @lev, i64 0, i64 %9
  store i32 0, ptr %10, align 4, !tbaa !5
  %11 = load i32, ptr @S, align 4, !tbaa !5
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %12 to i64
  %15 = getelementptr inbounds [201 x i32], ptr @_ZZ3bfsvE3que, i64 0, i64 %14
  store i32 %11, ptr %15, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %81, %0
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %20, label %82

20:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %1, align 4, !tbaa !5
  %23 = sext i32 %21 to i64
  %24 = getelementptr inbounds [201 x i32], ptr @_ZZ3bfsvE3que, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  store i32 %25, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [201 x i32], ptr @lnk, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  store i32 %29, ptr %4, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %75, %20
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = icmp ne i32 %31, -1
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %81

34:                                               ; preds = %30
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [161605 x %struct.Edge], ptr @e, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.Edge, ptr %37, i32 0, i32 2
  %39 = load x86_fp80, ptr %38, align 16, !tbaa !9
  %40 = call noundef i32 @_Z3sgne(x86_fp80 noundef %39)
  %41 = icmp sgt i32 %40, 0
  br i1 %41, label %42, label %74

42:                                               ; preds = %34
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [161605 x %struct.Edge], ptr @e, i64 0, i64 %44
  %46 = getelementptr inbounds %struct.Edge, ptr %45, i32 0, i32 1
  %47 = load i32, ptr %46, align 4, !tbaa !12
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [201 x i32], ptr @lev, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = icmp eq i32 %50, -1
  br i1 %51, label %52, label %74

52:                                               ; preds = %42
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [201 x i32], ptr @lev, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [161605 x %struct.Edge], ptr @e, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.Edge, ptr %60, i32 0, i32 1
  %62 = load i32, ptr %61, align 4, !tbaa !12
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [201 x i32], ptr @lev, i64 0, i64 %63
  store i32 %57, ptr %64, align 4, !tbaa !5
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [161605 x %struct.Edge], ptr @e, i64 0, i64 %66
  %68 = getelementptr inbounds %struct.Edge, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %68, align 4, !tbaa !12
  %70 = load i32, ptr %2, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %2, align 4, !tbaa !5
  %72 = sext i32 %70 to i64
  %73 = getelementptr inbounds [201 x i32], ptr @_ZZ3bfsvE3que, i64 0, i64 %72
  store i32 %69, ptr %73, align 4, !tbaa !5
  br label %74

74:                                               ; preds = %52, %42, %34
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %4, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [161605 x %struct.Edge], ptr @e, i64 0, i64 %77
  %79 = getelementptr inbounds %struct.Edge, ptr %78, i32 0, i32 0
  %80 = load i32, ptr %79, align 16, !tbaa !13
  store i32 %80, ptr %4, align 4, !tbaa !5
  br label %30, !llvm.loop !14

81:                                               ; preds = %33
  br label %16, !llvm.loop !16

82:                                               ; preds = %16
  %83 = load i32, ptr @T, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [201 x i32], ptr @lev, i64 0, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = icmp ne i32 %86, -1
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  ret i1 %87
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z3sgne(x86_fp80 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { inlinehint 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 #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 = !{!10, !11, i64 16}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !11, i64 16}
!11 = !{!"long double", !7, i64 0}
!12 = !{!10, !6, i64 4}
!13 = !{!10, !6, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

@N = external dso_local local_unnamed_addr global i32, align 4
@S = external dso_local local_unnamed_addr global i32, align 4
@T = external dso_local local_unnamed_addr global i32, align 4
@lev = external dso_local local_unnamed_addr global [201 x i32], align 16
@lnk = external dso_local local_unnamed_addr global [201 x i32], align 16
@e = external dso_local local_unnamed_addr global [161605 x %struct.Edge], align 16
@_ZZ3bfsvE3que = external hidden local_unnamed_addr global [201 x i32], align 16

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3bfsv() local_unnamed_addr #1 {
  %1 = load i32, ptr @N, align 4, !tbaa !5
  %2 = sext i32 %1 to i64
  %3 = shl nsw i64 %2, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @lev, i8 -1, i64 %3, i1 false)
  %4 = load i32, ptr @S, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [201 x i32], ptr @lev, i64 0, i64 %5
  store i32 0, ptr %6, align 4, !tbaa !5
  store i32 %4, ptr @_ZZ3bfsvE3que, align 16, !tbaa !5
  br label %9

.loopexit:                                        ; preds = %35, %9
  %.1.lcssa = phi i32 [ %.01419, %9 ], [ %.2, %35 ]
  %7 = sext i32 %.1.lcssa to i64
  %8 = icmp slt i64 %indvars.iv.next, %7
  br i1 %8, label %9, label %36, !llvm.loop !9

9:                                                ; preds = %0, %.loopexit
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %.loopexit ]
  %.01419 = phi i32 [ 1, %0 ], [ %.1.lcssa, %.loopexit ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = getelementptr inbounds [201 x i32], ptr @_ZZ3bfsvE3que, i64 0, i64 %indvars.iv
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [201 x i32], ptr @lnk, i64 0, i64 %12
  %.015 = load i32, ptr %13, align 4, !tbaa !5
  %.not16 = icmp eq i32 %.015, -1
  br i1 %.not16, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %9
  %14 = getelementptr inbounds [201 x i32], ptr @lev, i64 0, i64 %12
  br label %15

15:                                               ; preds = %.lr.ph, %35
  %.018 = phi i32 [ %.015, %.lr.ph ], [ %.0, %35 ]
  %.117 = phi i32 [ %.01419, %.lr.ph ], [ %.2, %35 ]
  %16 = sext i32 %.018 to i64
  %17 = getelementptr inbounds [161605 x %struct.Edge], ptr @e, i64 0, i64 %16
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %19 = load x86_fp80, ptr %18, align 16, !tbaa !11
  %20 = tail call noundef i32 @_Z3sgne(x86_fp80 noundef %19)
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %22, label %35

22:                                               ; preds = %15
  %23 = getelementptr inbounds i8, ptr %17, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !14
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [201 x i32], ptr @lev, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = icmp eq i32 %27, -1
  br i1 %28, label %29, label %35

29:                                               ; preds = %22
  %30 = load i32, ptr %14, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %26, align 4, !tbaa !5
  %32 = add nsw i32 %.117, 1
  %33 = sext i32 %.117 to i64
  %34 = getelementptr inbounds [201 x i32], ptr @_ZZ3bfsvE3que, i64 0, i64 %33
  store i32 %24, ptr %34, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %15, %22, %29
  %.2 = phi i32 [ %32, %29 ], [ %.117, %22 ], [ %.117, %15 ]
  %.0 = load i32, ptr %17, align 16, !tbaa !5
  %.not = icmp eq i32 %.0, -1
  br i1 %.not, label %.loopexit, label %15, !llvm.loop !15

36:                                               ; preds = %.loopexit
  %37 = load i32, ptr @T, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [201 x i32], ptr @lev, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = icmp ne i32 %40, -1
  ret i1 %41
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z3sgne(x86_fp80 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 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, !13, i64 16}
!12 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !13, i64 16}
!13 = !{!"long double", !7, i64 0}
!14 = !{!12, !6, i64 4}
!15 = distinct !{!15, !10}


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