; 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.mpz = type { i32, ptr, i32, i32, i8 }
%struct.mpq = type { %struct.mpz, %struct.mpz }

@MP_OK = 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

declare void @mp_int_clear(ptr noundef) #1

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

declare i32 @mp_int_init_copy(ptr noundef, ptr noundef) #1

declare i32 @mp_int_mul(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mp_rat_compare_unsigned(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca [2 x %struct.mpz], align 16
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.mpq, ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.mpq, ptr %12, i32 0, i32 1
  %14 = call i32 @mp_int_compare_unsigned(ptr noundef %11, ptr noundef %13)
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %22

16:                                               ; preds = %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.mpq, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.mpq, ptr %19, i32 0, i32 0
  %21 = call i32 @mp_int_compare_unsigned(ptr noundef %18, ptr noundef %20)
  store i32 %21, ptr %3, align 4
  br label %93

22:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 64, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 2147483647, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %22
  %24 = getelementptr inbounds [2 x %struct.mpz], ptr %6, i64 0, i64 0
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds %struct.mpz, ptr %24, i64 %26
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.mpq, ptr %28, i32 0, i32 0
  %30 = call i32 @mp_int_init_copy(ptr noundef %27, ptr noundef %29)
  store i32 %30, ptr %7, align 4, !tbaa !9
  %31 = load i32, ptr @MP_OK, align 4, !tbaa !9
  %32 = icmp ne i32 %30, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %23
  br label %81

34:                                               ; preds = %23
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %9, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %34
  br label %38

38:                                               ; preds = %37
  br label %39

39:                                               ; preds = %38
  %40 = getelementptr inbounds [2 x %struct.mpz], ptr %6, i64 0, i64 0
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds %struct.mpz, ptr %40, i64 %42
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.mpq, ptr %44, i32 0, i32 0
  %46 = call i32 @mp_int_init_copy(ptr noundef %43, ptr noundef %45)
  store i32 %46, ptr %7, align 4, !tbaa !9
  %47 = load i32, ptr @MP_OK, align 4, !tbaa !9
  %48 = icmp ne i32 %46, %47
  br i1 %48, label %49, label %50

49:                                               ; preds = %39
  br label %81

50:                                               ; preds = %39
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %9, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %50
  br label %54

54:                                               ; preds = %53
  %55 = getelementptr inbounds [2 x %struct.mpz], ptr %6, i64 0, i64 0
  %56 = getelementptr inbounds %struct.mpz, ptr %55, i64 0
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.mpq, ptr %57, i32 0, i32 1
  %59 = getelementptr inbounds [2 x %struct.mpz], ptr %6, i64 0, i64 0
  %60 = getelementptr inbounds %struct.mpz, ptr %59, i64 0
  %61 = call i32 @mp_int_mul(ptr noundef %56, ptr noundef %58, ptr noundef %60)
  store i32 %61, ptr %7, align 4, !tbaa !9
  %62 = load i32, ptr @MP_OK, align 4, !tbaa !9
  %63 = icmp ne i32 %61, %62
  br i1 %63, label %74, label %64

64:                                               ; preds = %54
  %65 = getelementptr inbounds [2 x %struct.mpz], ptr %6, i64 0, i64 0
  %66 = getelementptr inbounds %struct.mpz, ptr %65, i64 1
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.mpq, ptr %67, i32 0, i32 1
  %69 = getelementptr inbounds [2 x %struct.mpz], ptr %6, i64 0, i64 0
  %70 = getelementptr inbounds %struct.mpz, ptr %69, i64 1
  %71 = call i32 @mp_int_mul(ptr noundef %66, ptr noundef %68, ptr noundef %70)
  store i32 %71, ptr %7, align 4, !tbaa !9
  %72 = load i32, ptr @MP_OK, align 4, !tbaa !9
  %73 = icmp ne i32 %71, %72
  br i1 %73, label %74, label %75

74:                                               ; preds = %64, %54
  br label %81

75:                                               ; preds = %64
  %76 = getelementptr inbounds [2 x %struct.mpz], ptr %6, i64 0, i64 0
  %77 = getelementptr inbounds %struct.mpz, ptr %76, i64 0
  %78 = getelementptr inbounds [2 x %struct.mpz], ptr %6, i64 0, i64 0
  %79 = getelementptr inbounds %struct.mpz, ptr %78, i64 1
  %80 = call i32 @mp_int_compare_unsigned(ptr noundef %77, ptr noundef %79)
  store i32 %80, ptr %8, align 4, !tbaa !9
  br label %81

81:                                               ; preds = %75, %74, %49, %33
  br label %82

82:                                               ; preds = %86, %81
  %83 = load i32, ptr %9, align 4, !tbaa !9
  %84 = add nsw i32 %83, -1
  store i32 %84, ptr %9, align 4, !tbaa !9
  %85 = icmp sge i32 %84, 0
  br i1 %85, label %86, label %91

86:                                               ; preds = %82
  %87 = getelementptr inbounds [2 x %struct.mpz], ptr %6, i64 0, i64 0
  %88 = load i32, ptr %9, align 4, !tbaa !9
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds %struct.mpz, ptr %87, i64 %89
  call void @mp_int_clear(ptr noundef %90)
  br label %82, !llvm.loop !11

91:                                               ; preds = %82
  %92 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %92, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr %6) #3
  br label %93

93:                                               ; preds = %91, %16
  %94 = load i32, ptr %3, align 4
  ret i32 %94
}

declare i32 @mp_int_compare_unsigned(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

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

@MP_OK = external local_unnamed_addr constant i32, align 4

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

declare void @mp_int_clear(ptr noundef) local_unnamed_addr #1

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

declare i32 @mp_int_init_copy(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @mp_int_mul(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mp_rat_compare_unsigned(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca [2 x %struct.mpz], align 16
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = getelementptr inbounds i8, ptr %1, i64 32
  %6 = tail call i32 @mp_int_compare_unsigned(ptr noundef nonnull %4, ptr noundef nonnull %5) #3
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %10

8:                                                ; preds = %2
  %9 = tail call i32 @mp_int_compare_unsigned(ptr noundef %0, ptr noundef %1) #3
  br label %24

10:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %3) #3
  %11 = call i32 @mp_int_init_copy(ptr noundef nonnull %3, ptr noundef %0) #3
  %12 = load i32, ptr @MP_OK, align 4, !tbaa !5
  %.not = icmp eq i32 %11, %12
  br i1 %.not, label %13, label %._crit_edge

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %3, i64 32
  %15 = call i32 @mp_int_init_copy(ptr noundef nonnull %14, ptr noundef %1) #3
  %.not18 = icmp eq i32 %15, %11
  br i1 %.not18, label %16, label %.lr.ph.preheader

16:                                               ; preds = %13
  %17 = call i32 @mp_int_mul(ptr noundef nonnull %3, ptr noundef nonnull %5, ptr noundef nonnull %3) #3
  %.not19 = icmp eq i32 %17, %11
  br i1 %.not19, label %18, label %.lr.ph.preheader

18:                                               ; preds = %16
  %19 = call i32 @mp_int_mul(ptr noundef nonnull %14, ptr noundef nonnull %4, ptr noundef nonnull %14) #3
  %.not20 = icmp eq i32 %19, %11
  br i1 %.not20, label %20, label %.lr.ph.preheader

20:                                               ; preds = %18
  %21 = call i32 @mp_int_compare_unsigned(ptr noundef nonnull %3, ptr noundef nonnull %14) #3
  br label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %16, %18, %13, %20
  %.015.ph = phi i32 [ %21, %20 ], [ 2147483647, %18 ], [ 2147483647, %16 ], [ 2147483647, %13 ]
  %.0.ph = phi i64 [ 2, %20 ], [ 2, %18 ], [ 2, %16 ], [ 1, %13 ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %.0.ph, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %22 = getelementptr inbounds %struct.mpz, ptr %3, i64 %indvars.iv.next
  call void @mp_int_clear(ptr noundef nonnull %22) #3
  %23 = icmp ugt i64 %indvars.iv, 1
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %10
  %.01525 = phi i32 [ 2147483647, %10 ], [ %.015.ph, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #3
  br label %24

24:                                               ; preds = %._crit_edge, %8
  %.016 = phi i32 [ %9, %8 ], [ %.01525, %._crit_edge ]
  ret i32 %.016
}

declare i32 @mp_int_compare_unsigned(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass