; LLVM IR from codemistic/Data-Structures-and-Algorithms :: CPP/recursion/GCD_Rec.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"

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3gcdii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %10

8:                                                ; preds = %2
  %9 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %9, ptr %3, align 4
  br label %37

10:                                               ; preds = %2
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %10
  %14 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %14, ptr %3, align 4
  br label %37

15:                                               ; preds = %10
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = icmp eq i32 %16, %17
  br i1 %18, label %19, label %21

19:                                               ; preds = %15
  %20 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %20, ptr %3, align 4
  br label %37

21:                                               ; preds = %15
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = icmp sgt i32 %22, %23
  br i1 %24, label %25, label %31

25:                                               ; preds = %21
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = sub nsw i32 %26, %27
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = call noundef i32 @_Z3gcdii(i32 noundef %28, i32 noundef %29)
  store i32 %30, ptr %3, align 4
  br label %37

31:                                               ; preds = %21
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sub nsw i32 %33, %34
  %36 = call noundef i32 @_Z3gcdii(i32 noundef %32, i32 noundef %35)
  store i32 %36, ptr %3, align 4
  br label %37

37:                                               ; preds = %31, %25, %19, %13, %8
  %38 = load i32, ptr %3, align 4
  ret i32 %38
}

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

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef i32 @_Z3gcdii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %0, 0
  br i1 %3, label %tailrecurse.outer._crit_edge, label %.lr.ph.split

.lr.ph.split:                                     ; preds = %2, %tailrecurse.outer
  %.tr18.ph35 = phi i32 [ %.tr182030, %tailrecurse.outer ], [ %1, %2 ]
  %.tr.ph34 = phi i32 [ %7, %tailrecurse.outer ], [ %0, %2 ]
  %4 = icmp eq i32 %.tr18.ph35, 0
  %5 = icmp eq i32 %.tr.ph34, %.tr18.ph35
  %or.cond29 = or i1 %4, %5
  br i1 %or.cond29, label %tailrecurse.outer._crit_edge, label %.lr.ph31

.lr.ph31:                                         ; preds = %.lr.ph.split, %tailrecurse
  %.tr182030 = phi i32 [ %9, %tailrecurse ], [ %.tr18.ph35, %.lr.ph.split ]
  %6 = icmp sgt i32 %.tr.ph34, %.tr182030
  br i1 %6, label %tailrecurse.outer, label %tailrecurse

tailrecurse.outer:                                ; preds = %.lr.ph31
  %7 = sub nsw i32 %.tr.ph34, %.tr182030
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %tailrecurse.outer._crit_edge, label %.lr.ph.split

tailrecurse:                                      ; preds = %.lr.ph31
  %9 = sub nsw i32 %.tr182030, %.tr.ph34
  %10 = icmp eq i32 %9, 0
  %11 = icmp eq i32 %.tr.ph34, %9
  %or.cond = or i1 %10, %11
  br i1 %or.cond, label %tailrecurse.outer._crit_edge, label %.lr.ph31

tailrecurse.outer._crit_edge:                     ; preds = %.lr.ph.split, %tailrecurse.outer, %tailrecurse, %2
  %.0 = phi i32 [ %1, %2 ], [ %.tr.ph34, %tailrecurse ], [ %.tr.ph34, %.lr.ph.split ], [ %.tr182030, %tailrecurse.outer ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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)"}


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