; LLVM IR from tangjz/acm-icpc :: TDL_training/2015-11-02/D - Polynomial-time Reductions - lzy.ll (Z3dfsi)

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

@lnk = external dso_local global [109 x ptr], align 16
@tm = external dso_local global i32, align 4
@cnt = external dso_local global i32, align 4
@dn = external dso_local global [109 x i32], align 16
@lw = external dso_local global [109 x i32], align 16
@rt = external dso_local global [109 x i32], align 16
@z = external dso_local global [109 x i32], align 16
@in = external dso_local global [109 x i8], align 16
@t = external dso_local global i32, align 4
@s = external dso_local global [109 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr @tm, align 4, !tbaa !5
  %6 = add nsw i32 %5, 1
  store i32 %6, ptr @tm, align 4, !tbaa !5
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [109 x i32], ptr @lw, i64 0, i64 %8
  store i32 %6, ptr %9, align 4, !tbaa !5
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [109 x i32], ptr @dn, i64 0, i64 %11
  store i32 %6, ptr %12, align 4, !tbaa !5
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [109 x i8], ptr @in, i64 0, i64 %14
  store i8 1, ptr %15, align 1, !tbaa !9
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = load i32, ptr @t, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr @t, align 4, !tbaa !5
  %19 = sext i32 %17 to i64
  %20 = getelementptr inbounds [109 x i32], ptr @s, i64 0, i64 %19
  store i32 %16, ptr %20, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [109 x ptr], ptr @lnk, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  store ptr %24, ptr %4, align 8, !tbaa !11
  br label %25

25:                                               ; preds = %70, %1
  %26 = load ptr, ptr %4, align 8, !tbaa !11
  %27 = icmp ne ptr %26, null
  br i1 %27, label %29, label %28

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

29:                                               ; preds = %25
  %30 = load ptr, ptr %4, align 8, !tbaa !11
  %31 = getelementptr inbounds %struct.Edge, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !13
  store i32 %32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [109 x i32], ptr @dn, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %50, label %37

37:                                               ; preds = %29
  %38 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z3dfsi(i32 noundef %38)
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [109 x i32], ptr @lw, i64 0, i64 %40
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [109 x i32], ptr @lw, i64 0, i64 %43
  %45 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %41, ptr noundef nonnull align 4 dereferenceable(4) %44)
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [109 x i32], ptr @lw, i64 0, i64 %48
  store i32 %46, ptr %49, align 4, !tbaa !5
  br label %69

50:                                               ; preds = %29
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [109 x i8], ptr @in, i64 0, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !9, !range !15, !noundef !16
  %55 = trunc i8 %54 to i1
  br i1 %55, label %56, label %68

56:                                               ; preds = %50
  %57 = load i32, ptr %2, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [109 x i32], ptr @lw, i64 0, i64 %58
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [109 x i32], ptr @dn, i64 0, i64 %61
  %63 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %59, ptr noundef nonnull align 4 dereferenceable(4) %62)
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = load i32, ptr %2, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [109 x i32], ptr @lw, i64 0, i64 %66
  store i32 %64, ptr %67, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %56, %50
  br label %69

69:                                               ; preds = %68, %37
  br label %70

70:                                               ; preds = %69
  %71 = load ptr, ptr %4, align 8, !tbaa !11
  %72 = getelementptr inbounds %struct.Edge, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !17
  store ptr %73, ptr %4, align 8, !tbaa !11
  br label %25, !llvm.loop !18

74:                                               ; preds = %28
  %75 = load i32, ptr %2, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [109 x i32], ptr @dn, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = load i32, ptr %2, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [109 x i32], ptr @lw, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = icmp eq i32 %78, %82
  br i1 %83, label %84, label %112

84:                                               ; preds = %74
  %85 = load i32, ptr @cnt, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr @cnt, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [109 x i32], ptr @z, i64 0, i64 %87
  store i32 0, ptr %88, align 4, !tbaa !5
  br label %89

89:                                               ; preds = %107, %84
  %90 = load i32, ptr @t, align 4, !tbaa !5
  %91 = add nsw i32 %90, -1
  store i32 %91, ptr @t, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [109 x i32], ptr @s, i64 0, i64 %92
  %94 = load i32, ptr %93, align 4, !tbaa !5
  store i32 %94, ptr %3, align 4, !tbaa !5
  %95 = load i32, ptr @cnt, align 4, !tbaa !5
  %96 = load i32, ptr %3, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [109 x i32], ptr @rt, i64 0, i64 %97
  store i32 %95, ptr %98, align 4, !tbaa !5
  %99 = load i32, ptr @cnt, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [109 x i32], ptr @z, i64 0, i64 %100
  %102 = load i32, ptr %101, align 4, !tbaa !5
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr %101, align 4, !tbaa !5
  %104 = load i32, ptr %3, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [109 x i8], ptr @in, i64 0, i64 %105
  store i8 0, ptr %106, align 1, !tbaa !9
  br label %107

107:                                              ; preds = %89
  %108 = load i32, ptr %2, align 4, !tbaa !5
  %109 = load i32, ptr %3, align 4, !tbaa !5
  %110 = icmp ne i32 %108, %109
  br i1 %110, label %89, label %111, !llvm.loop !20

111:                                              ; preds = %107
  br label %112

112:                                              ; preds = %111, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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


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

@lnk = external dso_local local_unnamed_addr global [109 x ptr], align 16
@tm = external dso_local local_unnamed_addr global i32, align 4
@cnt = external dso_local local_unnamed_addr global i32, align 4
@dn = external dso_local global [109 x i32], align 16
@lw = external dso_local global [109 x i32], align 16
@rt = external dso_local local_unnamed_addr global [109 x i32], align 16
@z = external dso_local local_unnamed_addr global [109 x i32], align 16
@in = external dso_local local_unnamed_addr global [109 x i8], align 16
@t = external dso_local local_unnamed_addr global i32, align 4
@s = external dso_local local_unnamed_addr global [109 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @tm, align 4, !tbaa !5
  %3 = add nsw i32 %2, 1
  store i32 %3, ptr @tm, align 4, !tbaa !5
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [109 x i32], ptr @lw, i64 0, i64 %4
  store i32 %3, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds [109 x i32], ptr @dn, i64 0, i64 %4
  store i32 %3, ptr %6, align 4, !tbaa !5
  %7 = getelementptr inbounds [109 x i8], ptr @in, i64 0, i64 %4
  store i8 1, ptr %7, align 1, !tbaa !9
  %8 = load i32, ptr @t, align 4, !tbaa !5
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr @t, align 4, !tbaa !5
  %10 = sext i32 %8 to i64
  %11 = getelementptr inbounds [109 x i32], ptr @s, i64 0, i64 %10
  store i32 %0, ptr %11, align 4, !tbaa !5
  %12 = getelementptr inbounds [109 x ptr], ptr @lnk, i64 0, i64 %4
  %.023 = load ptr, ptr %12, align 8, !tbaa !11
  %.not24 = icmp eq ptr %.023, null
  br i1 %.not24, label %._crit_edge.thread, label %.lr.ph

._crit_edge:                                      ; preds = %27
  %.pre = load i32, ptr %6, align 4, !tbaa !5
  %13 = icmp eq i32 %.pre, %28
  br i1 %13, label %._crit_edge.thread, label %44

.lr.ph:                                           ; preds = %1, %27
  %14 = phi i32 [ %28, %27 ], [ %3, %1 ]
  %.025 = phi ptr [ %.0, %27 ], [ %.023, %1 ]
  %15 = load i32, ptr %.025, align 8, !tbaa !13
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [109 x i32], ptr @dn, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %.not22 = icmp eq i32 %18, 0
  br i1 %.not22, label %19, label %21

19:                                               ; preds = %.lr.ph
  tail call void @_Z3dfsi(i32 noundef %15)
  %20 = getelementptr inbounds [109 x i32], ptr @lw, i64 0, i64 %16
  br label %.sink.split

21:                                               ; preds = %.lr.ph
  %22 = getelementptr inbounds [109 x i8], ptr @in, i64 0, i64 %16
  %23 = load i8, ptr %22, align 1, !tbaa !9, !range !15, !noundef !16
  %24 = trunc nuw i8 %23 to i1
  br i1 %24, label %.sink.split, label %27

.sink.split:                                      ; preds = %21, %19
  %.sink = phi ptr [ %20, %19 ], [ %17, %21 ]
  %25 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %.sink)
  %26 = load i32, ptr %25, align 4, !tbaa !5
  store i32 %26, ptr %5, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %.sink.split, %21
  %28 = phi i32 [ %14, %21 ], [ %26, %.sink.split ]
  %29 = getelementptr inbounds i8, ptr %.025, i64 8
  %.0 = load ptr, ptr %29, align 8, !tbaa !11
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17

._crit_edge.thread:                               ; preds = %1, %._crit_edge
  %30 = load i32, ptr @cnt, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr @cnt, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [109 x i32], ptr @z, i64 0, i64 %32
  %t.promoted = load i32, ptr @t, align 4, !tbaa !5
  %34 = sext i32 %t.promoted to i64
  br label %35

35:                                               ; preds = %35, %._crit_edge.thread
  %indvars.iv = phi i64 [ %indvars.iv.next, %35 ], [ %34, %._crit_edge.thread ]
  %36 = phi i32 [ %41, %35 ], [ 0, %._crit_edge.thread ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %37 = getelementptr inbounds [109 x i32], ptr @s, i64 0, i64 %indvars.iv.next
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [109 x i32], ptr @rt, i64 0, i64 %39
  store i32 %31, ptr %40, align 4, !tbaa !5
  %41 = add nuw nsw i32 %36, 1
  %42 = getelementptr inbounds [109 x i8], ptr @in, i64 0, i64 %39
  store i8 0, ptr %42, align 1, !tbaa !9
  %.not21 = icmp eq i32 %38, %0
  br i1 %.not21, label %.loopexit, label %35, !llvm.loop !19

.loopexit:                                        ; preds = %35
  %43 = trunc nsw i64 %indvars.iv.next to i32
  store i32 %43, ptr @t, align 4, !tbaa !5
  store i32 %41, ptr %33, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %.loopexit, %._crit_edge
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

attributes #0 = { 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 = { 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" }

!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 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS4Edge", !6, i64 0, !12, i64 8}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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