; LLVM IR from tangjz/acm-icpc :: lydsy/2595.ll (Z3dfsii)

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

@ctr = external dso_local global i32, align 4
@s = external dso_local global [101 x i32], align 16
@g = external dso_local global [1025 x [101 x i32]], align 16
@used = external dso_local global [101 x i8], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [101 x i8], ptr @used, i64 0, i64 %8
  store i8 1, ptr %9, align 1, !tbaa !9
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [1025 x [101 x i32]], ptr @g, i64 0, i64 %11
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [101 x i32], ptr %12, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = icmp eq i32 %16, -1
  br i1 %17, label %18, label %19

18:                                               ; preds = %2
  br label %64

19:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [1025 x [101 x i32]], ptr @g, i64 0, i64 %21
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [101 x i32], ptr %22, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = load i32, ptr @ctr, align 4, !tbaa !5
  %28 = ashr i32 %26, %27
  store i32 %28, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1025 x [101 x i32]], ptr @g, i64 0, i64 %30
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [101 x i32], ptr %31, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = load i32, ptr @ctr, align 4, !tbaa !5
  %37 = shl i32 1, %36
  %38 = sub nsw i32 %37, 1
  %39 = and i32 %35, %38
  store i32 %39, ptr %6, align 4, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = icmp eq i32 %40, %41
  br i1 %42, label %43, label %60

43:                                               ; preds = %19
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [101 x i32], ptr @s, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = or i32 %44, %48
  %50 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %49, i32 noundef %50)
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = xor i32 %51, %52
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [101 x i32], ptr @s, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = or i32 %53, %57
  %59 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %58, i32 noundef %59)
  br label %63

60:                                               ; preds = %19
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %61, i32 noundef %62)
  br label %63

63:                                               ; preds = %60, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %64

64:                                               ; preds = %63, %18
  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: 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 = { 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}


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

@ctr = external dso_local local_unnamed_addr global i32, align 4
@s = external dso_local local_unnamed_addr global [101 x i32], align 16
@g = external dso_local local_unnamed_addr global [1025 x [101 x i32]], align 16
@used = external dso_local local_unnamed_addr global [101 x i8], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %1 to i64
  %4 = getelementptr inbounds [101 x i8], ptr @used, i64 0, i64 %3
  store i8 1, ptr %4, align 1, !tbaa !5
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [1025 x [101 x i32]], ptr @g, i64 0, i64 %5, i64 %3
  %7 = load i32, ptr %6, align 4, !tbaa !9
  %8 = icmp eq i32 %7, -1
  br i1 %8, label %tailrecurse._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %.pre22 = load i32, ptr @ctr, align 4, !tbaa !9
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %tailrecurse.backedge
  %9 = phi i32 [ %23, %tailrecurse.backedge ], [ %.pre22, %.lr.ph.preheader ]
  %10 = phi i32 [ %28, %tailrecurse.backedge ], [ %7, %.lr.ph.preheader ]
  %.tr1921 = phi i32 [ %11, %tailrecurse.backedge ], [ %1, %.lr.ph.preheader ]
  %.tr20 = phi i32 [ %.tr.be, %tailrecurse.backedge ], [ %0, %.lr.ph.preheader ]
  %11 = ashr i32 %10, %9
  %notmask = shl nsw i32 -1, %9
  %12 = xor i32 %notmask, -1
  %13 = and i32 %10, %12
  %14 = icmp eq i32 %11, %.tr1921
  br i1 %14, label %15, label %tailrecurse.backedge

15:                                               ; preds = %.lr.ph
  %16 = sext i32 %.tr1921 to i64
  %17 = getelementptr inbounds [101 x i32], ptr @s, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = or i32 %18, %13
  tail call void @_Z3dfsii(i32 noundef %19, i32 noundef %.tr1921)
  %20 = xor i32 %13, %.tr20
  %21 = load i32, ptr %17, align 4, !tbaa !9
  %22 = or i32 %21, %20
  %.pre = load i32, ptr @ctr, align 4, !tbaa !9
  br label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %15, %.lr.ph
  %23 = phi i32 [ %.pre, %15 ], [ %9, %.lr.ph ]
  %.tr.be = phi i32 [ %22, %15 ], [ %13, %.lr.ph ]
  %24 = sext i32 %11 to i64
  %25 = getelementptr inbounds [101 x i8], ptr @used, i64 0, i64 %24
  store i8 1, ptr %25, align 1, !tbaa !5
  %26 = sext i32 %.tr.be to i64
  %27 = getelementptr inbounds [1025 x [101 x i32]], ptr @g, i64 0, i64 %26, i64 %24
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = icmp eq i32 %28, -1
  br i1 %29, label %tailrecurse._crit_edge, label %.lr.ph

tailrecurse._crit_edge:                           ; preds = %tailrecurse.backedge, %2
  ret void
}

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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


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