; LLVM IR from tangjz/acm-icpc :: codeforces/complete/1552G.ll (Z3dfsiy)

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

@m = external dso_local global i32, align 4
@adt = external dso_local global [11 x i32], align 16
@msk = external dso_local global [11 x i64], align 16
@nxt = external dso_local global [11 x [41 x i64]], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3dfsiy(i32 noundef %0, i64 noundef %1) #0 {
  %3 = alloca i1, align 1
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = load i32, ptr @m, align 4, !tbaa !5
  %11 = icmp eq i32 %9, %10
  br i1 %11, label %12, label %20

12:                                               ; preds = %2
  %13 = load i64, ptr %5, align 8, !tbaa !9
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = call noundef i32 @_Z8popcounty(i64 noundef %14)
  %16 = zext i32 %15 to i64
  %17 = shl i64 1, %16
  %18 = sub i64 %17, 1
  %19 = icmp eq i64 %13, %18
  store i1 %19, ptr %3, align 1
  br label %67

20:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [11 x i64], ptr @msk, i64 0, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !9
  %26 = and i64 %21, %25
  %27 = call noundef i32 @_Z8popcounty(i64 noundef %26)
  store i32 %27, ptr %6, align 4, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [11 x i64], ptr @msk, i64 0, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !9
  %32 = xor i64 %31, -1
  %33 = load i64, ptr %5, align 8, !tbaa !9
  %34 = and i64 %33, %32
  store i64 %34, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %60, %20
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [11 x i32], ptr @adt, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = icmp sle i32 %36, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %35
  store i32 2, ptr %8, align 4
  br label %63

43:                                               ; preds = %35
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  %46 = load i64, ptr %5, align 8, !tbaa !9
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [11 x [41 x i64]], ptr @nxt, i64 0, i64 %48
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = add nsw i32 %50, %51
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [41 x i64], ptr %49, i64 0, i64 %53
  %55 = load i64, ptr %54, align 8, !tbaa !9
  %56 = or i64 %46, %55
  %57 = call noundef zeroext i1 @_Z3dfsiy(i32 noundef %45, i64 noundef %56)
  br i1 %57, label %59, label %58

58:                                               ; preds = %43
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %63

59:                                               ; preds = %43
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %7, align 4, !tbaa !5
  br label %35, !llvm.loop !11

63:                                               ; preds = %58, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %64 = load i32, ptr %8, align 4
  switch i32 %64, label %66 [
    i32 2, label %65
  ]

65:                                               ; preds = %63
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %66

66:                                               ; preds = %65, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %67

67:                                               ; preds = %66, %12
  %68 = load i1, ptr %3, align 1
  ret i1 %68
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z8popcounty(i64 noundef) #1

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

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

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


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

@m = external dso_local local_unnamed_addr global i32, align 4
@adt = external dso_local local_unnamed_addr global [11 x i32], align 16
@msk = external dso_local local_unnamed_addr global [11 x i64], align 16
@nxt = external dso_local local_unnamed_addr global [11 x [41 x i64]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z3dfsiy(i32 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @m, align 4, !tbaa !5
  %4 = icmp eq i32 %3, %0
  br i1 %4, label %5, label %10

5:                                                ; preds = %2
  %6 = tail call noundef i32 @_Z8popcounty(i64 noundef %1)
  %7 = zext nneg i32 %6 to i64
  %notmask = shl nsw i64 -1, %7
  %8 = xor i64 %notmask, %1
  %9 = icmp eq i64 %8, -1
  br label %.critedge

10:                                               ; preds = %2
  %11 = sext i32 %0 to i64
  %12 = getelementptr inbounds [11 x i64], ptr @msk, i64 0, i64 %11
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = and i64 %13, %1
  %15 = tail call noundef i32 @_Z8popcounty(i64 noundef %14)
  %16 = load i64, ptr %12, align 8, !tbaa !9
  %17 = xor i64 %16, -1
  %18 = and i64 %17, %1
  %19 = getelementptr inbounds [11 x i32], ptr @adt, i64 0, i64 %11
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %.not19 = icmp slt i32 %20, 0
  br i1 %.not19, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %10
  %21 = add nsw i32 %0, 1
  %22 = sext i32 %15 to i64
  br label %26

23:                                               ; preds = %26
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %24 = load i32, ptr %19, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %.not.not = icmp slt i64 %indvars.iv, %25
  br i1 %.not.not, label %26, label %.critedge, !llvm.loop !11

26:                                               ; preds = %.lr.ph, %23
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %23 ]
  %27 = add nsw i64 %indvars.iv, %22
  %28 = getelementptr inbounds [11 x [41 x i64]], ptr @nxt, i64 0, i64 %11, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %30 = or i64 %29, %18
  %31 = tail call noundef zeroext i1 @_Z3dfsiy(i32 noundef %21, i64 noundef %30)
  br i1 %31, label %23, label %.critedge

.critedge:                                        ; preds = %26, %23, %10, %5
  %.2 = phi i1 [ %9, %5 ], [ true, %10 ], [ %31, %23 ], [ %31, %26 ]
  ret i1 %.2
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z8popcounty(i64 noundef) 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 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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