; 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

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

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

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

declare i32 @mp_int_add(ptr noundef, 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_add_int(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 %struct.mpz, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  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 32, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = call i32 @mp_int_init_copy(ptr noundef %8, ptr noundef %11)
  store i32 %12, ptr %9, align 4, !tbaa !9
  %13 = load i32, ptr @MP_OK, align 4, !tbaa !9
  %14 = icmp ne i32 %12, %13
  br i1 %14, label %15, label %17

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

17:                                               ; preds = %3
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.mpq, ptr %18, i32 0, i32 1
  %20 = call i32 @mp_int_mul(ptr noundef %8, ptr noundef %19, ptr noundef %8)
  store i32 %20, ptr %9, align 4, !tbaa !9
  %21 = load i32, ptr @MP_OK, align 4, !tbaa !9
  %22 = icmp ne i32 %20, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %17
  br label %43

24:                                               ; preds = %17
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = call i32 @mp_rat_copy(ptr noundef %25, ptr noundef %26)
  store i32 %27, ptr %9, align 4, !tbaa !9
  %28 = load i32, ptr @MP_OK, align 4, !tbaa !9
  %29 = icmp ne i32 %27, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %24
  br label %43

31:                                               ; preds = %24
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.mpq, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.mpq, ptr %34, i32 0, i32 0
  %36 = call i32 @mp_int_add(ptr noundef %33, ptr noundef %8, ptr noundef %35)
  store i32 %36, ptr %9, 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 %43

40:                                               ; preds = %31
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = call i32 @s_rat_reduce(ptr noundef %41)
  store i32 %42, ptr %9, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %40, %39, %30, %23
  call void @mp_int_clear(ptr noundef %8)
  %44 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %44, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %45

45:                                               ; preds = %43, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #3
  %46 = load i32, ptr %4, align 4
  ret i32 %46
}

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

; 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

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

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

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

declare i32 @mp_int_add(ptr noundef, 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_add_int(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca %struct.mpz, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #3
  %5 = call i32 @mp_int_init_copy(ptr noundef nonnull %4, ptr noundef %1) #3
  %6 = load i32, ptr @MP_OK, align 4, !tbaa !5
  %.not = icmp eq i32 %5, %6
  br i1 %.not, label %7, label %17

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = call i32 @mp_int_mul(ptr noundef nonnull %4, ptr noundef nonnull %8, ptr noundef nonnull %4) #3
  %.not14 = icmp eq i32 %9, %5
  br i1 %.not14, label %10, label %16

10:                                               ; preds = %7
  %11 = call i32 @mp_rat_copy(ptr noundef %0, ptr noundef %2)
  %.not15 = icmp eq i32 %11, %5
  br i1 %.not15, label %12, label %16

12:                                               ; preds = %10
  %13 = call i32 @mp_int_add(ptr noundef %2, ptr noundef nonnull %4, ptr noundef %2) #3
  %.not16 = icmp eq i32 %13, %5
  br i1 %.not16, label %14, label %16

14:                                               ; preds = %12
  %15 = call i32 @s_rat_reduce(ptr noundef %2)
  br label %16

16:                                               ; preds = %12, %10, %7, %14
  %.0 = phi i32 [ %9, %7 ], [ %11, %10 ], [ %13, %12 ], [ %15, %14 ]
  call void @mp_int_clear(ptr noundef nonnull %4) #3
  br label %17

17:                                               ; preds = %3, %16
  %.09 = phi i32 [ %.0, %16 ], [ %5, %3 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #3
  ret i32 %.09
}

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: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass