; LLVM IR from TheAlgorithms/C-Plus-Plus :: math/gcd_recursive_euclidean.ll (Z3gcdii)

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

@.str = external hidden unnamed_addr constant [43 x i8], align 1
@_ZTISt12domain_error = external constant ptr

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3gcdii(i32 noundef %0, i32 noundef %1) #0 personality ptr @__gxx_personality_v0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = icmp sle i32 %8, 0
  %10 = zext i1 %9 to i32
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = icmp sle i32 %11, 0
  %13 = zext i1 %12 to i32
  %14 = or i32 %10, %13
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %23

16:                                               ; preds = %2
  %17 = call ptr @__cxa_allocate_exception(i64 16) #3
  invoke void @_ZNSt12domain_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16) %17, ptr noundef @.str)
          to label %18 unwind label %19

18:                                               ; preds = %16
  call void @__cxa_throw(ptr %17, ptr @_ZTISt12domain_error, ptr @_ZNSt12domain_errorD1Ev) #4
  unreachable

19:                                               ; preds = %16
  %20 = landingpad { ptr, i32 }
          cleanup
  %21 = extractvalue { ptr, i32 } %20, 0
  store ptr %21, ptr %6, align 8
  %22 = extractvalue { ptr, i32 } %20, 1
  store i32 %22, ptr %7, align 4
  call void @__cxa_free_exception(ptr %17) #3
  br label %63

23:                                               ; preds = %2
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = icmp eq i32 %24, %25
  br i1 %26, label %27, label %29

27:                                               ; preds = %23
  %28 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %28, ptr %3, align 4
  br label %61

29:                                               ; preds = %23
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %34

32:                                               ; preds = %29
  %33 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %33, ptr %3, align 4
  br label %61

34:                                               ; preds = %29
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %39

37:                                               ; preds = %34
  %38 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %38, ptr %3, align 4
  br label %61

39:                                               ; preds = %34
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = icmp eq i32 %40, %41
  br i1 %42, label %43, label %45

43:                                               ; preds = %39
  %44 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %44, ptr %3, align 4
  br label %61

45:                                               ; preds = %39
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = icmp sgt i32 %46, %47
  br i1 %48, label %49, label %55

49:                                               ; preds = %45
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = sub nsw i32 %50, %51
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = call noundef i32 @_Z3gcdii(i32 noundef %52, i32 noundef %53)
  store i32 %54, ptr %3, align 4
  br label %61

55:                                               ; preds = %45
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = sub nsw i32 %57, %58
  %60 = call noundef i32 @_Z3gcdii(i32 noundef %56, i32 noundef %59)
  store i32 %60, ptr %3, align 4
  br label %61

61:                                               ; preds = %55, %49, %43, %37, %32, %27
  %62 = load i32, ptr %3, align 4
  ret i32 %62

63:                                               ; preds = %19
  %64 = load ptr, ptr %6, align 8
  %65 = load i32, ptr %7, align 4
  %66 = insertvalue { ptr, i32 } poison, ptr %64, 0
  %67 = insertvalue { ptr, i32 } %66, i32 %65, 1
  resume { ptr, i32 } %67
}

declare ptr @__cxa_allocate_exception(i64)

declare void @_ZNSt12domain_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

declare void @__cxa_free_exception(ptr)

; Function Attrs: nounwind
declare void @_ZNSt12domain_errorD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2

declare void @__cxa_throw(ptr, ptr, ptr)

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 = { "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 = { nounwind "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 }
attributes #4 = { noreturn }

!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"}


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

@.str = external hidden unnamed_addr constant [43 x i8], align 1
@_ZTISt12domain_error = external constant ptr

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3gcdii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %3 = icmp slt i32 %0, 1
  %4 = icmp slt i32 %1, 1
  %5 = or i1 %3, %4
  br i1 %5, label %tailrecurse.outer._crit_edge, label %.lr.ph.split.preheader

.lr.ph.split.preheader:                           ; preds = %2, %tailrecurse.outer
  %.tr24.ph33 = phi i32 [ %.tr2428, %tailrecurse.outer ], [ %1, %2 ]
  %.tr.ph32 = phi i32 [ %13, %tailrecurse.outer ], [ %0, %2 ]
  br label %.lr.ph.split

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %2
  %6 = tail call ptr @__cxa_allocate_exception(i64 16) #3
  invoke void @_ZNSt12domain_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull @.str)
          to label %7 unwind label %8

7:                                                ; preds = %tailrecurse.outer._crit_edge
  tail call void @__cxa_throw(ptr nonnull %6, ptr nonnull @_ZTISt12domain_error, ptr nonnull @_ZNSt12domain_errorD1Ev) #4
  unreachable

8:                                                ; preds = %tailrecurse.outer._crit_edge
  %9 = landingpad { ptr, i32 }
          cleanup
  tail call void @__cxa_free_exception(ptr %6) #3
  resume { ptr, i32 } %9

.lr.ph.split:                                     ; preds = %.lr.ph.split.preheader, %tailrecurse
  %.tr2428 = phi i32 [ %17, %tailrecurse ], [ %.tr24.ph33, %.lr.ph.split.preheader ]
  %10 = icmp eq i32 %.tr.ph32, %.tr2428
  br i1 %10, label %.split.us, label %11

11:                                               ; preds = %.lr.ph.split
  %12 = icmp ugt i32 %.tr.ph32, %.tr2428
  br i1 %12, label %tailrecurse.outer, label %tailrecurse

tailrecurse.outer:                                ; preds = %11
  %13 = sub i32 %.tr.ph32, %.tr2428
  %14 = icmp slt i32 %13, 1
  %15 = icmp slt i32 %.tr2428, 1
  %16 = or i1 %14, %15
  br i1 %16, label %tailrecurse.outer._crit_edge, label %.lr.ph.split.preheader

tailrecurse:                                      ; preds = %11
  %17 = sub i32 %.tr2428, %.tr.ph32
  %18 = icmp slt i32 %17, 1
  br i1 %18, label %tailrecurse.outer._crit_edge, label %.lr.ph.split

.split.us:                                        ; preds = %.lr.ph.split
  ret i32 %.tr.ph32
}

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

declare void @_ZNSt12domain_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

declare void @__cxa_free_exception(ptr) local_unnamed_addr

; Function Attrs: nounwind
declare void @_ZNSt12domain_errorD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

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 = { "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 = { nounwind "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 }
attributes #4 = { noreturn }

!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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass