; LLVM IR from upupming/algorithm :: AdvancedLevel_C++/1088. Rational Arithmetic (20).ll (Z4funcxx)

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

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z3gcdxx(i64 noundef, i64 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4funcxx(i64 noundef %0, i64 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i8, align 1
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !5
  %9 = load i64, ptr %3, align 8, !tbaa !5
  %10 = load i64, ptr %4, align 8, !tbaa !5
  %11 = mul nsw i64 %9, %10
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %19

13:                                               ; preds = %2
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = icmp eq i64 %14, 0
  %16 = zext i1 %15 to i64
  %17 = select i1 %15, ptr @.str.1, ptr @.str.2
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef %17)
  br label %93

19:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #4
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = icmp slt i64 %20, 0
  br i1 %21, label %22, label %25

22:                                               ; preds = %19
  %23 = load i64, ptr %4, align 8, !tbaa !5
  %24 = icmp sgt i64 %23, 0
  br i1 %24, label %33, label %25

25:                                               ; preds = %22, %19
  %26 = load i64, ptr %3, align 8, !tbaa !5
  %27 = icmp sgt i64 %26, 0
  br i1 %27, label %28, label %31

28:                                               ; preds = %25
  %29 = load i64, ptr %4, align 8, !tbaa !5
  %30 = icmp slt i64 %29, 0
  br label %31

31:                                               ; preds = %28, %25
  %32 = phi i1 [ false, %25 ], [ %30, %28 ]
  br label %33

33:                                               ; preds = %31, %22
  %34 = phi i1 [ true, %22 ], [ %32, %31 ]
  %35 = zext i1 %34 to i8
  store i8 %35, ptr %5, align 1, !tbaa !9
  %36 = load i64, ptr %3, align 8, !tbaa !5
  %37 = call noundef i64 @_ZSt3absx(i64 noundef %36)
  store i64 %37, ptr %3, align 8, !tbaa !5
  %38 = load i64, ptr %4, align 8, !tbaa !5
  %39 = call noundef i64 @_ZSt3absx(i64 noundef %38)
  store i64 %39, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %40 = load i64, ptr %3, align 8, !tbaa !5
  %41 = load i64, ptr %4, align 8, !tbaa !5
  %42 = sdiv i64 %40, %41
  store i64 %42, ptr %6, align 8, !tbaa !5
  %43 = load i8, ptr %5, align 1, !tbaa !9, !range !11, !noundef !12
  %44 = trunc i8 %43 to i1
  %45 = zext i1 %44 to i64
  %46 = select i1 %44, ptr @.str.3, ptr @.str.4
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef %46)
  %48 = load i64, ptr %6, align 8, !tbaa !5
  %49 = icmp ne i64 %48, 0
  br i1 %49, label %50, label %53

50:                                               ; preds = %33
  %51 = load i64, ptr %6, align 8, !tbaa !5
  %52 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i64 noundef %51)
  br label %53

53:                                               ; preds = %50, %33
  %54 = load i64, ptr %3, align 8, !tbaa !5
  %55 = load i64, ptr %4, align 8, !tbaa !5
  %56 = srem i64 %54, %55
  %57 = icmp eq i64 %56, 0
  br i1 %57, label %58, label %64

58:                                               ; preds = %53
  %59 = load i8, ptr %5, align 1, !tbaa !9, !range !11, !noundef !12
  %60 = trunc i8 %59 to i1
  br i1 %60, label %61, label %63

61:                                               ; preds = %58
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  br label %63

63:                                               ; preds = %61, %58
  store i32 1, ptr %7, align 4
  br label %91

64:                                               ; preds = %53
  %65 = load i64, ptr %6, align 8, !tbaa !5
  %66 = icmp ne i64 %65, 0
  br i1 %66, label %67, label %69

67:                                               ; preds = %64
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  br label %69

69:                                               ; preds = %67, %64
  %70 = load i64, ptr %3, align 8, !tbaa !5
  %71 = load i64, ptr %6, align 8, !tbaa !5
  %72 = load i64, ptr %4, align 8, !tbaa !5
  %73 = mul nsw i64 %71, %72
  %74 = sub nsw i64 %70, %73
  store i64 %74, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %75 = load i64, ptr %3, align 8, !tbaa !5
  %76 = load i64, ptr %4, align 8, !tbaa !5
  %77 = call noundef i64 @_Z3gcdxx(i64 noundef %75, i64 noundef %76)
  store i64 %77, ptr %8, align 8, !tbaa !5
  %78 = load i64, ptr %3, align 8, !tbaa !5
  %79 = load i64, ptr %8, align 8, !tbaa !5
  %80 = sdiv i64 %78, %79
  store i64 %80, ptr %3, align 8, !tbaa !5
  %81 = load i64, ptr %4, align 8, !tbaa !5
  %82 = load i64, ptr %8, align 8, !tbaa !5
  %83 = sdiv i64 %81, %82
  store i64 %83, ptr %4, align 8, !tbaa !5
  %84 = load i64, ptr %3, align 8, !tbaa !5
  %85 = load i64, ptr %4, align 8, !tbaa !5
  %86 = load i8, ptr %5, align 1, !tbaa !9, !range !11, !noundef !12
  %87 = trunc i8 %86 to i1
  %88 = zext i1 %87 to i64
  %89 = select i1 %87, ptr @.str.6, ptr @.str.4
  %90 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, i64 noundef %84, i64 noundef %85, ptr noundef %89)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  store i32 0, ptr %7, align 4
  br label %91

91:                                               ; preds = %69, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #4
  %92 = load i32, ptr %7, align 4
  switch i32 %92, label %94 [
    i32 0, label %93
    i32 1, label %93
  ]

93:                                               ; preds = %91, %91, %13
  ret void

94:                                               ; preds = %91
  unreachable
}

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}


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

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z3gcdxx(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4funcxx(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = mul nsw i64 %1, %0
  %4 = icmp eq i64 %3, 0
  br i1 %4, label %5, label %9

5:                                                ; preds = %2
  %6 = icmp eq i64 %1, 0
  %7 = select i1 %6, ptr @.str.1, ptr @.str.2
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull %7)
  br label %40

9:                                                ; preds = %2
  %10 = icmp slt i64 %0, 0
  %11 = icmp sgt i64 %1, 0
  %or.cond = and i1 %10, %11
  br i1 %or.cond, label %16, label %12

12:                                               ; preds = %9
  %13 = icmp sgt i64 %0, 0
  %14 = icmp slt i64 %1, 0
  %15 = and i1 %13, %14
  br label %16

16:                                               ; preds = %9, %12
  %17 = phi i1 [ %15, %12 ], [ true, %9 ]
  %18 = tail call noundef i64 @_ZSt3absx(i64 noundef %0)
  %19 = tail call noundef i64 @_ZSt3absx(i64 noundef %1)
  %20 = sdiv i64 %18, %19
  %.recomposed = srem i64 %18, %19
  %spec.select = select i1 %17, ptr @.str.3, ptr @.str.4
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull %spec.select)
  %.not = icmp eq i64 %20, 0
  br i1 %.not, label %22, label %.thread

22:                                               ; preds = %16
  %23 = srem i64 %18, %19
  %24 = icmp eq i64 %23, 0
  br i1 %24, label %28, label %33

.thread:                                          ; preds = %16
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i64 noundef %20)
  %26 = srem i64 %18, %19
  %27 = icmp eq i64 %26, 0
  br i1 %27, label %28, label %31

28:                                               ; preds = %.thread, %22
  br i1 %17, label %29, label %40

29:                                               ; preds = %28
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  br label %40

31:                                               ; preds = %.thread
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  br label %33

33:                                               ; preds = %22, %31
  %34 = mul nsw i64 %20, %19
  %35 = tail call noundef i64 @_Z3gcdxx(i64 noundef %.recomposed, i64 noundef %19)
  %36 = sdiv i64 %.recomposed, %35
  %37 = sdiv i64 %19, %35
  %38 = select i1 %17, ptr @.str.6, ptr @.str.4
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, i64 noundef %36, i64 noundef %37, ptr noundef nonnull %38)
  br label %40

40:                                               ; preds = %33, %29, %28, %5
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) local_unnamed_addr #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 = { nofree nounwind "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 #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" }

!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: DivRemPairsPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass