; 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.3 = external hidden unnamed_addr constant [35 x i8], align 1
@__PRETTY_FUNCTION__.mp_int_sqr = external hidden unnamed_addr constant [37 x i8], align 1

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

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @s_free(ptr noundef) #2

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

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

20:                                               ; preds = %17
  br label %22

21:                                               ; preds = %17, %2
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 792, ptr noundef @__PRETTY_FUNCTION__.mp_int_sqr) #5
  unreachable

22:                                               ; preds = %20
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.mpz, ptr %23, i32 0, i32 3
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = add i32 %25, 1
  %27 = udiv i32 %26, 2
  %28 = mul i32 4, %27
  store i32 %28, ptr %7, align 4, !tbaa !9
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = icmp eq ptr %29, %30
  br i1 %31, label %32, label %49

32:                                               ; preds = %22
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = add i32 %33, 1
  %35 = udiv i32 %34, 2
  %36 = mul i32 2, %35
  store i32 %36, ptr %8, align 4, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = icmp ugt i32 8, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %32
  br label %42

40:                                               ; preds = %32
  %41 = load i32, ptr %8, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %40, %39
  %43 = phi i32 [ 8, %39 ], [ %41, %40 ]
  store i32 %43, ptr %8, align 4, !tbaa !9
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = call ptr @s_alloc(i32 noundef %44)
  store ptr %45, ptr %6, align 8, !tbaa !5
  %46 = icmp eq ptr %45, null
  br i1 %46, label %47, label %48

47:                                               ; preds = %42
  store i32 -2, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %138

48:                                               ; preds = %42
  br label %59

49:                                               ; preds = %22
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = call i32 @s_pad(ptr noundef %50, i32 noundef %51)
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %55, label %54

54:                                               ; preds = %49
  store i32 -2, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %138

55:                                               ; preds = %49
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.mpz, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !13
  store ptr %58, ptr %6, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %55, %48
  br label %60

60:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %61 = load i32, ptr %7, align 4, !tbaa !9
  %62 = zext i32 %61 to i64
  %63 = mul i64 %62, 4
  %64 = trunc i64 %63 to i32
  store i32 %64, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %65, ptr %11, align 8, !tbaa !5
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = load i32, ptr %10, align 4, !tbaa !9
  %68 = zext i32 %67 to i64
  call void @llvm.memset.p0.i64(ptr align 4 %66, i8 0, i64 %68, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %69

69:                                               ; preds = %60
  br label %70

70:                                               ; preds = %69
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.mpz, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !13
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.mpz, ptr %75, i32 0, i32 3
  %77 = load i32, ptr %76, align 4, !tbaa !11
  %78 = call i32 @s_ksqr(ptr noundef %73, ptr noundef %74, i32 noundef %77)
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.mpz, ptr %80, i32 0, i32 1
  %82 = load ptr, ptr %81, align 8, !tbaa !13
  %83 = icmp ne ptr %79, %82
  br i1 %83, label %84, label %101

84:                                               ; preds = %70
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.mpz, ptr %85, i32 0, i32 1
  %87 = load ptr, ptr %86, align 8, !tbaa !13
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = icmp ne ptr %87, %88
  br i1 %89, label %90, label %94

90:                                               ; preds = %84
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.mpz, ptr %91, i32 0, i32 1
  %93 = load ptr, ptr %92, align 8, !tbaa !13
  call void @s_free(ptr noundef %93)
  br label %94

94:                                               ; preds = %90, %84
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.mpz, ptr %96, i32 0, i32 1
  store ptr %95, ptr %97, align 8, !tbaa !13
  %98 = load i32, ptr %8, align 4, !tbaa !9
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.mpz, ptr %99, i32 0, i32 2
  store i32 %98, ptr %100, align 8, !tbaa !14
  br label %101

101:                                              ; preds = %94, %70
  %102 = load i32, ptr %7, align 4, !tbaa !9
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.mpz, ptr %103, i32 0, i32 3
  store i32 %102, ptr %104, align 4, !tbaa !11
  br label %105

105:                                              ; preds = %101
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %106 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %106, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %107 = load ptr, ptr %12, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.mpz, ptr %107, i32 0, i32 3
  %109 = load i32, ptr %108, align 4, !tbaa !11
  store i32 %109, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %110 = load ptr, ptr %12, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.mpz, ptr %110, i32 0, i32 1
  %112 = load ptr, ptr %111, align 8, !tbaa !13
  %113 = load i32, ptr %13, align 4, !tbaa !9
  %114 = zext i32 %113 to i64
  %115 = getelementptr inbounds i32, ptr %112, i64 %114
  %116 = getelementptr inbounds i32, ptr %115, i64 -1
  store ptr %116, ptr %14, align 8, !tbaa !5
  br label %117

117:                                              ; preds = %127, %105
  %118 = load i32, ptr %13, align 4, !tbaa !9
  %119 = icmp ugt i32 %118, 1
  br i1 %119, label %120, label %125

120:                                              ; preds = %117
  %121 = load ptr, ptr %14, align 8, !tbaa !5
  %122 = getelementptr inbounds i32, ptr %121, i32 -1
  store ptr %122, ptr %14, align 8, !tbaa !5
  %123 = load i32, ptr %121, align 4, !tbaa !9
  %124 = icmp eq i32 %123, 0
  br label %125

125:                                              ; preds = %120, %117
  %126 = phi i1 [ false, %117 ], [ %124, %120 ]
  br i1 %126, label %127, label %130

127:                                              ; preds = %125
  %128 = load i32, ptr %13, align 4, !tbaa !9
  %129 = add i32 %128, -1
  store i32 %129, ptr %13, align 4, !tbaa !9
  br label %117, !llvm.loop !15

130:                                              ; preds = %125
  %131 = load i32, ptr %13, align 4, !tbaa !9
  %132 = load ptr, ptr %12, align 8, !tbaa !5
  %133 = getelementptr inbounds %struct.mpz, ptr %132, i32 0, i32 3
  store i32 %131, ptr %133, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %134

134:                                              ; preds = %130
  br label %135

135:                                              ; preds = %134
  %136 = load ptr, ptr %5, align 8, !tbaa !5
  %137 = getelementptr inbounds %struct.mpz, ptr %136, i32 0, i32 4
  store i8 0, ptr %137, align 8, !tbaa !17
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %138

138:                                              ; preds = %135, %54, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %139 = load i32, ptr %3, align 4
  ret i32 %139
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind }
attributes #5 = { 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, !10, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!12, !7, i64 24}


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

@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [35 x i8], align 1
@__PRETTY_FUNCTION__.mp_int_sqr = external hidden unnamed_addr constant [37 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare hidden void @s_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @s_pad(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -2, 1) i32 @mp_int_sqr(ptr noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = icmp ne ptr %0, null
  %4 = icmp ne ptr %1, null
  %or.cond = and i1 %3, %4
  br i1 %or.cond, label %6, label %5

5:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 792, ptr noundef nonnull @__PRETTY_FUNCTION__.mp_int_sqr) #3
  unreachable

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 20
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = shl i32 %8, 1
  %10 = add i32 %9, 2
  %11 = and i32 %10, -4
  %12 = icmp eq ptr %0, %1
  br i1 %12, label %13, label %18

13:                                               ; preds = %6
  %14 = icmp ult i32 %10, 8
  %15 = select i1 %14, i32 8, i32 %11
  %16 = tail call ptr @s_alloc(i32 noundef %15)
  %17 = icmp eq ptr %16, null
  br i1 %17, label %47, label %23

18:                                               ; preds = %6
  %19 = tail call i32 @s_pad(ptr noundef nonnull %1, i32 noundef %11)
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %47, label %20

20:                                               ; preds = %18
  %21 = getelementptr inbounds i8, ptr %1, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  br label %23

23:                                               ; preds = %20, %13
  %.044 = phi i32 [ %15, %13 ], [ 0, %20 ]
  %.043 = phi ptr [ %16, %13 ], [ %22, %20 ]
  %24 = zext i32 %11 to i64
  %25 = shl i32 %11, 2
  %26 = zext i32 %25 to i64
  tail call void @llvm.memset.p0.i64(ptr align 4 %.043, i8 0, i64 %26, i1 false)
  %27 = getelementptr inbounds i8, ptr %0, i64 8
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = tail call i32 @s_ksqr(ptr noundef %28, ptr noundef %.043, i32 noundef %29)
  %31 = getelementptr inbounds i8, ptr %1, i64 8
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  %.not49 = icmp eq ptr %.043, %32
  br i1 %.not49, label %37, label %33

33:                                               ; preds = %23
  %.not50 = icmp eq ptr %32, %1
  br i1 %.not50, label %35, label %34

34:                                               ; preds = %33
  tail call void @s_free(ptr noundef %32)
  br label %35

35:                                               ; preds = %34, %33
  store ptr %.043, ptr %31, align 8, !tbaa !11
  %36 = getelementptr inbounds i8, ptr %1, i64 16
  store i32 %.044, ptr %36, align 8, !tbaa !12
  br label %37

37:                                               ; preds = %35, %23
  %38 = phi ptr [ %.043, %35 ], [ %32, %23 ]
  %39 = getelementptr inbounds i8, ptr %1, i64 20
  store i32 %11, ptr %39, align 4, !tbaa !5
  %.not56 = icmp eq i32 %11, 0
  br i1 %.not56, label %.critedge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %37
  %40 = getelementptr inbounds i32, ptr %38, i64 %24
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %43
  %.053.pn = phi ptr [ %.053, %43 ], [ %40, %.lr.ph.preheader ]
  %.04152 = phi i32 [ %44, %43 ], [ %11, %.lr.ph.preheader ]
  %.053 = getelementptr inbounds i8, ptr %.053.pn, i64 -4
  %41 = load i32, ptr %.053, align 4, !tbaa !13
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %.critedge

43:                                               ; preds = %.lr.ph
  %44 = add i32 %.04152, -1
  %45 = icmp ugt i32 %44, 1
  br i1 %45, label %.lr.ph, label %.critedge, !llvm.loop !14

.critedge:                                        ; preds = %.lr.ph, %43, %37
  %.041.lcssa = phi i32 [ 0, %37 ], [ 1, %43 ], [ %.04152, %.lr.ph ]
  store i32 %.041.lcssa, ptr %39, align 4, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %1, i64 24
  store i8 0, ptr %46, align 8, !tbaa !16
  br label %47

47:                                               ; preds = %18, %13, %.critedge
  %.042 = phi i32 [ 0, %.critedge ], [ -2, %13 ], [ -2, %18 ]
  ret i32 %.042
}

; Function Attrs: nounwind uwtable
declare hidden i32 @s_ksqr(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 = !{!6, !7, i64 16}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!6, !8, i64 24}


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