; LLVM IR from ncduy0303/Competitive-Programming :: Mathematics/GCD.ll (Z3ldexxxRxS_)

; 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
declare dso_local noundef i64 @_Z3gcdxxRxS_(i64 noundef, i64 noundef, ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #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 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 zeroext i1 @_Z3ldexxxRxS_(i64 noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4) #0 {
  %6 = alloca i1, align 1
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store i64 %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %14 = load i64, ptr %7, align 8, !tbaa !5
  %15 = call noundef i64 @_ZSt3absx(i64 noundef %14)
  %16 = load i64, ptr %8, align 8, !tbaa !5
  %17 = call noundef i64 @_ZSt3absx(i64 noundef %16)
  %18 = load ptr, ptr %10, align 8, !tbaa !9
  %19 = load ptr, ptr %11, align 8, !tbaa !9
  %20 = call noundef i64 @_Z3gcdxxRxS_(i64 noundef %15, i64 noundef %17, ptr noundef nonnull align 8 dereferenceable(8) %18, ptr noundef nonnull align 8 dereferenceable(8) %19)
  store i64 %20, ptr %12, align 8, !tbaa !5
  %21 = load i64, ptr %9, align 8, !tbaa !5
  %22 = load i64, ptr %12, align 8, !tbaa !5
  %23 = srem i64 %21, %22
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %5
  store i1 false, ptr %6, align 1
  store i32 1, ptr %13, align 4
  br label %55

26:                                               ; preds = %5
  %27 = load i64, ptr %9, align 8, !tbaa !5
  %28 = load i64, ptr %12, align 8, !tbaa !5
  %29 = sdiv i64 %27, %28
  %30 = load ptr, ptr %10, align 8, !tbaa !9
  %31 = load i64, ptr %30, align 8, !tbaa !5
  %32 = mul nsw i64 %31, %29
  store i64 %32, ptr %30, align 8, !tbaa !5
  %33 = load i64, ptr %9, align 8, !tbaa !5
  %34 = load i64, ptr %12, align 8, !tbaa !5
  %35 = sdiv i64 %33, %34
  %36 = load ptr, ptr %11, align 8, !tbaa !9
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = mul nsw i64 %37, %35
  store i64 %38, ptr %36, align 8, !tbaa !5
  %39 = load i64, ptr %7, align 8, !tbaa !5
  %40 = icmp slt i64 %39, 0
  br i1 %40, label %41, label %46

41:                                               ; preds = %26
  %42 = load ptr, ptr %10, align 8, !tbaa !9
  %43 = load i64, ptr %42, align 8, !tbaa !5
  %44 = sub nsw i64 0, %43
  %45 = load ptr, ptr %10, align 8, !tbaa !9
  store i64 %44, ptr %45, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %41, %26
  %47 = load i64, ptr %8, align 8, !tbaa !5
  %48 = icmp slt i64 %47, 0
  br i1 %48, label %49, label %54

49:                                               ; preds = %46
  %50 = load ptr, ptr %11, align 8, !tbaa !9
  %51 = load i64, ptr %50, align 8, !tbaa !5
  %52 = sub nsw i64 0, %51
  %53 = load ptr, ptr %11, align 8, !tbaa !9
  store i64 %52, ptr %53, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %49, %46
  store i1 true, ptr %6, align 1
  store i32 1, ptr %13, align 4
  br label %55

55:                                               ; preds = %54, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %56 = load i1, ptr %6, align 1
  ret i1 %56
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) #2

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 = { inlinehint 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 #3 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


; 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 uwtable
declare dso_local noundef i64 @_Z3gcdxxRxS_(i64 noundef, i64 noundef, ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3ldexxxRxS_(i64 noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4) local_unnamed_addr #0 {
  %6 = tail call noundef i64 @_ZSt3absx(i64 noundef %0)
  %7 = tail call noundef i64 @_ZSt3absx(i64 noundef %1)
  %8 = tail call noundef i64 @_Z3gcdxxRxS_(i64 noundef %6, i64 noundef %7, ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %9 = srem i64 %2, %8
  %10 = sdiv i64 %2, %8
  %.not = icmp eq i64 %9, 0
  br i1 %.not, label %11, label %25

11:                                               ; preds = %5
  %12 = load i64, ptr %3, align 8, !tbaa !5
  %13 = mul nsw i64 %12, %10
  store i64 %13, ptr %3, align 8, !tbaa !5
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = mul nsw i64 %14, %10
  store i64 %15, ptr %4, align 8, !tbaa !5
  %16 = icmp slt i64 %0, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %11
  %18 = load i64, ptr %3, align 8, !tbaa !5
  %19 = sub nsw i64 0, %18
  store i64 %19, ptr %3, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %17, %11
  %21 = icmp slt i64 %1, 0
  br i1 %21, label %22, label %25

22:                                               ; preds = %20
  %23 = load i64, ptr %4, align 8, !tbaa !5
  %24 = sub nsw i64 0, %23
  store i64 %24, ptr %4, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %20, %22, %5
  ret i1 %.not
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) local_unnamed_addr #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 = { inlinehint 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 long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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