; LLVM IR from upupming/algorithm :: leetcode/contest-247/1916. Count Ways to Build Rooms in an Ant Colony.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"

@head = external dso_local global [100010 x i32], align 16
@ver = external dso_local global [100010 x i32], align 16
@Next = external dso_local global [100010 x i32], align 16
@f = external dso_local global [100010 x i32], align 16
@g = external dso_local global [100010 x i32], align 16
@s = external dso_local global [100010 x i32], align 16
@sz = external dso_local global [100010 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 uwtable
define dso_local noundef i32 @_Z3dfsi(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
  store i32 %0, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [100010 x i32], ptr @sz, i64 0, i64 %8
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %13, ptr %3, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %34, %1
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [100010 x i32], ptr @ver, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  store i32 %22, ptr %4, align 4, !tbaa !5
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = call noundef i32 @_Z3dfsi(i32 noundef %23)
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [100010 x i32], ptr @sz, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100010 x i32], ptr @sz, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = add nsw i32 %32, %28
  store i32 %33, ptr %31, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %34

34:                                               ; preds = %18
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100010 x i32], ptr @Next, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  store i32 %38, ptr %3, align 4, !tbaa !5
  br label %14, !llvm.loop !9

39:                                               ; preds = %17
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100010 x i32], ptr @sz, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [100010 x i32], ptr @f, i64 0, i64 %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 [100010 x i32], ptr @s, i64 0, i64 %48
  store i32 %46, ptr %49, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  store i32 %53, ptr %5, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %89, %39
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %58, label %57

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

58:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [100010 x i32], ptr @ver, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  store i32 %62, ptr %6, align 4, !tbaa !5
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [100010 x i32], ptr @s, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [100010 x i32], ptr @sz, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [100010 x i32], ptr @g, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = mul nsw i64 %67, %75
  %77 = srem i64 %76, 1000000007
  %78 = load i32, ptr %6, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [100010 x i32], ptr @s, i64 0, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = mul nsw i64 %77, %82
  %84 = srem i64 %83, 1000000007
  %85 = trunc i64 %84 to i32
  %86 = load i32, ptr %2, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [100010 x i32], ptr @s, i64 0, i64 %87
  store i32 %85, ptr %88, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %89

89:                                               ; preds = %58
  %90 = load i32, ptr %5, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [100010 x i32], ptr @Next, i64 0, i64 %91
  %93 = load i32, ptr %92, align 4, !tbaa !5
  store i32 %93, ptr %5, align 4, !tbaa !5
  br label %54, !llvm.loop !11

94:                                               ; preds = %57
  %95 = load i32, ptr %2, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [100010 x i32], ptr @sz, i64 0, i64 %96
  %98 = load i32, ptr %97, align 4, !tbaa !5
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %97, align 4, !tbaa !5
  %100 = load i32, ptr %2, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [100010 x i32], ptr @s, i64 0, i64 %101
  %103 = load i32, ptr %102, align 4, !tbaa !5
  ret i32 %103
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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

@head = external dso_local local_unnamed_addr global [100010 x i32], align 16
@ver = external dso_local local_unnamed_addr global [100010 x i32], align 16
@Next = external dso_local local_unnamed_addr global [100010 x i32], align 16
@f = external dso_local local_unnamed_addr global [100010 x i32], align 16
@g = external dso_local local_unnamed_addr global [100010 x i32], align 16
@s = external dso_local local_unnamed_addr global [100010 x i32], align 16
@sz = external dso_local local_unnamed_addr global [100010 x i32], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z3dfsi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [100010 x i32], ptr @sz, i64 0, i64 %2
  store i32 0, ptr %3, align 4, !tbaa !5
  %4 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %2
  %.022 = load i32, ptr %4, align 4, !tbaa !5
  %.not23 = icmp eq i32 %.022, 0
  br i1 %.not23, label %._crit_edge.thread, label %.lr.ph

._crit_edge.thread:                               ; preds = %1
  %5 = load i32, ptr @f, align 16, !tbaa !5
  %6 = getelementptr inbounds [100010 x i32], ptr @s, i64 0, i64 %2
  store i32 %5, ptr %6, align 4, !tbaa !5
  br label %._crit_edge30

._crit_edge:                                      ; preds = %.lr.ph
  %.02025.pre = load i32, ptr %4, align 4, !tbaa !5
  %7 = sext i32 %19 to i64
  %8 = getelementptr inbounds [100010 x i32], ptr @f, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = getelementptr inbounds [100010 x i32], ptr @s, i64 0, i64 %2
  store i32 %9, ptr %10, align 4, !tbaa !5
  %.not2126 = icmp eq i32 %.02025.pre, 0
  br i1 %.not2126, label %._crit_edge30, label %.lr.ph29

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.024 = phi i32 [ %.0, %.lr.ph ], [ %.022, %1 ]
  %11 = sext i32 %.024 to i64
  %12 = getelementptr inbounds [100010 x i32], ptr @ver, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = tail call noundef i32 @_Z3dfsi(i32 noundef %13)
  %15 = sext i32 %13 to i64
  %16 = getelementptr inbounds [100010 x i32], ptr @sz, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = add nsw i32 %18, %17
  store i32 %19, ptr %3, align 4, !tbaa !5
  %20 = getelementptr inbounds [100010 x i32], ptr @Next, i64 0, i64 %11
  %.0 = load i32, ptr %20, align 4, !tbaa !5
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge30:                                    ; preds = %.lr.ph29, %._crit_edge.thread, %._crit_edge
  %21 = phi i32 [ %19, %._crit_edge ], [ 0, %._crit_edge.thread ], [ %19, %.lr.ph29 ]
  %22 = phi i32 [ %9, %._crit_edge ], [ %5, %._crit_edge.thread ], [ %43, %.lr.ph29 ]
  %23 = add nsw i32 %21, 1
  store i32 %23, ptr %3, align 4, !tbaa !5
  ret i32 %22

.lr.ph29:                                         ; preds = %._crit_edge, %.lr.ph29
  %24 = phi i32 [ %43, %.lr.ph29 ], [ %9, %._crit_edge ]
  %.02027 = phi i32 [ %.020, %.lr.ph29 ], [ %.02025.pre, %._crit_edge ]
  %25 = sext i32 %.02027 to i64
  %26 = getelementptr inbounds [100010 x i32], ptr @ver, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = sext i32 %24 to i64
  %29 = sext i32 %27 to i64
  %30 = getelementptr inbounds [100010 x i32], ptr @sz, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [100010 x i32], ptr @g, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = mul nsw i64 %35, %28
  %37 = srem i64 %36, 1000000007
  %38 = getelementptr inbounds [100010 x i32], ptr @s, i64 0, i64 %29
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = mul nsw i64 %37, %40
  %42 = srem i64 %41, 1000000007
  %43 = trunc nsw i64 %42 to i32
  store i32 %43, ptr %10, align 4, !tbaa !5
  %44 = getelementptr inbounds [100010 x i32], ptr @Next, i64 0, i64 %25
  %.020 = load i32, ptr %44, align 4, !tbaa !5
  %.not21 = icmp eq i32 %.020, 0
  br i1 %.not21, label %._crit_edge30, label %.lr.ph29, !llvm.loop !11
}

attributes #0 = { mustprogress nofree 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 = distinct !{!11, !10}


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