; LLVM IR from tangjz/acm-icpc :: hdu/6039.ll (Z3dfsiii)

; 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 }
%struct.Segment = type { i32, i32 }

@a = external dso_local global [100001 x i32], align 16
@tot = external dso_local global i32, align 4
@lnk = external dso_local global [100001 x i32], align 16
@lst = external dso_local global [100001 x i32], align 16
@rt = external dso_local global i32, align 4
@idx = external dso_local global [100001 x i32], align 16
@in = external dso_local global [100001 x i32], align 16
@out = external dso_local global [100001 x i32], align 16
@pL = external dso_local global [100001 x i32], align 16
@pR = external dso_local global [100001 x i32], align 16
@qL = external dso_local global [100001 x i32], align 16
@qR = external dso_local global [100001 x i32], align 16
@e = external dso_local global [200003 x %struct.Edge], align 16
@g = external dso_local global [200003 x %struct.Edge], align 16
@seg = external dso_local global [200003 x %struct.Segment], 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7seg_idxii(i32 noundef, i32 noundef) #1

; 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 @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %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
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %13 = load i32, ptr @rt, align 4, !tbaa !5
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100001 x i32], ptr @idx, i64 0, i64 %15
  store i32 %13, ptr %16, align 4, !tbaa !5
  %17 = load i32, ptr @tot, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr @tot, align 4, !tbaa !5
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [100001 x i32], ptr @in, i64 0, i64 %20
  store i32 %18, ptr %21, align 4, !tbaa !5
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = load i32, ptr @tot, align 4, !tbaa !5
  %24 = load i32, ptr @tot, align 4, !tbaa !5
  %25 = call noundef i32 @_Z7seg_idxii(i32 noundef %23, i32 noundef %24)
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %26
  %28 = getelementptr inbounds %struct.Segment, ptr %27, i32 0, i32 0
  store i32 %22, ptr %28, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100001 x i32], ptr @lst, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  store i32 %32, ptr %7, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %105, %3
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = icmp ne i32 %34, -1
  br i1 %35, label %37, label %36

36:                                               ; preds = %33
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %111

37:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [200003 x %struct.Edge], ptr @g, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.Edge, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !11
  store i32 %42, ptr %9, align 4, !tbaa !5
  %43 = load i32, ptr @tot, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  %45 = load i32, ptr %9, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [100001 x i32], ptr @pL, i64 0, i64 %46
  store i32 %44, ptr %47, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %48 = load i32, ptr %9, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [100001 x i32], ptr @lnk, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  store i32 %51, ptr %10, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %94, %37
  %53 = load i32, ptr %10, align 4, !tbaa !5
  %54 = icmp ne i32 %53, -1
  br i1 %54, label %56, label %55

55:                                               ; preds = %52
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %100

56:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %57 = load i32, ptr %10, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %58
  %60 = getelementptr inbounds %struct.Edge, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %60, align 4, !tbaa !11
  store i32 %61, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %62 = load i32, ptr %11, align 4, !tbaa !5
  %63 = call noundef i32 @_Z8dsu_findi(i32 noundef %62)
  store i32 %63, ptr %12, align 4, !tbaa !5
  %64 = load i32, ptr %12, align 4, !tbaa !5
  %65 = load i32, ptr %5, align 4, !tbaa !5
  %66 = icmp eq i32 %64, %65
  br i1 %66, label %67, label %68

67:                                               ; preds = %56
  store i32 7, ptr %8, align 4
  br label %91

68:                                               ; preds = %56
  %69 = load i32, ptr @tot, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  %71 = load i32, ptr %11, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [100001 x i32], ptr @qL, i64 0, i64 %72
  store i32 %70, ptr %73, align 4, !tbaa !5
  %74 = load i32, ptr %12, align 4, !tbaa !5
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = load i32, ptr %6, align 4, !tbaa !5
  %77 = load i32, ptr %9, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = add nsw i32 %76, %80
  %82 = load i32, ptr %11, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = sub nsw i32 %81, %85
  call void @_Z3dfsiii(i32 noundef %74, i32 noundef %75, i32 noundef %86)
  %87 = load i32, ptr @tot, align 4, !tbaa !5
  %88 = load i32, ptr %11, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [100001 x i32], ptr @qR, i64 0, i64 %89
  store i32 %87, ptr %90, align 4, !tbaa !5
  store i32 0, ptr %8, align 4
  br label %91

91:                                               ; preds = %68, %67
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  %92 = load i32, ptr %8, align 4
  switch i32 %92, label %116 [
    i32 0, label %93
    i32 7, label %94
  ]

93:                                               ; preds = %91
  br label %94

94:                                               ; preds = %93, %91
  %95 = load i32, ptr %10, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %96
  %98 = getelementptr inbounds %struct.Edge, ptr %97, i32 0, i32 0
  %99 = load i32, ptr %98, align 8, !tbaa !13
  store i32 %99, ptr %10, align 4, !tbaa !5
  br label %52, !llvm.loop !14

100:                                              ; preds = %55
  %101 = load i32, ptr @tot, align 4, !tbaa !5
  %102 = load i32, ptr %9, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [100001 x i32], ptr @pR, i64 0, i64 %103
  store i32 %101, ptr %104, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %105

105:                                              ; preds = %100
  %106 = load i32, ptr %7, align 4, !tbaa !5
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds [200003 x %struct.Edge], ptr @g, i64 0, i64 %107
  %109 = getelementptr inbounds %struct.Edge, ptr %108, i32 0, i32 0
  %110 = load i32, ptr %109, align 8, !tbaa !13
  store i32 %110, ptr %7, align 4, !tbaa !5
  br label %33, !llvm.loop !16

111:                                              ; preds = %36
  %112 = load i32, ptr @tot, align 4, !tbaa !5
  %113 = load i32, ptr %4, align 4, !tbaa !5
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds [100001 x i32], ptr @out, i64 0, i64 %114
  store i32 %112, ptr %115, align 4, !tbaa !5
  ret void

116:                                              ; preds = %91
  unreachable
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !6, i64 0}
!10 = !{!"_ZTS7Segment", !6, i64 0, !6, i64 4}
!11 = !{!12, !6, i64 4}
!12 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!13 = !{!12, !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 }
%struct.Segment = type { i32, i32 }

@a = external dso_local local_unnamed_addr global [100001 x i32], align 16
@tot = external dso_local local_unnamed_addr global i32, align 4
@lnk = external dso_local local_unnamed_addr global [100001 x i32], align 16
@lst = external dso_local local_unnamed_addr global [100001 x i32], align 16
@rt = external dso_local local_unnamed_addr global i32, align 4
@idx = external dso_local local_unnamed_addr global [100001 x i32], align 16
@in = external dso_local local_unnamed_addr global [100001 x i32], align 16
@out = external dso_local local_unnamed_addr global [100001 x i32], align 16
@pL = external dso_local local_unnamed_addr global [100001 x i32], align 16
@pR = external dso_local local_unnamed_addr global [100001 x i32], align 16
@qL = external dso_local local_unnamed_addr global [100001 x i32], align 16
@qR = 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
@g = external dso_local local_unnamed_addr global [200003 x %struct.Edge], align 16
@seg = external dso_local local_unnamed_addr global [200003 x %struct.Segment], align 16

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7seg_idxii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = load i32, ptr @rt, align 4, !tbaa !5
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [100001 x i32], ptr @idx, i64 0, i64 %5
  store i32 %4, ptr %6, align 4, !tbaa !5
  %7 = load i32, ptr @tot, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr @tot, align 4, !tbaa !5
  %9 = getelementptr inbounds [100001 x i32], ptr @in, i64 0, i64 %5
  store i32 %8, ptr %9, align 4, !tbaa !5
  %10 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %8, i32 noundef %8)
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [200003 x %struct.Segment], ptr @seg, i64 0, i64 %11
  store i32 %2, ptr %12, align 8, !tbaa !9
  %13 = getelementptr inbounds [100001 x i32], ptr @lst, i64 0, i64 %5
  %.030 = load i32, ptr %13, align 4, !tbaa !5
  %.not31 = icmp eq i32 %.030, -1
  %.pre37 = load i32, ptr @tot, align 4, !tbaa !5
  br i1 %.not31, label %._crit_edge35, label %.lr.ph34

._crit_edge35:                                    ; preds = %._crit_edge, %3
  %14 = phi i32 [ %.pre37, %3 ], [ %26, %._crit_edge ]
  %15 = getelementptr inbounds [100001 x i32], ptr @out, i64 0, i64 %5
  store i32 %14, ptr %15, align 4, !tbaa !5
  ret void

.lr.ph34:                                         ; preds = %3, %._crit_edge
  %16 = phi i32 [ %26, %._crit_edge ], [ %.pre37, %3 ]
  %.032 = phi i32 [ %.0, %._crit_edge ], [ %.030, %3 ]
  %17 = sext i32 %.032 to i64
  %18 = getelementptr inbounds [200003 x %struct.Edge], ptr @g, i64 0, i64 %17
  %19 = getelementptr inbounds i8, ptr %18, i64 4
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = add nsw i32 %16, 1
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds [100001 x i32], ptr @pL, i64 0, i64 %22
  store i32 %21, ptr %23, align 4, !tbaa !5
  %24 = getelementptr inbounds [100001 x i32], ptr @lnk, i64 0, i64 %22
  %.02427 = load i32, ptr %24, align 4, !tbaa !5
  %.not2628 = icmp eq i32 %.02427, -1
  br i1 %.not2628, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph34
  %25 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %22
  br label %28

._crit_edge.loopexit:                             ; preds = %47
  %.pre36 = load i32, ptr @tot, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph34
  %26 = phi i32 [ %.pre36, %._crit_edge.loopexit ], [ %16, %.lr.ph34 ]
  %27 = getelementptr inbounds [100001 x i32], ptr @pR, i64 0, i64 %22
  store i32 %26, ptr %27, align 4, !tbaa !5
  %.0 = load i32, ptr %18, align 8, !tbaa !5
  %.not = icmp eq i32 %.0, -1
  br i1 %.not, label %._crit_edge35, label %.lr.ph34, !llvm.loop !13

28:                                               ; preds = %.lr.ph, %47
  %.02429 = phi i32 [ %.02427, %.lr.ph ], [ %.024, %47 ]
  %29 = sext i32 %.02429 to i64
  %30 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %29
  %31 = getelementptr inbounds i8, ptr %30, i64 4
  %32 = load i32, ptr %31, align 4, !tbaa !11
  %33 = tail call noundef i32 @_Z8dsu_findi(i32 noundef %32)
  %34 = icmp eq i32 %33, %1
  br i1 %34, label %47, label %35

35:                                               ; preds = %28
  %36 = load i32, ptr @tot, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  %38 = sext i32 %32 to i64
  %39 = getelementptr inbounds [100001 x i32], ptr @qL, i64 0, i64 %38
  store i32 %37, ptr %39, align 4, !tbaa !5
  %40 = load i32, ptr %25, align 4, !tbaa !5
  %41 = add nsw i32 %40, %2
  %42 = getelementptr inbounds [100001 x i32], ptr @a, i64 0, i64 %38
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sub i32 %41, %43
  tail call void @_Z3dfsiii(i32 noundef %33, i32 noundef %0, i32 noundef %44)
  %45 = load i32, ptr @tot, align 4, !tbaa !5
  %46 = getelementptr inbounds [100001 x i32], ptr @qR, i64 0, i64 %38
  store i32 %45, ptr %46, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %28, %35
  %.024 = load i32, ptr %30, align 8, !tbaa !5
  %.not26 = icmp eq i32 %.024, -1
  br i1 %.not26, label %._crit_edge.loopexit, label %28, !llvm.loop !15
}

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

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


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