; LLVM IR from Tunghohin/Competitive_Coding :: Daimayuan/488.ll (Z21solve_linear_equationxxxRxS_)

; 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 @_Z6ex_gcdxxRxS_(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 @_Z21solve_linear_equationxxxRxS_(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
  %14 = alloca i64, align 8
  %15 = alloca i128, align 16
  %16 = alloca i64, align 8
  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) #2
  %17 = load i64, ptr %7, align 8, !tbaa !5
  %18 = load i64, ptr %8, align 8, !tbaa !5
  %19 = load ptr, ptr %10, align 8, !tbaa !9
  %20 = load ptr, ptr %11, align 8, !tbaa !9
  %21 = call noundef i64 @_Z6ex_gcdxxRxS_(i64 noundef %17, i64 noundef %18, ptr noundef nonnull align 8 dereferenceable(8) %19, ptr noundef nonnull align 8 dereferenceable(8) %20)
  store i64 %21, ptr %12, align 8, !tbaa !5
  %22 = load i64, ptr %9, align 8, !tbaa !5
  %23 = load i64, ptr %12, align 8, !tbaa !5
  %24 = srem i64 %22, %23
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %26, label %27

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

27:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  %28 = load i64, ptr %9, align 8, !tbaa !5
  %29 = load i64, ptr %12, align 8, !tbaa !5
  %30 = sdiv i64 %28, %29
  store i64 %30, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %15) #2
  %31 = load ptr, ptr %10, align 8, !tbaa !9
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = sext i64 %32 to i128
  %34 = load i64, ptr %14, align 8, !tbaa !5
  %35 = sext i64 %34 to i128
  %36 = mul nsw i128 %33, %35
  store i128 %36, ptr %15, align 16, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #2
  %37 = load i64, ptr %8, align 8, !tbaa !5
  %38 = load i64, ptr %12, align 8, !tbaa !5
  %39 = sdiv i64 %37, %38
  store i64 %39, ptr %16, align 8, !tbaa !5
  %40 = load i128, ptr %15, align 16, !tbaa !11
  %41 = load i64, ptr %16, align 8, !tbaa !5
  %42 = sext i64 %41 to i128
  %43 = srem i128 %40, %42
  %44 = load i64, ptr %16, align 8, !tbaa !5
  %45 = sext i64 %44 to i128
  %46 = add nsw i128 %43, %45
  %47 = trunc i128 %46 to i64
  %48 = load i64, ptr %16, align 8, !tbaa !5
  %49 = srem i64 %47, %48
  %50 = load ptr, ptr %10, align 8, !tbaa !9
  store i64 %49, ptr %50, align 8, !tbaa !5
  %51 = load i64, ptr %9, align 8, !tbaa !5
  %52 = load i64, ptr %7, align 8, !tbaa !5
  %53 = load ptr, ptr %10, align 8, !tbaa !9
  %54 = load i64, ptr %53, align 8, !tbaa !5
  %55 = mul nsw i64 %52, %54
  %56 = sub nsw i64 %51, %55
  %57 = load i64, ptr %8, align 8, !tbaa !5
  %58 = sdiv i64 %56, %57
  %59 = load ptr, ptr %11, align 8, !tbaa !9
  store i64 %58, ptr %59, align 8, !tbaa !5
  %60 = load ptr, ptr %11, align 8, !tbaa !9
  %61 = load i64, ptr %60, align 8, !tbaa !5
  %62 = icmp slt i64 %61, 0
  br i1 %62, label %63, label %64

63:                                               ; preds = %27
  store i1 false, ptr %6, align 1
  store i32 1, ptr %13, align 4
  br label %65

64:                                               ; preds = %27
  store i1 true, ptr %6, align 1
  store i32 1, ptr %13, align 4
  br label %65

65:                                               ; preds = %64, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  br label %66

66:                                               ; preds = %65, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  %67 = load i1, ptr %6, align 1
  ret i1 %67
}

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 = !{!"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}
!11 = !{!12, !12, i64 0}
!12 = !{!"__int128", !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 @_Z6ex_gcdxxRxS_(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 @_Z21solve_linear_equationxxxRxS_(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 @_Z6ex_gcdxxRxS_(i64 noundef %0, i64 noundef %1, ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %7 = srem i64 %2, %6
  %8 = sdiv i64 %2, %6
  %.not = icmp eq i64 %7, 0
  br i1 %.not, label %9, label %24

9:                                                ; preds = %5
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = sext i64 %10 to i128
  %12 = sext i64 %8 to i128
  %13 = mul nsw i128 %11, %12
  %14 = sdiv i64 %1, %6
  %15 = sext i64 %14 to i128
  %16 = srem i128 %13, %15
  %17 = trunc nsw i128 %16 to i64
  %18 = add i64 %14, %17
  %19 = srem i64 %18, %14
  store i64 %19, ptr %3, align 8, !tbaa !5
  %20 = mul nsw i64 %19, %0
  %21 = sub nsw i64 %2, %20
  %22 = sdiv i64 %21, %1
  store i64 %22, ptr %4, align 8, !tbaa !5
  %23 = icmp sgt i64 %22, -1
  br label %24

24:                                               ; preds = %5, %9
  %.1 = phi i1 [ %23, %9 ], [ false, %5 ]
  ret i1 %.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" }

!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,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass