; LLVM IR from chirag-singhal/Coding-Interview-101 :: Miscellaneous/InterviewBit/Maths/LargestCoprimeDivisor.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 %11, label %8

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

11:                                               ; preds = %8, %2
  store i32 0, ptr %3, align 4
  br label %34

12:                                               ; preds = %8
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = icmp eq i32 %13, %14
  br i1 %15, label %16, label %18

16:                                               ; preds = %12
  %17 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %17, ptr %3, align 4
  br label %34

18:                                               ; preds = %12
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = icmp sgt i32 %19, %20
  br i1 %21, label %22, label %28

22:                                               ; preds = %18
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sub nsw i32 %23, %24
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = call noundef i32 @_Z3gcdii(i32 noundef %25, i32 noundef %26)
  store i32 %27, ptr %3, align 4
  br label %34

28:                                               ; preds = %18
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sub nsw i32 %30, %31
  %33 = call noundef i32 @_Z3gcdii(i32 noundef %29, i32 noundef %32)
  store i32 %33, ptr %3, align 4
  br label %34

34:                                               ; preds = %28, %22, %16, %11
  %35 = load i32, ptr %3, align 4
  ret i32 %35
}

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
  %4 = icmp eq i32 %1, 0
  %or.cond1925 = or i1 %3, %4
  br i1 %or.cond1925, label %tailrecurse.outer._crit_edge, label %.lr.ph.split.preheader

.lr.ph.split.preheader:                           ; preds = %2, %tailrecurse.outer
  %.tr17.ph27 = phi i32 [ %.tr1720, %tailrecurse.outer ], [ %1, %2 ]
  %.tr.ph26 = phi i32 [ %8, %tailrecurse.outer ], [ %0, %2 ]
  br label %.lr.ph.split

.lr.ph.split:                                     ; preds = %.lr.ph.split.preheader, %tailrecurse
  %.tr1720 = phi i32 [ %11, %tailrecurse ], [ %.tr17.ph27, %.lr.ph.split.preheader ]
  %5 = icmp eq i32 %.tr.ph26, %.tr1720
  br i1 %5, label %tailrecurse.outer._crit_edge, label %6

6:                                                ; preds = %.lr.ph.split
  %7 = icmp sgt i32 %.tr.ph26, %.tr1720
  br i1 %7, label %tailrecurse.outer, label %tailrecurse

tailrecurse.outer:                                ; preds = %6
  %8 = sub i32 %.tr.ph26, %.tr1720
  %9 = icmp eq i32 %8, 0
  %10 = icmp eq i32 %.tr1720, 0
  %or.cond19 = or i1 %9, %10
  br i1 %or.cond19, label %tailrecurse.outer._crit_edge, label %.lr.ph.split.preheader

tailrecurse:                                      ; preds = %6
  %11 = sub i32 %.tr1720, %.tr.ph26
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %tailrecurse.outer._crit_edge, label %.lr.ph.split

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %.lr.ph.split, %2
  %.0 = phi i32 [ 0, %2 ], [ %.tr.ph26, %.lr.ph.split ], [ 0, %tailrecurse ], [ 0, %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