; LLVM IR from wesley-a-leung/Resources :: Tests/C++/math/CombinatoricsFuzzTest.ll (Z4bmodmm)

; 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.Barrett = type { i64, i64 }

@_ZZ4bmodmmE1b = external hidden global %struct.Barrett, align 8
@_ZGVZ4bmodmmE1b = external hidden global i64, align 8

; Function Attrs: nounwind
declare i32 @__cxa_guard_acquire(ptr) #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare void @__cxa_guard_abort(ptr) #0

; Function Attrs: nounwind
declare void @__cxa_guard_release(ptr) #0

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z4bmodmm(i64 noundef %0, i64 noundef %1) #3 personality ptr @__gxx_personality_v0 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.Barrett, align 8
  %8 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !5
  %9 = load atomic i8, ptr @_ZGVZ4bmodmmE1b acquire, align 8
  %10 = icmp eq i8 %9, 0
  br i1 %10, label %11, label %16, !prof !9

11:                                               ; preds = %2
  %12 = call i32 @__cxa_guard_acquire(ptr @_ZGVZ4bmodmmE1b) #0
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %16

14:                                               ; preds = %11
  invoke void @_ZN7BarrettC2Em(ptr noundef nonnull align 8 dereferenceable(16) @_ZZ4bmodmmE1b, i64 noundef 1)
          to label %15 unwind label %22

15:                                               ; preds = %14
  call void @__cxa_guard_release(ptr @_ZGVZ4bmodmmE1b) #0
  br label %16

16:                                               ; preds = %15, %11, %2
  %17 = load i64, ptr @_ZZ4bmodmmE1b, align 8, !tbaa !10
  %18 = load i64, ptr %4, align 8, !tbaa !5
  %19 = icmp ne i64 %17, %18
  br i1 %19, label %20, label %26

20:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #0
  %21 = load i64, ptr %4, align 8, !tbaa !5
  call void @_ZN7BarrettC2Em(ptr noundef nonnull align 8 dereferenceable(16) %7, i64 noundef %21)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 @_ZZ4bmodmmE1b, ptr align 8 %7, i64 16, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #0
  br label %26

22:                                               ; preds = %14
  %23 = landingpad { ptr, i32 }
          cleanup
  %24 = extractvalue { ptr, i32 } %23, 0
  store ptr %24, ptr %5, align 8
  %25 = extractvalue { ptr, i32 } %23, 1
  store i32 %25, ptr %6, align 4
  call void @__cxa_guard_abort(ptr @_ZGVZ4bmodmmE1b) #0
  br label %38

26:                                               ; preds = %20, %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #0
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = call noundef i64 @_ZN7Barrett6reduceEm(ptr noundef nonnull align 8 dereferenceable(16) @_ZZ4bmodmmE1b, i64 noundef %27)
  store i64 %28, ptr %8, align 8, !tbaa !5
  %29 = load i64, ptr %8, align 8, !tbaa !5
  %30 = load i64, ptr %4, align 8, !tbaa !5
  %31 = icmp uge i64 %29, %30
  br i1 %31, label %32, label %36

32:                                               ; preds = %26
  %33 = load i64, ptr %4, align 8, !tbaa !5
  %34 = load i64, ptr %8, align 8, !tbaa !5
  %35 = sub i64 %34, %33
  store i64 %35, ptr %8, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %32, %26
  %37 = load i64, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #0
  ret i64 %37

38:                                               ; preds = %22
  %39 = load ptr, ptr %5, align 8
  %40 = load i32, ptr %6, align 4
  %41 = insertvalue { ptr, i32 } poison, ptr %39, 0
  %42 = insertvalue { ptr, i32 } %41, i32 %40, 1
  resume { ptr, i32 } %42
}

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

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

attributes #0 = { nounwind }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"branch_weights", i32 1, i32 1048575}
!10 = !{!11, !6, i64 0}
!11 = !{!"_ZTS7Barrett", !6, i64 0, !6, i64 8}
!12 = !{i64 0, i64 8, !5, i64 8, i64 8, !5}


; 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.Barrett = type { i64, i64 }

@_ZZ4bmodmmE1b = external hidden global %struct.Barrett, align 8
@_ZGVZ4bmodmmE1b = external hidden global i64, align 8

; Function Attrs: nofree nounwind
declare i32 @__cxa_guard_acquire(ptr) local_unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nofree nounwind
declare void @__cxa_guard_release(ptr) local_unnamed_addr #0

; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z4bmodmm(i64 noundef %0, i64 noundef %1) local_unnamed_addr #3 personality ptr @__gxx_personality_v0 {
  %3 = alloca %struct.Barrett, align 8
  %4 = load atomic i8, ptr @_ZGVZ4bmodmmE1b acquire, align 8
  %5 = icmp eq i8 %4, 0
  br i1 %5, label %6, label %9, !prof !5

6:                                                ; preds = %2
  %7 = tail call i32 @__cxa_guard_acquire(ptr nonnull @_ZGVZ4bmodmmE1b) #4
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %9, label %8

8:                                                ; preds = %6
  tail call void @_ZN7BarrettC2Em(ptr noundef nonnull align 8 dereferenceable(16) @_ZZ4bmodmmE1b, i64 noundef 1)
  tail call void @__cxa_guard_release(ptr nonnull @_ZGVZ4bmodmmE1b) #4
  br label %9

9:                                                ; preds = %8, %6, %2
  %10 = load i64, ptr @_ZZ4bmodmmE1b, align 8, !tbaa !6
  %.not11 = icmp eq i64 %10, %1
  br i1 %.not11, label %12, label %11

11:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  call void @_ZN7BarrettC2Em(ptr noundef nonnull align 8 dereferenceable(16) %3, i64 noundef %1)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) @_ZZ4bmodmmE1b, ptr noundef nonnull align 8 dereferenceable(16) %3, i64 16, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  br label %12

12:                                               ; preds = %11, %9
  %13 = call noundef i64 @_ZN7Barrett6reduceEm(ptr noundef nonnull align 8 dereferenceable(16) @_ZZ4bmodmmE1b, i64 noundef %0)
  %.not12 = icmp ult i64 %13, %1
  %14 = select i1 %.not12, i64 0, i64 %1
  %spec.select = sub i64 %13, %14
  ret i64 %spec.select
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7BarrettC2Em(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) unnamed_addr #3 align 2

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

attributes #0 = { nofree nounwind }
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 = !{!"branch_weights", i32 1, i32 1048575}
!6 = !{!7, !8, i64 0}
!7 = !{!"_ZTS7Barrett", !8, i64 0, !8, i64 8}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{i64 0, i64 8, !12, i64 8, i64 8, !12}
!12 = !{!8, !8, i64 0}


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