; 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
@MP_TRUNC = 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_set_value(ptr noundef, i64 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_compare_zero(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mp_rat_read_cstring(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.mpq, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = call i32 @mp_int_read_cstring(ptr noundef %14, i32 noundef %15, ptr noundef %16, ptr noundef %11)
  store i32 %17, ptr %10, 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 %26

20:                                               ; preds = %4
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = load i32, ptr @MP_TRUNC, align 4, !tbaa !9
  %23 = icmp ne i32 %21, %22
  br i1 %23, label %24, label %26

24:                                               ; preds = %20
  %25 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %25, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %81

26:                                               ; preds = %20, %4
  br label %27

27:                                               ; preds = %39, %26
  %28 = call ptr @__ctype_b_loc() #5
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = load i8, ptr %30, align 1, !tbaa !11
  %32 = zext i8 %31 to i32
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i16, ptr %29, i64 %33
  %35 = load i16, ptr %34, align 2, !tbaa !12
  %36 = zext i16 %35 to i32
  %37 = and i32 %36, 8192
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %42

39:                                               ; preds = %27
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i32 1
  store ptr %41, ptr %11, align 8, !tbaa !5
  br label %27, !llvm.loop !14

42:                                               ; preds = %27
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  %44 = load i8, ptr %43, align 1, !tbaa !11
  %45 = sext i8 %44 to i32
  %46 = icmp ne i32 %45, 47
  br i1 %46, label %47, label %58

47:                                               ; preds = %42
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.mpq, ptr %48, i32 0, i32 1
  %50 = call i32 @mp_int_set_value(ptr noundef %49, i64 noundef 1)
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %56

53:                                               ; preds = %47
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %54, ptr %55, align 8, !tbaa !5
  br label %56

56:                                               ; preds = %53, %47
  %57 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %57, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %81

58:                                               ; preds = %42
  %59 = load ptr, ptr %11, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i32 1
  store ptr %60, ptr %11, align 8, !tbaa !5
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.mpq, ptr %61, i32 0, i32 1
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = call i32 @mp_int_read_cstring(ptr noundef %62, i32 noundef %63, ptr noundef %64, ptr noundef %65)
  store i32 %66, ptr %10, 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 = %58
  %70 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %70, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %81

71:                                               ; preds = %58
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.mpq, ptr %72, i32 0, i32 1
  %74 = call i32 @mp_int_compare_zero(ptr noundef %73)
  %75 = icmp eq i32 %74, 0
  br i1 %75, label %76, label %78

76:                                               ; preds = %71
  %77 = load i32, ptr @MP_UNDEF, align 4, !tbaa !9
  store i32 %77, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %81

78:                                               ; preds = %71
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = call i32 @s_rat_reduce(ptr noundef %79)
  store i32 %80, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %81

81:                                               ; preds = %78, %76, %69, %56, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %82 = load i32, ptr %5, align 4
  ret i32 %82
}

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() #3

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 willreturn memory(none) "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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(none) }

!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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@MP_OK = external local_unnamed_addr constant i32, align 4
@MP_UNDEF = external local_unnamed_addr constant i32, align 4
@MP_TRUNC = 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_set_value(ptr noundef, i64 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_compare_zero(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mp_rat_read_cstring(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %6 = call i32 @mp_int_read_cstring(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef nonnull %5) #4
  %7 = load i32, ptr @MP_OK, align 4, !tbaa !5
  %.not = icmp eq i32 %6, %7
  %8 = load i32, ptr @MP_TRUNC, align 4
  %.not18 = icmp eq i32 %6, %8
  %or.cond = select i1 %.not, i1 true, i1 %.not18
  br i1 %or.cond, label %.preheader, label %41

.preheader:                                       ; preds = %4
  %9 = tail call ptr @__ctype_b_loc() #5
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !9
  %12 = load i8, ptr %11, align 1, !tbaa !11
  %13 = zext i8 %12 to i64
  %14 = getelementptr inbounds i16, ptr %10, i64 %13
  %15 = load i16, ptr %14, align 2, !tbaa !12
  %16 = and i16 %15, 8192
  %.not1924 = icmp eq i16 %16, 0
  br i1 %.not1924, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %17 = phi ptr [ %18, %.lr.ph ], [ %11, %.preheader ]
  %18 = getelementptr inbounds i8, ptr %17, i64 1
  store ptr %18, ptr %5, align 8, !tbaa !9
  %19 = load ptr, ptr %9, align 8, !tbaa !9
  %20 = load i8, ptr %18, align 1, !tbaa !11
  %21 = zext i8 %20 to i64
  %22 = getelementptr inbounds i16, ptr %19, i64 %21
  %23 = load i16, ptr %22, align 2, !tbaa !12
  %24 = and i16 %23, 8192
  %.not19 = icmp eq i16 %24, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.lcssa23 = phi ptr [ %11, %.preheader ], [ %18, %.lr.ph ]
  %.lcssa = phi i8 [ %12, %.preheader ], [ %20, %.lr.ph ]
  %.not20 = icmp eq i8 %.lcssa, 47
  br i1 %.not20, label %30, label %25

25:                                               ; preds = %._crit_edge
  %26 = getelementptr inbounds i8, ptr %0, i64 32
  %27 = call i32 @mp_int_set_value(ptr noundef nonnull %26, i64 noundef 1) #4
  %.not22 = icmp eq ptr %3, null
  br i1 %.not22, label %41, label %28

28:                                               ; preds = %25
  %29 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %29, ptr %3, align 8, !tbaa !9
  br label %41

30:                                               ; preds = %._crit_edge
  %31 = getelementptr inbounds i8, ptr %.lcssa23, i64 1
  store ptr %31, ptr %5, align 8, !tbaa !9
  %32 = getelementptr inbounds i8, ptr %0, i64 32
  %33 = call i32 @mp_int_read_cstring(ptr noundef nonnull %32, i32 noundef %1, ptr noundef nonnull %31, ptr noundef %3) #4
  %.not21 = icmp eq i32 %33, %7
  br i1 %.not21, label %34, label %41

34:                                               ; preds = %30
  %35 = call i32 @mp_int_compare_zero(ptr noundef nonnull %32) #4
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %39

37:                                               ; preds = %34
  %38 = load i32, ptr @MP_UNDEF, align 4, !tbaa !5
  br label %41

39:                                               ; preds = %34
  %40 = call i32 @s_rat_reduce(ptr noundef %0)
  br label %41

41:                                               ; preds = %30, %25, %28, %4, %39, %37
  %.0 = phi i32 [ %38, %37 ], [ %40, %39 ], [ %6, %4 ], [ %6, %28 ], [ %6, %25 ], [ %33, %30 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  ret i32 %.0
}

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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() local_unnamed_addr #3

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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(none) }

!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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass