; LLVM IR from tangjz/acm-icpc :: codeforces/complete/924F.ll (Z3dfsiiix)

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

%"class.std::bitset" = type { %"struct.std::_Base_bitset" }
%"struct.std::_Base_bitset" = type { [2 x i64] }

@pos = external dso_local global [19 x [32175 x i32]], align 16
@bit = external dso_local global [11 x i64], align 16
@f = external dso_local global [191791 x [11 x [9 x i64]]], align 16
@vis = external dso_local global [11 x %"class.std::bitset"], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiiix(i32 noundef %0, i32 noundef %1, i32 noundef %2, i64 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca %"class.std::bitset", align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = icmp eq i32 %14, 10
  br i1 %15, label %16, label %61

16:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = ashr i32 %17, 1
  store i32 %18, ptr %9, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %56, %16
  %20 = load i32, ptr %9, align 4, !tbaa !5
  %21 = icmp sge i32 %20, 0
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  store i32 2, ptr %10, align 4
  br label %59

23:                                               ; preds = %19
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sub nsw i32 %24, 1
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [11 x %"class.std::bitset"], ptr @vis, i64 0, i64 %26
  %28 = load i32, ptr %9, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = call noundef zeroext i1 @_ZNKSt6bitsetILm82EE4testEm(ptr noundef nonnull align 8 dereferenceable(16) %27, i64 noundef %29)
  br i1 %30, label %31, label %55

31:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = load i32, ptr %9, align 4, !tbaa !5
  %34 = sub nsw i32 %32, %33
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = sub nsw i32 %34, %35
  store i32 %36, ptr %11, align 4, !tbaa !5
  %37 = load i32, ptr %11, align 4, !tbaa !5
  %38 = icmp sgt i32 %37, 1
  br i1 %38, label %39, label %54

39:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %40 = load i64, ptr %8, align 8, !tbaa !9
  %41 = call noundef i32 @_Z5getIDx(i64 noundef %40)
  store i32 %41, ptr %12, align 4, !tbaa !5
  %42 = load i32, ptr %12, align 4, !tbaa !5
  %43 = load i32, ptr %12, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [32175 x i32], ptr @pos, i64 0, i64 %44
  store i32 %42, ptr %45, align 4, !tbaa !5
  %46 = load i32, ptr %12, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [191791 x [11 x [9 x i64]]], ptr @f, i64 0, i64 %47
  %49 = getelementptr inbounds [11 x [9 x i64]], ptr %48, i64 0, i64 9
  %50 = load i32, ptr %11, align 4, !tbaa !5
  %51 = sub nsw i32 %50, 1
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [9 x i64], ptr %49, i64 0, i64 %52
  store i64 1, ptr %53, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %54

54:                                               ; preds = %39, %31
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %59

55:                                               ; preds = %23
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %9, align 4, !tbaa !5
  %58 = add nsw i32 %57, -1
  store i32 %58, ptr %9, align 4, !tbaa !5
  br label %19, !llvm.loop !11

59:                                               ; preds = %54, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %60

60:                                               ; preds = %59
  br label %107

61:                                               ; preds = %4
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = sub nsw i32 %62, 1
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [11 x %"class.std::bitset"], ptr @vis, i64 0, i64 %64
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [11 x %"class.std::bitset"], ptr @vis, i64 0, i64 %67
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %68, ptr align 16 %65, i64 16, i1 false)
  %69 = load i32, ptr %5, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  %71 = load i32, ptr %6, align 4, !tbaa !5
  %72 = load i32, ptr %7, align 4, !tbaa !5
  %73 = load i64, ptr %8, align 8, !tbaa !9
  call void @_Z3dfsiiix(i32 noundef %70, i32 noundef %71, i32 noundef %72, i64 noundef %73)
  br label %74

74:                                               ; preds = %77, %61
  %75 = load i32, ptr %6, align 4, !tbaa !5
  %76 = icmp slt i32 %75, 18
  br i1 %76, label %77, label %107

77:                                               ; preds = %74
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #5
  %78 = load i32, ptr %5, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [11 x %"class.std::bitset"], ptr @vis, i64 0, i64 %79
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = call { i64, i64 } @_ZNKSt6bitsetILm82EElsEm(ptr noundef nonnull align 8 dereferenceable(16) %80, i64 noundef %82) #5
  %84 = getelementptr inbounds %"class.std::bitset", ptr %13, i32 0, i32 0
  %85 = getelementptr inbounds %"struct.std::_Base_bitset", ptr %84, i32 0, i32 0
  %86 = getelementptr inbounds { i64, i64 }, ptr %85, i32 0, i32 0
  %87 = extractvalue { i64, i64 } %83, 0
  store i64 %87, ptr %86, align 8
  %88 = getelementptr inbounds { i64, i64 }, ptr %85, i32 0, i32 1
  %89 = extractvalue { i64, i64 } %83, 1
  store i64 %89, ptr %88, align 8
  %90 = load i32, ptr %5, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [11 x %"class.std::bitset"], ptr @vis, i64 0, i64 %91
  %93 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm82EEoRERKS0_(ptr noundef nonnull align 8 dereferenceable(16) %92, ptr noundef nonnull align 8 dereferenceable(16) %13) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #5
  %94 = load i32, ptr %5, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  %96 = load i32, ptr %6, align 4, !tbaa !5
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %6, align 4, !tbaa !5
  %98 = load i32, ptr %5, align 4, !tbaa !5
  %99 = load i32, ptr %7, align 4, !tbaa !5
  %100 = add nsw i32 %99, %98
  store i32 %100, ptr %7, align 4, !tbaa !5
  %101 = load i32, ptr %5, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [11 x i64], ptr @bit, i64 0, i64 %102
  %104 = load i64, ptr %103, align 8, !tbaa !9
  %105 = load i64, ptr %8, align 8, !tbaa !9
  %106 = add nsw i64 %105, %104
  store i64 %106, ptr %8, align 8, !tbaa !9
  call void @_Z3dfsiiix(i32 noundef %95, i32 noundef %97, i32 noundef %100, i64 noundef %106)
  br label %74, !llvm.loop !13

107:                                              ; preds = %74, %60
  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: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6bitsetILm82EE4testEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) #0 align 2

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { i64, i64 } @_ZNKSt6bitsetILm82EElsEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) #4 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm82EEoRERKS0_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #4 align 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { 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"}
!13 = distinct !{!13, !12}


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

%"class.std::bitset" = type { %"struct.std::_Base_bitset" }
%"struct.std::_Base_bitset" = type { [2 x i64] }

@pos = external dso_local local_unnamed_addr global [19 x [32175 x i32]], align 16
@bit = external dso_local local_unnamed_addr global [11 x i64], align 16
@f = external dso_local local_unnamed_addr global [191791 x [11 x [9 x i64]]], align 16
@vis = external dso_local global [11 x %"class.std::bitset"], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiiix(i32 noundef %0, i32 noundef %1, i32 noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = alloca %"class.std::bitset", align 8
  %6 = icmp eq i32 %0, 10
  br i1 %6, label %7, label %26

7:                                                ; preds = %4
  %8 = ashr i32 %2, 1
  %9 = icmp sgt i32 %8, -1
  br i1 %9, label %.lr.ph42.preheader, label %.loopexit

.lr.ph42.preheader:                               ; preds = %7
  %10 = zext nneg i32 %8 to i64
  br label %.lr.ph42

.lr.ph42:                                         ; preds = %.lr.ph42.preheader, %24
  %indvars.iv = phi i64 [ %10, %.lr.ph42.preheader ], [ %indvars.iv.next, %24 ]
  %11 = tail call noundef zeroext i1 @_ZNKSt6bitsetILm82EE4testEm(ptr noundef nonnull align 8 dereferenceable(16) getelementptr inbounds (i8, ptr @vis, i64 144), i64 noundef %indvars.iv)
  br i1 %11, label %12, label %24

12:                                               ; preds = %.lr.ph42
  %13 = trunc nuw nsw i64 %indvars.iv to i32
  %14 = shl nuw i32 %13, 1
  %15 = sub i32 %2, %14
  %16 = icmp sgt i32 %15, 1
  br i1 %16, label %17, label %.loopexit

17:                                               ; preds = %12
  %18 = tail call noundef i32 @_Z5getIDx(i64 noundef %3)
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [32175 x i32], ptr @pos, i64 0, i64 %19
  store i32 %18, ptr %20, align 4, !tbaa !5
  %21 = add nsw i32 %15, -1
  %22 = zext nneg i32 %21 to i64
  %23 = getelementptr inbounds [191791 x [11 x [9 x i64]]], ptr @f, i64 0, i64 %19, i64 9, i64 %22
  store i64 1, ptr %23, align 8, !tbaa !9
  br label %.loopexit

24:                                               ; preds = %.lr.ph42
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %25 = icmp sgt i64 %indvars.iv, 0
  br i1 %25, label %.lr.ph42, label %.loopexit, !llvm.loop !11

26:                                               ; preds = %4
  %27 = add nsw i32 %0, -1
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [11 x %"class.std::bitset"], ptr @vis, i64 0, i64 %28
  %30 = sext i32 %0 to i64
  %31 = getelementptr inbounds [11 x %"class.std::bitset"], ptr @vis, i64 0, i64 %30
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %31, ptr noundef nonnull align 16 dereferenceable(16) %29, i64 16, i1 false)
  %32 = add nsw i32 %0, 1
  tail call void @_Z3dfsiiix(i32 noundef %32, i32 noundef %1, i32 noundef %2, i64 noundef %3)
  %33 = icmp slt i32 %1, 18
  br i1 %33, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %26
  %34 = getelementptr inbounds i8, ptr %5, i64 8
  %35 = getelementptr inbounds [11 x i64], ptr @bit, i64 0, i64 %30
  br label %36

36:                                               ; preds = %.lr.ph, %36
  %.040 = phi i32 [ %1, %.lr.ph ], [ %41, %36 ]
  %.03139 = phi i32 [ %2, %.lr.ph ], [ %42, %36 ]
  %.03338 = phi i64 [ %3, %.lr.ph ], [ %44, %36 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #5
  %37 = call { i64, i64 } @_ZNKSt6bitsetILm82EElsEm(ptr noundef nonnull align 8 dereferenceable(16) %31, i64 noundef %30) #5
  %38 = extractvalue { i64, i64 } %37, 0
  store i64 %38, ptr %5, align 8
  %39 = extractvalue { i64, i64 } %37, 1
  store i64 %39, ptr %34, align 8
  %40 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm82EEoRERKS0_(ptr noundef nonnull align 8 dereferenceable(16) %31, ptr noundef nonnull align 8 dereferenceable(16) %5) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #5
  %41 = add i32 %.040, 1
  %42 = add nsw i32 %.03139, %0
  %43 = load i64, ptr %35, align 8, !tbaa !9
  %44 = add nsw i64 %43, %.03338
  call void @_Z3dfsiiix(i32 noundef %32, i32 noundef %41, i32 noundef %42, i64 noundef %44)
  %exitcond.not = icmp eq i32 %41, 18
  br i1 %exitcond.not, label %.loopexit, label %36, !llvm.loop !13

.loopexit:                                        ; preds = %36, %24, %26, %7, %17, %12
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6bitsetILm82EE4testEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) local_unnamed_addr #0 align 2

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { i64, i64 } @_ZNKSt6bitsetILm82EElsEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6bitsetILm82EEoRERKS0_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #4 align 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { 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"}
!13 = distinct !{!13, !12}


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