; LLVM IR from Tiramisu-Compiler/tiramisu :: 3rdParty/isl/imath (imrat)

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

%struct.mpq = type { %struct.mpz, %struct.mpz }
%struct.mpz = type { i32, ptr, i32, i32, i8 }

@MP_OK = external constant i32, align 4
@MP_UNDEF = external constant i32, align 4

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @mp_rat_copy(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mp_rat_recip(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call i32 @mp_rat_compare_zero(ptr noundef %9)
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %14

12:                                               ; preds = %2
  %13 = load i32, ptr @MP_UNDEF, align 4, !tbaa !9
  store i32 %13, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %43

14:                                               ; preds = %2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = call i32 @mp_rat_copy(ptr noundef %15, ptr noundef %16)
  store i32 %17, ptr %6, align 4, !tbaa !9
  %18 = load i32, ptr @MP_OK, align 4, !tbaa !9
  %19 = icmp ne i32 %17, %18
  br i1 %19, label %20, label %22

20:                                               ; preds = %14
  %21 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %21, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %43

22:                                               ; preds = %14
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.mpq, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.mpq, ptr %25, i32 0, i32 1
  call void @mp_int_swap(ptr noundef %24, ptr noundef %26)
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.mpq, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds %struct.mpz, ptr %28, i32 0, i32 4
  %30 = load i8, ptr %29, align 8, !tbaa !11
  store i8 %30, ptr %8, align 1, !tbaa !14
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.mpq, ptr %31, i32 0, i32 1
  %33 = getelementptr inbounds %struct.mpz, ptr %32, i32 0, i32 4
  %34 = load i8, ptr %33, align 8, !tbaa !15
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.mpq, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds %struct.mpz, ptr %36, i32 0, i32 4
  store i8 %34, ptr %37, align 8, !tbaa !11
  %38 = load i8, ptr %8, align 1, !tbaa !14
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.mpq, ptr %39, i32 0, i32 1
  %41 = getelementptr inbounds %struct.mpz, ptr %40, i32 0, i32 4
  store i8 %38, ptr %41, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  %42 = load i32, ptr @MP_OK, align 4, !tbaa !9
  store i32 %42, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %43

43:                                               ; preds = %22, %20, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %44 = load i32, ptr %3, align 4
  ret i32 %44
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @mp_rat_compare_zero(ptr noundef) #1

declare void @mp_int_swap(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !7, i64 24}
!12 = !{!"mpq", !13, i64 0, !13, i64 32}
!13 = !{!"mpz", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !7, i64 24}
!14 = !{!7, !7, i64 0}
!15 = !{!12, !7, i64 56}


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

@MP_OK = external local_unnamed_addr constant i32, align 4
@MP_UNDEF = external local_unnamed_addr constant i32, align 4

; Function Attrs: nounwind uwtable
declare dso_local i32 @mp_rat_copy(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @mp_rat_recip(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @mp_rat_compare_zero(ptr noundef %0)
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %5, label %7

5:                                                ; preds = %2
  %6 = load i32, ptr @MP_UNDEF, align 4, !tbaa !5
  br label %16

7:                                                ; preds = %2
  %8 = tail call i32 @mp_rat_copy(ptr noundef %0, ptr noundef %1)
  %9 = load i32, ptr @MP_OK, align 4, !tbaa !5
  %.not = icmp eq i32 %8, %9
  br i1 %.not, label %10, label %16

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %1, i64 32
  tail call void @mp_int_swap(ptr noundef %1, ptr noundef nonnull %11) #2
  %12 = getelementptr inbounds i8, ptr %1, i64 24
  %13 = load i8, ptr %12, align 8, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %1, i64 56
  %15 = load i8, ptr %14, align 8, !tbaa !13
  store i8 %15, ptr %12, align 8, !tbaa !9
  store i8 %13, ptr %14, align 8, !tbaa !13
  br label %16

16:                                               ; preds = %7, %10, %5
  %.0 = phi i32 [ %6, %5 ], [ %8, %10 ], [ %8, %7 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @mp_rat_compare_zero(ptr noundef) local_unnamed_addr #0

declare void @mp_int_swap(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 = { 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/C++ TBAA"}
!9 = !{!10, !7, i64 24}
!10 = !{!"mpq", !11, i64 0, !11, i64 32}
!11 = !{!"mpz", !6, i64 0, !12, i64 8, !6, i64 16, !6, i64 20, !7, i64 24}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !7, i64 56}


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