; 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_ZPOS = external constant i8, align 1

; 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
define dso_local i32 @mp_rat_compare(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
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.mpq, ptr %8, i32 0, i32 0
  %10 = getelementptr inbounds %struct.mpz, ptr %9, i32 0, i32 4
  %11 = load i8, ptr %10, align 8, !tbaa !9
  %12 = zext i8 %11 to i32
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.mpq, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %struct.mpz, ptr %14, i32 0, i32 4
  %16 = load i8, ptr %15, align 8, !tbaa !9
  %17 = zext i8 %16 to i32
  %18 = icmp ne i32 %12, %17
  br i1 %18, label %19, label %30

19:                                               ; preds = %2
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.mpq, ptr %20, i32 0, i32 0
  %22 = getelementptr inbounds %struct.mpz, ptr %21, i32 0, i32 4
  %23 = load i8, ptr %22, align 8, !tbaa !9
  %24 = zext i8 %23 to i32
  %25 = load i8, ptr @MP_ZPOS, align 1, !tbaa !13
  %26 = zext i8 %25 to i32
  %27 = icmp eq i32 %24, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %19
  store i32 1, ptr %3, align 4
  br label %48

29:                                               ; preds = %19
  store i32 -1, ptr %3, align 4
  br label %48

30:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = call i32 @mp_rat_compare_unsigned(ptr noundef %31, ptr noundef %32)
  store i32 %33, ptr %6, align 4, !tbaa !14
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.mpq, ptr %34, i32 0, i32 0
  %36 = getelementptr inbounds %struct.mpz, ptr %35, i32 0, i32 4
  %37 = load i8, ptr %36, align 8, !tbaa !9
  %38 = zext i8 %37 to i32
  %39 = load i8, ptr @MP_ZPOS, align 1, !tbaa !13
  %40 = zext i8 %39 to i32
  %41 = icmp eq i32 %38, %40
  br i1 %41, label %42, label %44

42:                                               ; preds = %30
  %43 = load i32, ptr %6, align 4, !tbaa !14
  store i32 %43, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %47

44:                                               ; preds = %30
  %45 = load i32, ptr %6, align 4, !tbaa !14
  %46 = sub nsw i32 0, %45
  store i32 %46, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %47

47:                                               ; preds = %44, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %48

48:                                               ; preds = %47, %29, %28
  %49 = load i32, ptr %3, align 4
  ret i32 %49
}

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

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 = { 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, !7, i64 24}
!10 = !{!"mpq", !11, i64 0, !11, i64 32}
!11 = !{!"mpz", !12, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !7, i64 24}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!12, !12, 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"

@MP_ZPOS = external local_unnamed_addr constant i8, align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @mp_rat_compare(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load i8, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 24
  %6 = load i8, ptr %5, align 8, !tbaa !5
  %.not = icmp eq i8 %4, %6
  br i1 %.not, label %10, label %7

7:                                                ; preds = %2
  %8 = load i8, ptr @MP_ZPOS, align 1, !tbaa !12
  %9 = icmp eq i8 %4, %8
  %. = select i1 %9, i32 1, i32 -1
  br label %16

10:                                               ; preds = %2
  %11 = tail call i32 @mp_rat_compare_unsigned(ptr noundef nonnull %0, ptr noundef nonnull %1)
  %12 = load i8, ptr %3, align 8, !tbaa !5
  %13 = load i8, ptr @MP_ZPOS, align 1, !tbaa !12
  %14 = icmp eq i8 %12, %13
  %15 = sub nsw i32 0, %11
  %.0 = select i1 %14, i32 %11, i32 %15
  br label %16

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

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

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

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


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