; LLVM IR from Tiramisu-Compiler/tiramisu :: 3rdParty/isl/imath (imath)

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

@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [54 x i8], align 1
@__PRETTY_FUNCTION__.mp_int_invmod = external hidden unnamed_addr constant [48 x i8], align 1

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

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

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @mp_int_clear(ptr noundef) #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mp_int_invmod(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %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 i8, align 1
  %10 = alloca [2 x %struct.mpz], align 16
  %11 = alloca i32, align 4
  %12 = 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 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 64, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %22

15:                                               ; preds = %3
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %22

18:                                               ; preds = %15
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  br label %23

22:                                               ; preds = %18, %15, %3
  call void @__assert_fail(ptr noundef @.str.13, ptr noundef @.str.1, i32 noundef 1275, ptr noundef @__PRETTY_FUNCTION__.mp_int_invmod) #4
  unreachable

23:                                               ; preds = %21
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.mpz, ptr %24, i32 0, i32 3
  %26 = load i32, ptr %25, align 4, !tbaa !11
  %27 = icmp eq i32 %26, 1
  br i1 %27, label %28, label %36

28:                                               ; preds = %23
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.mpz, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = getelementptr inbounds i32, ptr %31, i64 0
  %33 = load i32, ptr %32, align 4, !tbaa !9
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %28
  br label %44

36:                                               ; preds = %28, %23
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.mpz, ptr %37, i32 0, i32 4
  %39 = load i8, ptr %38, align 8, !tbaa !14
  %40 = zext i8 %39 to i32
  %41 = icmp eq i32 %40, 1
  %42 = zext i1 %41 to i64
  %43 = select i1 %41, i32 -1, i32 1
  br label %44

44:                                               ; preds = %36, %35
  %45 = phi i32 [ 0, %35 ], [ %43, %36 ]
  %46 = icmp eq i32 %45, 0
  br i1 %46, label %71, label %47

47:                                               ; preds = %44
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.mpz, ptr %48, i32 0, i32 3
  %50 = load i32, ptr %49, align 4, !tbaa !11
  %51 = icmp eq i32 %50, 1
  br i1 %51, label %52, label %60

52:                                               ; preds = %47
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.mpz, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !13
  %56 = getelementptr inbounds i32, ptr %55, i64 0
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = icmp eq i32 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %52
  br label %68

60:                                               ; preds = %52, %47
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.mpz, ptr %61, i32 0, i32 4
  %63 = load i8, ptr %62, align 8, !tbaa !14
  %64 = zext i8 %63 to i32
  %65 = icmp eq i32 %64, 1
  %66 = zext i1 %65 to i64
  %67 = select i1 %65, i32 -1, i32 1
  br label %68

68:                                               ; preds = %60, %59
  %69 = phi i32 [ 0, %59 ], [ %67, %60 ]
  %70 = icmp sle i32 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %68, %44
  store i32 -3, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %141

72:                                               ; preds = %68
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.mpz, ptr %73, i32 0, i32 4
  %75 = load i8, ptr %74, align 8, !tbaa !14
  store i8 %75, ptr %9, align 1, !tbaa !15
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %76

76:                                               ; preds = %85, %72
  %77 = load i32, ptr %11, align 4, !tbaa !9
  %78 = icmp slt i32 %77, 2
  br i1 %78, label %79, label %88

79:                                               ; preds = %76
  %80 = getelementptr inbounds [2 x %struct.mpz], ptr %10, i64 0, i64 0
  %81 = load i32, ptr %11, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds %struct.mpz, ptr %80, i64 %82
  %84 = call i32 @mp_int_init(ptr noundef %83)
  br label %85

85:                                               ; preds = %79
  %86 = load i32, ptr %11, align 4, !tbaa !9
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %11, align 4, !tbaa !9
  br label %76, !llvm.loop !16

88:                                               ; preds = %76
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = getelementptr inbounds [2 x %struct.mpz], ptr %10, i64 0, i64 0
  %92 = getelementptr inbounds %struct.mpz, ptr %91, i64 0
  %93 = getelementptr inbounds [2 x %struct.mpz], ptr %10, i64 0, i64 0
  %94 = getelementptr inbounds %struct.mpz, ptr %93, i64 1
  %95 = call i32 @mp_int_egcd(ptr noundef %89, ptr noundef %90, ptr noundef %92, ptr noundef %94, ptr noundef null)
  store i32 %95, ptr %8, align 4, !tbaa !9
  %96 = icmp ne i32 %95, 0
  br i1 %96, label %97, label %98

97:                                               ; preds = %88
  br label %129

98:                                               ; preds = %88
  %99 = getelementptr inbounds [2 x %struct.mpz], ptr %10, i64 0, i64 0
  %100 = getelementptr inbounds %struct.mpz, ptr %99, i64 0
  %101 = call i32 @mp_int_compare_value(ptr noundef %100, i64 noundef 1)
  %102 = icmp ne i32 %101, 0
  br i1 %102, label %103, label %104

103:                                              ; preds = %98
  store i32 -4, ptr %8, align 4, !tbaa !9
  br label %129

104:                                              ; preds = %98
  %105 = getelementptr inbounds [2 x %struct.mpz], ptr %10, i64 0, i64 0
  %106 = getelementptr inbounds %struct.mpz, ptr %105, i64 1
  %107 = load ptr, ptr %6, align 8, !tbaa !5
  %108 = getelementptr inbounds [2 x %struct.mpz], ptr %10, i64 0, i64 0
  %109 = getelementptr inbounds %struct.mpz, ptr %108, i64 1
  %110 = call i32 @mp_int_mod(ptr noundef %106, ptr noundef %107, ptr noundef %109)
  store i32 %110, ptr %8, align 4, !tbaa !9
  %111 = icmp ne i32 %110, 0
  br i1 %111, label %112, label %113

112:                                              ; preds = %104
  br label %129

113:                                              ; preds = %104
  %114 = load i8, ptr %9, align 1, !tbaa !15
  %115 = zext i8 %114 to i32
  %116 = icmp eq i32 %115, 1
  br i1 %116, label %117, label %123

117:                                              ; preds = %113
  %118 = load ptr, ptr %6, align 8, !tbaa !5
  %119 = getelementptr inbounds [2 x %struct.mpz], ptr %10, i64 0, i64 0
  %120 = getelementptr inbounds %struct.mpz, ptr %119, i64 1
  %121 = load ptr, ptr %7, align 8, !tbaa !5
  %122 = call i32 @mp_int_sub(ptr noundef %118, ptr noundef %120, ptr noundef %121)
  store i32 %122, ptr %8, align 4, !tbaa !9
  br label %128

123:                                              ; preds = %113
  %124 = getelementptr inbounds [2 x %struct.mpz], ptr %10, i64 0, i64 0
  %125 = getelementptr inbounds %struct.mpz, ptr %124, i64 1
  %126 = load ptr, ptr %7, align 8, !tbaa !5
  %127 = call i32 @mp_int_copy(ptr noundef %125, ptr noundef %126)
  store i32 %127, ptr %8, align 4, !tbaa !9
  br label %128

128:                                              ; preds = %123, %117
  br label %129

129:                                              ; preds = %128, %112, %103, %97
  br label %130

130:                                              ; preds = %134, %129
  %131 = load i32, ptr %11, align 4, !tbaa !9
  %132 = add nsw i32 %131, -1
  store i32 %132, ptr %11, align 4, !tbaa !9
  %133 = icmp sge i32 %132, 0
  br i1 %133, label %134, label %139

134:                                              ; preds = %130
  %135 = getelementptr inbounds [2 x %struct.mpz], ptr %10, i64 0, i64 0
  %136 = load i32, ptr %11, align 4, !tbaa !9
  %137 = sext i32 %136 to i64
  %138 = getelementptr inbounds %struct.mpz, ptr %135, i64 %137
  call void @mp_int_clear(ptr noundef %138)
  br label %130, !llvm.loop !18

139:                                              ; preds = %130
  %140 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %140, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %141

141:                                              ; preds = %139, %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %142 = load i32, ptr %4, align 4
  ret i32 %142
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @mp_int_egcd(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { noreturn nounwind "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 }
attributes #4 = { noreturn 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 = !{!12, !10, i64 20}
!12 = !{!"mpz", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !7, i64 24}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !7, i64 24}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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

@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [54 x i8], align 1
@__PRETTY_FUNCTION__.mp_int_invmod = external hidden unnamed_addr constant [48 x i8], align 1

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

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

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @mp_int_clear(ptr noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mp_int_invmod(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca [2 x %struct.mpz], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %4) #3
  %5 = icmp ne ptr %0, null
  %6 = icmp ne ptr %1, null
  %or.cond = and i1 %5, %6
  %7 = icmp ne ptr %2, null
  %or.cond3 = and i1 %or.cond, %7
  br i1 %or.cond3, label %9, label %8

8:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.13, ptr noundef nonnull @.str.1, i32 noundef 1275, ptr noundef nonnull @__PRETTY_FUNCTION__.mp_int_invmod) #4
  unreachable

9:                                                ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 20
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 1
  br i1 %12, label %13, label %.critedge

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = load i32, ptr %15, align 4, !tbaa !12
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %.critedge37, label %.critedge

.critedge:                                        ; preds = %13, %9
  %18 = getelementptr inbounds i8, ptr %1, i64 20
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = icmp eq i32 %19, 1
  br i1 %20, label %21, label %26

21:                                               ; preds = %.critedge
  %22 = getelementptr inbounds i8, ptr %1, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = load i32, ptr %23, align 4, !tbaa !12
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %.critedge37, label %26

26:                                               ; preds = %21, %.critedge
  %27 = getelementptr inbounds i8, ptr %1, i64 24
  %28 = load i8, ptr %27, align 8, !tbaa !13
  %29 = icmp eq i8 %28, 1
  br i1 %29, label %.critedge37, label %30

30:                                               ; preds = %26
  %31 = getelementptr inbounds i8, ptr %0, i64 24
  %32 = load i8, ptr %31, align 8, !tbaa !13
  %33 = call i32 @mp_int_init(ptr noundef nonnull %4)
  %34 = getelementptr inbounds i8, ptr %4, i64 32
  %35 = call i32 @mp_int_init(ptr noundef nonnull %34)
  %36 = call i32 @mp_int_egcd(ptr noundef nonnull %0, ptr noundef nonnull %1, ptr noundef nonnull %4, ptr noundef nonnull %34, ptr noundef null)
  %.not = icmp eq i32 %36, 0
  br i1 %.not, label %37, label %.critedge37.loopexit

37:                                               ; preds = %30
  %38 = call i32 @mp_int_compare_value(ptr noundef nonnull %4, i64 noundef 1)
  %.not34 = icmp eq i32 %38, 0
  br i1 %.not34, label %39, label %.critedge37.loopexit

39:                                               ; preds = %37
  %40 = call i32 @mp_int_mod(ptr noundef nonnull %34, ptr noundef nonnull %1, ptr noundef nonnull %34)
  %.not35 = icmp eq i32 %40, 0
  br i1 %.not35, label %41, label %.critedge37.loopexit

41:                                               ; preds = %39
  %42 = icmp eq i8 %32, 1
  br i1 %42, label %43, label %45

43:                                               ; preds = %41
  %44 = call i32 @mp_int_sub(ptr noundef nonnull %1, ptr noundef nonnull %34, ptr noundef nonnull %2)
  br label %.critedge37.loopexit

45:                                               ; preds = %41
  %46 = call i32 @mp_int_copy(ptr noundef nonnull %34, ptr noundef nonnull %2)
  br label %.critedge37.loopexit

.critedge37.loopexit:                             ; preds = %37, %43, %45, %39, %30
  %.027 = phi i32 [ %36, %30 ], [ %40, %39 ], [ %44, %43 ], [ %46, %45 ], [ -4, %37 ]
  call void @mp_int_clear(ptr noundef nonnull %34)
  call void @mp_int_clear(ptr noundef nonnull %4)
  br label %.critedge37

.critedge37:                                      ; preds = %.critedge37.loopexit, %21, %26, %13
  %.026 = phi i32 [ -3, %13 ], [ -3, %26 ], [ -3, %21 ], [ %.027, %.critedge37.loopexit ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %4) #3
  ret i32 %.026
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @mp_int_egcd(ptr noundef, ptr noundef, ptr noundef, 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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { noreturn nounwind "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 }
attributes #4 = { noreturn 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, !7, i64 20}
!6 = !{!"mpz", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 20, !8, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !8, i64 24}


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