; LLVM IR from tangjz/acm-icpc :: hdu/4769.ll (Z4calci)

; 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.Bitset = type { i32, [10 x i64] }

@m = external dso_local global i32, align 4
@rcnt = external dso_local global i32, align 4
@curC = external dso_local global [61 x %struct.Bitset], align 16
@row = external dso_local global [601 x %struct.Bitset], align 16
@col = external dso_local global [201 x %struct.Bitset], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4calci(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca %struct.Bitset, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %struct.Bitset, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %10 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %10, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 88, ptr %5) #4
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [61 x %struct.Bitset], ptr @curC, i64 0, i64 %12
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %13, i64 88, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %14 = call noundef i32 @_ZNK6Bitset6lowbitEi(ptr noundef nonnull align 8 dereferenceable(88) %5, i32 noundef 0)
  store i32 %14, ptr %6, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %52, %1
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = load i32, ptr @m, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  store i32 2, ptr %7, align 4
  br label %56

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [201 x %struct.Bitset], ptr @col, i64 0, i64 %22
  %24 = call noundef i32 @_ZNK6Bitset6lowbitEi(ptr noundef nonnull align 8 dereferenceable(88) %23, i32 noundef 0)
  store i32 %24, ptr %8, align 4, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = load i32, ptr @rcnt, align 4, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %47

28:                                               ; preds = %20
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %4, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %39, %28
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = load i32, ptr @rcnt, align 4, !tbaa !5
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %35, label %46

35:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 88, ptr %9) #4
  %36 = load i32, ptr %8, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [601 x %struct.Bitset], ptr @row, i64 0, i64 %37
  call void @_ZNK6BitsetmiERKS_(ptr dead_on_unwind writable sret(%struct.Bitset) align 8 %9, ptr noundef nonnull align 8 dereferenceable(88) %5, ptr noundef nonnull align 8 dereferenceable(88) %38)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %9, i64 88, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 88, ptr %9) #4
  br label %39

39:                                               ; preds = %35
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [201 x %struct.Bitset], ptr @col, i64 0, i64 %41
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  %45 = call noundef i32 @_ZNK6Bitset6lowbitEi(ptr noundef nonnull align 8 dereferenceable(88) %42, i32 noundef %44)
  store i32 %45, ptr %8, align 4, !tbaa !5
  br label %31, !llvm.loop !11

46:                                               ; preds = %31
  br label %48

47:                                               ; preds = %20
  store i32 1061109567, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %49

48:                                               ; preds = %46
  store i32 0, ptr %7, align 4
  br label %49

49:                                               ; preds = %48, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %50 = load i32, ptr %7, align 4
  switch i32 %50, label %56 [
    i32 0, label %51
  ]

51:                                               ; preds = %49
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  %55 = call noundef i32 @_ZNK6Bitset6lowbitEi(ptr noundef nonnull align 8 dereferenceable(88) %5, i32 noundef %54)
  store i32 %55, ptr %6, align 4, !tbaa !5
  br label %15, !llvm.loop !13

56:                                               ; preds = %49, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %57 = load i32, ptr %7, align 4
  switch i32 %57, label %60 [
    i32 2, label %58
  ]

58:                                               ; preds = %56
  %59 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %59, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %60

60:                                               ; preds = %58, %56
  call void @llvm.lifetime.end.p0(i64 88, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %61 = load i32, ptr %2, align 4
  ret i32 %61
}

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6Bitset6lowbitEi(ptr noundef nonnull align 8 dereferenceable(88), i32 noundef) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK6BitsetmiERKS_(ptr dead_on_unwind noalias writable sret(%struct.Bitset) align 8, ptr noundef nonnull align 8 dereferenceable(88), ptr noundef nonnull align 8 dereferenceable(88)) #0 align 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 = !{i64 0, i64 4, !5, i64 8, i64 80, !10}
!10 = !{!7, !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"

%struct.Bitset = type { i32, [10 x i64] }

@m = external dso_local local_unnamed_addr global i32, align 4
@rcnt = external dso_local local_unnamed_addr global i32, align 4
@curC = external dso_local local_unnamed_addr global [61 x %struct.Bitset], align 16
@row = external dso_local global [601 x %struct.Bitset], align 16
@col = external dso_local global [201 x %struct.Bitset], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4calci(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca %struct.Bitset, align 8
  %3 = alloca %struct.Bitset, align 8
  call void @llvm.lifetime.start.p0(i64 88, ptr nonnull %2) #4
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [61 x %struct.Bitset], ptr @curC, i64 0, i64 %4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(88) %2, ptr noundef nonnull align 8 dereferenceable(88) %5, i64 88, i1 false), !tbaa.struct !5
  %6 = call noundef i32 @_ZNK6Bitset6lowbitEi(ptr noundef nonnull align 8 dereferenceable(88) %2, i32 noundef 0)
  %7 = load i32, ptr @m, align 4, !tbaa !6
  %.not26 = icmp slt i32 %6, %7
  br i1 %.not26, label %.lr.ph30, label %.thread

.lr.ph30:                                         ; preds = %1, %._crit_edge
  %.01728 = phi i32 [ %21, %._crit_edge ], [ %6, %1 ]
  %.01827 = phi i32 [ %13, %._crit_edge ], [ %0, %1 ]
  %8 = sext i32 %.01728 to i64
  %9 = getelementptr inbounds [201 x %struct.Bitset], ptr @col, i64 0, i64 %8
  %10 = call noundef i32 @_ZNK6Bitset6lowbitEi(ptr noundef nonnull align 8 dereferenceable(88) %9, i32 noundef 0)
  %11 = load i32, ptr @rcnt, align 4, !tbaa !6
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %.lr.ph.preheader, label %.thread

.lr.ph.preheader:                                 ; preds = %.lr.ph30
  %13 = add nsw i32 %.01827, 1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.025 = phi i32 [ %17, %.lr.ph ], [ %10, %.lr.ph.preheader ]
  call void @llvm.lifetime.start.p0(i64 88, ptr nonnull %3) #4
  %14 = sext i32 %.025 to i64
  %15 = getelementptr inbounds [601 x %struct.Bitset], ptr @row, i64 0, i64 %14
  call void @_ZNK6BitsetmiERKS_(ptr dead_on_unwind nonnull writable sret(%struct.Bitset) align 8 %3, ptr noundef nonnull align 8 dereferenceable(88) %2, ptr noundef nonnull align 8 dereferenceable(88) %15)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(88) %2, ptr noundef nonnull align 8 dereferenceable(88) %3, i64 88, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.end.p0(i64 88, ptr nonnull %3) #4
  %16 = add nsw i32 %.025, 1
  %17 = call noundef i32 @_ZNK6Bitset6lowbitEi(ptr noundef nonnull align 8 dereferenceable(88) %9, i32 noundef %16)
  %18 = load i32, ptr @rcnt, align 4, !tbaa !6
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph
  %20 = add nsw i32 %.01728, 1
  %21 = call noundef i32 @_ZNK6Bitset6lowbitEi(ptr noundef nonnull align 8 dereferenceable(88) %2, i32 noundef %20)
  %22 = load i32, ptr @m, align 4, !tbaa !6
  %.not = icmp slt i32 %21, %22
  br i1 %.not, label %.lr.ph30, label %.thread, !llvm.loop !13

.thread:                                          ; preds = %._crit_edge, %.lr.ph30, %1
  %spec.select = phi i32 [ %0, %1 ], [ 1061109567, %.lr.ph30 ], [ %13, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 88, ptr nonnull %2) #4
  ret i32 %spec.select
}

; 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 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) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6Bitset6lowbitEi(ptr noundef nonnull align 8 dereferenceable(88), i32 noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK6BitsetmiERKS_(ptr dead_on_unwind noalias writable sret(%struct.Bitset) align 8, ptr noundef nonnull align 8 dereferenceable(88), ptr noundef nonnull align 8 dereferenceable(88)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 = !{i64 0, i64 4, !6, i64 8, i64 80, !10}
!6 = !{!7, !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass