; LLVM IR from facebook/redex :: libredex (MonitorCount)

; 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.sparta::ConstantAbstractDomain" = type { %"class.sparta::acd_impl::ConstantAbstractValueRepr" }
%"class.sparta::acd_impl::ConstantAbstractValueRepr" = type { i32, i32 }
%"class.boost::optional" = type { %"class.boost::optional_detail::tc_optional_base" }
%"class.boost::optional_detail::tc_optional_base" = type { i8, i32 }

; 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: 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) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6sparta14AbstractDomainINS_22ConstantAbstractDomainIjEEED2Ev(ptr noundef nonnull align 1 dereferenceable(1)) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK6sparta22ConstantAbstractDomainIjE8is_valueEv(ptr noundef nonnull align 4 dereferenceable(8)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZNK6sparta22ConstantAbstractDomainIjE12get_constantEv(ptr noundef nonnull align 4 dereferenceable(8)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNO5boost8optionalIjEdeEv(ptr noundef nonnull align 4 dereferenceable(8)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZNK13IRInstruction6opcodeEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6sparta22ConstantAbstractDomainIjEC2Ej(ptr noundef nonnull align 4 dereferenceable(8), i32 noundef) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK13monitor_count8Analyzer19analyze_instructionEPK13IRInstructionPN6sparta22ConstantAbstractDomainIjEE(ptr noundef nonnull align 8 dereferenceable(256) %0, ptr noundef %1, ptr noundef %2) unnamed_addr #3 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  %8 = alloca %"class.sparta::ConstantAbstractDomain", align 4
  %9 = alloca %"class.boost::optional", align 4
  %10 = alloca %"class.sparta::ConstantAbstractDomain", align 4
  %11 = alloca %"class.boost::optional", align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = call noundef zeroext i1 @_ZNK6sparta22ConstantAbstractDomainIjE8is_valueEv(ptr noundef nonnull align 4 dereferenceable(8) %13)
  br i1 %14, label %16, label %15

15:                                               ; preds = %3
  br label %39

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #4
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call noundef zeroext i16 @_ZNK13IRInstruction6opcodeEv(ptr noundef nonnull align 8 dereferenceable(32) %17)
  store i16 %18, ptr %7, align 2, !tbaa !9
  %19 = load i16, ptr %7, align 2, !tbaa !9
  %20 = zext i16 %19 to i32
  switch i32 %20, label %37 [
    i32 16, label %21
    i32 17, label %29
  ]

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = call i64 @_ZNK6sparta22ConstantAbstractDomainIjE12get_constantEv(ptr noundef nonnull align 4 dereferenceable(8) %22)
  %24 = getelementptr inbounds %"class.boost::optional", ptr %9, i32 0, i32 0
  store i64 %23, ptr %24, align 4
  %25 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNO5boost8optionalIjEdeEv(ptr noundef nonnull align 4 dereferenceable(8) %9)
  %26 = load i32, ptr %25, align 4, !tbaa !11
  %27 = add i32 %26, 1
  call void @_ZN6sparta22ConstantAbstractDomainIjEC2Ej(ptr noundef nonnull align 4 dereferenceable(8) %8, i32 noundef %27)
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %28, ptr align 4 %8, i64 8, i1 false)
  call void @_ZN6sparta14AbstractDomainINS_22ConstantAbstractDomainIjEEED2Ev(ptr noundef nonnull align 4 dereferenceable(8) %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %38

29:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call i64 @_ZNK6sparta22ConstantAbstractDomainIjE12get_constantEv(ptr noundef nonnull align 4 dereferenceable(8) %30)
  %32 = getelementptr inbounds %"class.boost::optional", ptr %11, i32 0, i32 0
  store i64 %31, ptr %32, align 4
  %33 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNO5boost8optionalIjEdeEv(ptr noundef nonnull align 4 dereferenceable(8) %11)
  %34 = load i32, ptr %33, align 4, !tbaa !11
  %35 = sub i32 %34, 1
  call void @_ZN6sparta22ConstantAbstractDomainIjEC2Ej(ptr noundef nonnull align 4 dereferenceable(8) %10, i32 noundef %35)
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %36, ptr align 4 %10, i64 8, i1 false)
  call void @_ZN6sparta14AbstractDomainINS_22ConstantAbstractDomainIjEEED2Ev(ptr noundef nonnull align 4 dereferenceable(8) %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %38

37:                                               ; preds = %16
  br label %38

38:                                               ; preds = %37, %29, %21
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #4
  br label %39

39:                                               ; preds = %38, %15
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_ZTS8IROpcode", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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"

%"class.sparta::ConstantAbstractDomain" = type { %"class.sparta::acd_impl::ConstantAbstractValueRepr" }
%"class.sparta::acd_impl::ConstantAbstractValueRepr" = type { i32, i32 }
%"class.boost::optional" = type { %"class.boost::optional_detail::tc_optional_base" }
%"class.boost::optional_detail::tc_optional_base" = type { i8, i32 }

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6sparta14AbstractDomainINS_22ConstantAbstractDomainIjEEED2Ev(ptr noundef nonnull align 1 dereferenceable(1)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK6sparta22ConstantAbstractDomainIjE8is_valueEv(ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZNK6sparta22ConstantAbstractDomainIjE12get_constantEv(ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNO5boost8optionalIjEdeEv(ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZNK13IRInstruction6opcodeEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6sparta22ConstantAbstractDomainIjEC2Ej(ptr noundef nonnull align 4 dereferenceable(8), i32 noundef) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK13monitor_count8Analyzer19analyze_instructionEPK13IRInstructionPN6sparta22ConstantAbstractDomainIjEE(ptr nocapture noundef nonnull readnone align 8 dereferenceable(256) %0, ptr noundef %1, ptr noundef nonnull %2) unnamed_addr #2 align 2 {
  %4 = alloca %"class.sparta::ConstantAbstractDomain", align 8
  %5 = alloca %"class.boost::optional", align 8
  %6 = alloca %"class.sparta::ConstantAbstractDomain", align 8
  %7 = alloca %"class.boost::optional", align 8
  %8 = tail call noundef zeroext i1 @_ZNK6sparta22ConstantAbstractDomainIjE8is_valueEv(ptr noundef nonnull align 4 dereferenceable(8) %2)
  br i1 %8, label %9, label %23

9:                                                ; preds = %3
  %10 = tail call noundef zeroext i16 @_ZNK13IRInstruction6opcodeEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  switch i16 %10, label %23 [
    i16 16, label %11
    i16 17, label %17
  ]

11:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %12 = tail call i64 @_ZNK6sparta22ConstantAbstractDomainIjE12get_constantEv(ptr noundef nonnull align 4 dereferenceable(8) %2)
  store i64 %12, ptr %5, align 8
  %13 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNO5boost8optionalIjEdeEv(ptr noundef nonnull align 4 dereferenceable(8) %5)
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = add i32 %14, 1
  call void @_ZN6sparta22ConstantAbstractDomainIjEC2Ej(ptr noundef nonnull align 4 dereferenceable(8) %4, i32 noundef %15)
  %16 = load i64, ptr %4, align 8
  store i64 %16, ptr %2, align 4
  call void @_ZN6sparta14AbstractDomainINS_22ConstantAbstractDomainIjEEED2Ev(ptr noundef nonnull align 4 dereferenceable(8) %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  br label %23

17:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  %18 = tail call i64 @_ZNK6sparta22ConstantAbstractDomainIjE12get_constantEv(ptr noundef nonnull align 4 dereferenceable(8) %2)
  store i64 %18, ptr %7, align 8
  %19 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNO5boost8optionalIjEdeEv(ptr noundef nonnull align 4 dereferenceable(8) %7)
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = add i32 %20, -1
  call void @_ZN6sparta22ConstantAbstractDomainIjEC2Ej(ptr noundef nonnull align 4 dereferenceable(8) %6, i32 noundef %21)
  %22 = load i64, ptr %6, align 8
  store i64 %22, ptr %2, align 4
  call void @_ZN6sparta14AbstractDomainINS_22ConstantAbstractDomainIjEEED2Ev(ptr noundef nonnull align 4 dereferenceable(8) %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  br label %23

23:                                               ; preds = %11, %17, %9, %3
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = { 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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass