; LLVM IR from TheAlgorithms/C-Plus-Plus :: math/least_common_multiple.ll (Z3gcdjj)

; 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 @_Z3gcdjj(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %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 eq i32 %8, 0
  br i1 %9, label %10, label %12

10:                                               ; preds = %2
  %11 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %11, ptr %3, align 4
  br label %49

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

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

17:                                               ; preds = %12
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = icmp eq i32 %18, %19
  br i1 %20, label %21, label %23

21:                                               ; preds = %17
  %22 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %22, ptr %3, align 4
  br label %49

23:                                               ; preds = %17
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = icmp ugt i32 %24, %25
  br i1 %26, label %27, label %38

27:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = udiv i32 %28, %29
  store i32 %30, ptr %6, align 4, !tbaa !5
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = mul i32 %33, %34
  %36 = sub i32 %32, %35
  %37 = call noundef i32 @_Z3gcdjj(i32 noundef %31, i32 noundef %36)
  store i32 %37, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %49

38:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = udiv i32 %39, %40
  store i32 %41, ptr %7, align 4, !tbaa !5
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = mul i32 %44, %45
  %47 = sub i32 %43, %46
  %48 = call noundef i32 @_Z3gcdjj(i32 noundef %42, i32 noundef %47)
  store i32 %48, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %49

49:                                               ; preds = %38, %27, %21, %15, %10
  %50 = load i32, ptr %3, align 4
  ret i32 %50
}

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

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


; 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 @_Z3gcdjj(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.preheader

.lr.ph.split.preheader:                           ; preds = %2
  %4 = icmp eq i32 %1, 0
  %5 = icmp eq i32 %0, %1
  %or.cond3555 = or i1 %4, %5
  br i1 %or.cond3555, label %tailrecurse.outer._crit_edge, label %.lr.ph37.preheader

.lr.ph37.preheader:                               ; preds = %.lr.ph.split.preheader, %tailrecurse.outer
  %.tr.ph4057 = phi i32 [ %.tr242636, %tailrecurse.outer ], [ %0, %.lr.ph.split.preheader ]
  %.tr24.ph4156 = phi i32 [ %7, %tailrecurse.outer ], [ %1, %.lr.ph.split.preheader ]
  br label %.lr.ph37

.lr.ph37:                                         ; preds = %.lr.ph37.preheader, %tailrecurse
  %.tr242636 = phi i32 [ %9, %tailrecurse ], [ %.tr24.ph4156, %.lr.ph37.preheader ]
  %6 = icmp ugt i32 %.tr.ph4057, %.tr242636
  br i1 %6, label %tailrecurse.outer, label %tailrecurse

tailrecurse.outer:                                ; preds = %.lr.ph37
  %7 = urem i32 %.tr.ph4057, %.tr242636
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %tailrecurse.outer._crit_edge, label %.lr.ph37.preheader

tailrecurse:                                      ; preds = %.lr.ph37
  %9 = urem i32 %.tr242636, %.tr.ph4057
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %tailrecurse.outer._crit_edge, label %.lr.ph37

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %.lr.ph.split.preheader, %2
  %.0 = phi i32 [ %1, %2 ], [ %0, %.lr.ph.split.preheader ], [ %.tr.ph4057, %tailrecurse ], [ %.tr242636, %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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass