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

declare i32 @mp_int_init(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @s_rat_reduce(ptr noundef) #2

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

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

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

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

15:                                               ; preds = %3
  %16 = load i32, ptr @MP_UNDEF, align 4, !tbaa !9
  store i32 %16, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %93

17:                                               ; preds = %3
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = icmp eq ptr %18, %19
  br i1 %20, label %25, label %21

21:                                               ; preds = %17
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = icmp eq ptr %22, %23
  br i1 %24, label %25, label %59

25:                                               ; preds = %21, %17
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #3
  %26 = call i32 @mp_int_init(ptr noundef %10)
  store i32 %26, ptr %8, align 4, !tbaa !9
  %27 = load i32, ptr @MP_OK, align 4, !tbaa !9
  %28 = icmp ne i32 %26, %27
  br i1 %28, label %29, label %31

29:                                               ; preds = %25
  %30 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %30, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %56

31:                                               ; preds = %25
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.mpq, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.mpq, ptr %34, i32 0, i32 1
  %36 = call i32 @mp_int_mul(ptr noundef %33, ptr noundef %35, ptr noundef %10)
  store i32 %36, ptr %8, align 4, !tbaa !9
  %37 = load i32, ptr @MP_OK, align 4, !tbaa !9
  %38 = icmp ne i32 %36, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %31
  br label %55

40:                                               ; preds = %31
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.mpq, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.mpq, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.mpq, ptr %45, i32 0, i32 1
  %47 = call i32 @mp_int_mul(ptr noundef %42, ptr noundef %44, ptr noundef %46)
  store i32 %47, ptr %8, align 4, !tbaa !9
  %48 = load i32, ptr @MP_OK, align 4, !tbaa !9
  %49 = icmp ne i32 %47, %48
  br i1 %49, label %50, label %51

50:                                               ; preds = %40
  br label %55

51:                                               ; preds = %40
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.mpq, ptr %52, i32 0, i32 0
  %54 = call i32 @mp_int_copy(ptr noundef %10, ptr noundef %53)
  store i32 %54, ptr %8, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %51, %50, %39
  call void @mp_int_clear(ptr noundef %10)
  store i32 0, ptr %9, align 4
  br label %56

56:                                               ; preds = %55, %29
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #3
  %57 = load i32, ptr %9, align 4
  switch i32 %57, label %93 [
    i32 0, label %58
  ]

58:                                               ; preds = %56
  br label %84

59:                                               ; preds = %21
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.mpq, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.mpq, ptr %62, i32 0, i32 1
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.mpq, ptr %64, i32 0, i32 0
  %66 = call i32 @mp_int_mul(ptr noundef %61, ptr noundef %63, ptr noundef %65)
  store i32 %66, ptr %8, align 4, !tbaa !9
  %67 = load i32, ptr @MP_OK, align 4, !tbaa !9
  %68 = icmp ne i32 %66, %67
  br i1 %68, label %69, label %71

69:                                               ; preds = %59
  %70 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %70, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %93

71:                                               ; preds = %59
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.mpq, ptr %72, i32 0, i32 1
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.mpq, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.mpq, ptr %76, i32 0, i32 1
  %78 = call i32 @mp_int_mul(ptr noundef %73, ptr noundef %75, ptr noundef %77)
  store i32 %78, ptr %8, align 4, !tbaa !9
  %79 = load i32, ptr @MP_OK, align 4, !tbaa !9
  %80 = icmp ne i32 %78, %79
  br i1 %80, label %81, label %83

81:                                               ; preds = %71
  %82 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %82, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %93

83:                                               ; preds = %71
  br label %84

84:                                               ; preds = %83, %58
  %85 = load i32, ptr %8, align 4, !tbaa !9
  %86 = load i32, ptr @MP_OK, align 4, !tbaa !9
  %87 = icmp ne i32 %85, %86
  br i1 %87, label %88, label %90

88:                                               ; preds = %84
  %89 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %89, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %93

90:                                               ; preds = %84
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = call i32 @s_rat_reduce(ptr noundef %91)
  store i32 %92, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %93

93:                                               ; preds = %90, %88, %81, %69, %56, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %94 = load i32, ptr %4, align 4
  ret i32 %94
}

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}


; 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
@MP_UNDEF = 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 i32 @mp_int_init(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @s_rat_reduce(ptr noundef) local_unnamed_addr #2

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

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

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_div(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca %struct.mpz, align 8
  %5 = tail call i32 @mp_rat_compare_zero(ptr noundef %1)
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %9

7:                                                ; preds = %3
  %8 = load i32, ptr @MP_UNDEF, align 4, !tbaa !5
  br label %35

9:                                                ; preds = %3
  %10 = icmp eq ptr %2, %0
  %11 = icmp eq ptr %2, %1
  %or.cond = or i1 %10, %11
  br i1 %or.cond, label %12, label %25

12:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #3
  %13 = call i32 @mp_int_init(ptr noundef nonnull %4) #3
  %14 = load i32, ptr @MP_OK, align 4, !tbaa !5
  %.not37 = icmp eq i32 %13, %14
  br i1 %.not37, label %15, label %24

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %1, i64 32
  %17 = call i32 @mp_int_mul(ptr noundef %0, ptr noundef nonnull %16, ptr noundef nonnull %4) #3
  %.not38 = icmp eq i32 %17, %13
  br i1 %.not38, label %18, label %33

18:                                               ; preds = %15
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  %20 = getelementptr inbounds i8, ptr %2, i64 32
  %21 = call i32 @mp_int_mul(ptr noundef nonnull %19, ptr noundef %1, ptr noundef nonnull %20) #3
  %.not39 = icmp eq i32 %21, %13
  br i1 %.not39, label %22, label %33

22:                                               ; preds = %18
  %23 = call i32 @mp_int_copy(ptr noundef nonnull %4, ptr noundef %2) #3
  br label %33

24:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #3
  br label %35

25:                                               ; preds = %9
  %26 = getelementptr inbounds i8, ptr %1, i64 32
  %27 = tail call i32 @mp_int_mul(ptr noundef %0, ptr noundef nonnull %26, ptr noundef %2) #3
  %28 = load i32, ptr @MP_OK, align 4, !tbaa !5
  %.not = icmp eq i32 %27, %28
  br i1 %.not, label %29, label %35

29:                                               ; preds = %25
  %30 = getelementptr inbounds i8, ptr %0, i64 32
  %31 = getelementptr inbounds i8, ptr %2, i64 32
  %32 = tail call i32 @mp_int_mul(ptr noundef nonnull %30, ptr noundef %1, ptr noundef nonnull %31) #3
  %.not36 = icmp eq i32 %32, %27
  br i1 %.not36, label %.thread42, label %35

33:                                               ; preds = %18, %15, %22
  %.024 = phi i32 [ %17, %15 ], [ %21, %18 ], [ %23, %22 ]
  call void @mp_int_clear(ptr noundef nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #3
  %.not40 = icmp eq i32 %.024, %13
  br i1 %.not40, label %.thread42, label %35

.thread42:                                        ; preds = %29, %33
  %34 = call i32 @s_rat_reduce(ptr noundef %2)
  br label %35

35:                                               ; preds = %24, %33, %29, %25, %.thread42, %7
  %.126 = phi i32 [ %8, %7 ], [ %34, %.thread42 ], [ %13, %24 ], [ %27, %25 ], [ %32, %29 ], [ %.024, %33 ]
  ret i32 %.126
}

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


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