; LLVM IR from tangjz/acm-icpc :: lydsy/4379.ll (Z4findii)

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

@n = external dso_local global i32, align 4
@lnk = external dso_local global [500001 x i32], align 16
@e = external dso_local global [1000002 x %struct.Edge], align 16
@_ZZ4findiiE3que = external hidden global [500001 x i32], align 16
@_ZZ4findiiE3dis = external hidden global [500001 x i32], align 16
@_ZZ4findiiE3pre = external hidden global [500001 x i32], align 16
@_ZZ4findiiE4path = external hidden global ptr, align 8

; 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 nounwind uwtable
define dso_local noundef i32 @_Z4findii(i32 noundef %0, i32 noundef %1) #2 {
  %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
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = mul i64 %10, 4
  call void @llvm.memset.p0.i64(ptr align 4 getelementptr inbounds (i32, ptr @_ZZ4findiiE3dis, i64 1), i8 -1, i64 %11, i1 false)
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3dis, i64 0, i64 %13
  store i32 0, ptr %14, align 4, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3pre, i64 0, i64 %16
  store i32 -1, ptr %17, align 4, !tbaa !5
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %6, align 4, !tbaa !5
  %21 = sext i32 %19 to i64
  %22 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3que, i64 0, i64 %21
  store i32 %18, ptr %22, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %92, %2
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %27, label %95

27:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3que, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  store i32 %31, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [500001 x i32], ptr @lnk, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  store i32 %35, ptr %8, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %85, %27
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = icmp ne i32 %37, -1
  br i1 %38, label %40, label %39

39:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %91

40:                                               ; preds = %36
  %41 = load i32, ptr %8, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1000002 x %struct.Edge], ptr @e, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.Edge, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = icmp ne i32 %45, %46
  br i1 %47, label %48, label %84

48:                                               ; preds = %40
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [1000002 x %struct.Edge], ptr @e, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.Edge, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3dis, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = icmp eq i32 %56, -1
  br i1 %57, label %58, label %84

58:                                               ; preds = %48
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3dis, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  %64 = load i32, ptr %8, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [1000002 x %struct.Edge], ptr @e, i64 0, i64 %65
  %67 = getelementptr inbounds %struct.Edge, ptr %66, i32 0, i32 1
  %68 = load i32, ptr %67, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3dis, i64 0, i64 %69
  store i32 %63, ptr %70, align 4, !tbaa !5
  %71 = load i32, ptr %5, align 4, !tbaa !5
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3pre, i64 0, i64 %73
  store i32 %71, ptr %74, align 4, !tbaa !5
  %75 = load i32, ptr %8, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [1000002 x %struct.Edge], ptr @e, i64 0, i64 %76
  %78 = getelementptr inbounds %struct.Edge, ptr %77, i32 0, i32 1
  %79 = load i32, ptr %78, align 4, !tbaa !9
  %80 = load i32, ptr %6, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %6, align 4, !tbaa !5
  %82 = sext i32 %80 to i64
  %83 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3que, i64 0, i64 %82
  store i32 %79, ptr %83, align 4, !tbaa !5
  br label %84

84:                                               ; preds = %58, %48, %40
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %8, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [1000002 x %struct.Edge], ptr @e, i64 0, i64 %87
  %89 = getelementptr inbounds %struct.Edge, ptr %88, i32 0, i32 0
  %90 = load i32, ptr %89, align 8, !tbaa !11
  store i32 %90, ptr %8, align 4, !tbaa !5
  br label %36, !llvm.loop !12

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

92:                                               ; preds = %91
  %93 = load i32, ptr %5, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %5, align 4, !tbaa !5
  br label %23, !llvm.loop !14

95:                                               ; preds = %23
  store i32 0, ptr %5, align 4, !tbaa !5
  %96 = load i32, ptr %6, align 4, !tbaa !5
  %97 = add nsw i32 %96, -1
  store i32 %97, ptr %6, align 4, !tbaa !5
  br label %98

98:                                               ; preds = %102, %95
  %99 = load i32, ptr %6, align 4, !tbaa !5
  %100 = icmp ne i32 %99, -1
  br i1 %100, label %101, label %116

101:                                              ; preds = %98
  br label %102

102:                                              ; preds = %101
  %103 = load i32, ptr %6, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3que, i64 0, i64 %104
  %106 = load i32, ptr %105, align 4, !tbaa !5
  %107 = load ptr, ptr @_ZZ4findiiE4path, align 8, !tbaa !15
  %108 = load i32, ptr %5, align 4, !tbaa !5
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr %5, align 4, !tbaa !5
  %110 = sext i32 %108 to i64
  %111 = getelementptr inbounds i32, ptr %107, i64 %110
  store i32 %106, ptr %111, align 4, !tbaa !5
  %112 = load i32, ptr %6, align 4, !tbaa !5
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3pre, i64 0, i64 %113
  %115 = load i32, ptr %114, align 4, !tbaa !5
  store i32 %115, ptr %6, align 4, !tbaa !5
  br label %98, !llvm.loop !17

116:                                              ; preds = %98
  %117 = load ptr, ptr @_ZZ4findiiE4path, align 8, !tbaa !15
  %118 = load i32, ptr %5, align 4, !tbaa !5
  %119 = ashr i32 %118, 1
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds i32, ptr %117, i64 %120
  %122 = load i32, ptr %121, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %122
}

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


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

@n = external dso_local local_unnamed_addr global i32, align 4
@lnk = external dso_local local_unnamed_addr global [500001 x i32], align 16
@e = external dso_local local_unnamed_addr global [1000002 x %struct.Edge], align 16
@_ZZ4findiiE3que = external hidden local_unnamed_addr global [500001 x i32], align 16
@_ZZ4findiiE3dis = external hidden local_unnamed_addr global [500001 x i32], align 16
@_ZZ4findiiE3pre = external hidden local_unnamed_addr global [500001 x i32], align 16
@_ZZ4findiiE4path = external hidden local_unnamed_addr global ptr, align 8

; 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 nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z4findii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = shl nsw i64 %4, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 getelementptr inbounds (i8, ptr @_ZZ4findiiE3dis, i64 4), i8 -1, i64 %5, i1 false)
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3dis, i64 0, i64 %6
  store i32 0, ptr %7, align 4, !tbaa !5
  store i32 -1, ptr @_ZZ4findiiE3pre, align 16, !tbaa !5
  store i32 %0, ptr @_ZZ4findiiE3que, align 16, !tbaa !5
  br label %8

8:                                                ; preds = %2, %._crit_edge
  %indvars.iv = phi i64 [ 0, %2 ], [ %indvars.iv.next, %._crit_edge ]
  %.02736 = phi i32 [ 1, %2 ], [ %.128.lcssa, %._crit_edge ]
  %9 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3que, i64 0, i64 %indvars.iv
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [500001 x i32], ptr @lnk, i64 0, i64 %11
  %.032 = load i32, ptr %12, align 4, !tbaa !5
  %.not3033 = icmp eq i32 %.032, -1
  br i1 %.not3033, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8
  %13 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3dis, i64 0, i64 %11
  %14 = trunc nuw nsw i64 %indvars.iv to i32
  br label %17

._crit_edge:                                      ; preds = %34, %8
  %.128.lcssa = phi i32 [ %.02736, %8 ], [ %.2, %34 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = sext i32 %.128.lcssa to i64
  %16 = icmp slt i64 %indvars.iv.next, %15
  br i1 %16, label %8, label %35, !llvm.loop !9

17:                                               ; preds = %.lr.ph, %34
  %.035 = phi i32 [ %.032, %.lr.ph ], [ %.0, %34 ]
  %.12834 = phi i32 [ %.02736, %.lr.ph ], [ %.2, %34 ]
  %18 = sext i32 %.035 to i64
  %19 = getelementptr inbounds [1000002 x %struct.Edge], ptr @e, i64 0, i64 %18
  %20 = getelementptr inbounds i8, ptr %19, i64 4
  %21 = load i32, ptr %20, align 4, !tbaa !11
  %.not31 = icmp eq i32 %21, %1
  br i1 %.not31, label %34, label %22

22:                                               ; preds = %17
  %23 = sext i32 %21 to i64
  %24 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3dis, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = icmp eq i32 %25, -1
  br i1 %26, label %27, label %34

27:                                               ; preds = %22
  %28 = load i32, ptr %13, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %24, align 4, !tbaa !5
  %30 = sext i32 %.12834 to i64
  %31 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3pre, i64 0, i64 %30
  store i32 %14, ptr %31, align 4, !tbaa !5
  %32 = add nsw i32 %.12834, 1
  %33 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3que, i64 0, i64 %30
  store i32 %21, ptr %33, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %17, %22, %27
  %.2 = phi i32 [ %32, %27 ], [ %.12834, %22 ], [ %.12834, %17 ]
  %.0 = load i32, ptr %19, align 8, !tbaa !5
  %.not30 = icmp eq i32 %.0, -1
  br i1 %.not30, label %._crit_edge, label %17, !llvm.loop !13

35:                                               ; preds = %._crit_edge
  %.not38 = icmp eq i32 %.128.lcssa, 0
  %.pre = load ptr, ptr @_ZZ4findiiE4path, align 8, !tbaa !14
  br i1 %.not38, label %._crit_edge43, label %.lr.ph42

.lr.ph42:                                         ; preds = %35
  %36 = add nsw i32 %.128.lcssa, -1
  br label %37

37:                                               ; preds = %.lr.ph42, %37
  %indvars.iv46 = phi i64 [ 0, %.lr.ph42 ], [ %indvars.iv.next47, %37 ]
  %.339 = phi i32 [ %36, %.lr.ph42 ], [ %43, %37 ]
  %38 = sext i32 %.339 to i64
  %39 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3que, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %41 = getelementptr inbounds i32, ptr %.pre, i64 %indvars.iv46
  store i32 %40, ptr %41, align 4, !tbaa !5
  %42 = getelementptr inbounds [500001 x i32], ptr @_ZZ4findiiE3pre, i64 0, i64 %38
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %.not = icmp eq i32 %43, -1
  br i1 %.not, label %._crit_edge43.loopexit, label %37, !llvm.loop !16

._crit_edge43.loopexit:                           ; preds = %37
  %44 = lshr i64 %indvars.iv.next47, 1
  %45 = and i64 %44, 2147483647
  br label %._crit_edge43

._crit_edge43:                                    ; preds = %._crit_edge43.loopexit, %35
  %.1.lcssa = phi i64 [ 0, %35 ], [ %45, %._crit_edge43.loopexit ]
  %46 = getelementptr inbounds i32, ptr %.pre, i64 %.1.lcssa
  %47 = load i32, ptr %46, align 4, !tbaa !5
  ret i32 %47
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, 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 = distinct !{!13, !10}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !7, i64 0}
!16 = distinct !{!16, !10}


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