; 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 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@__PRETTY_FUNCTION__.mp_int_to_int = external hidden unnamed_addr constant [44 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
define dso_local i32 @mp_int_to_int(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  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) #3
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  br label %15

14:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1620, ptr noundef @__PRETTY_FUNCTION__.mp_int_to_int) #4
  unreachable

15:                                               ; preds = %13
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.mpz, ptr %16, i32 0, i32 4
  %18 = load i8, ptr %17, align 8, !tbaa !11
  store i8 %18, ptr %9, align 1, !tbaa !14
  %19 = load i8, ptr %9, align 1, !tbaa !14
  %20 = zext i8 %19 to i32
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %26

22:                                               ; preds = %15
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = call i32 @mp_int_compare_value(ptr noundef %23, i64 noundef 9223372036854775807)
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %30, label %26

26:                                               ; preds = %22, %15
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = call i32 @mp_int_compare_value(ptr noundef %27, i64 noundef -9223372036854775808)
  %29 = icmp slt i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %26, %22
  store i32 -3, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %73

31:                                               ; preds = %26
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.mpz, ptr %32, i32 0, i32 3
  %34 = load i32, ptr %33, align 4, !tbaa !15
  store i32 %34, ptr %7, align 4, !tbaa !16
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.mpz, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  %38 = load i32, ptr %7, align 4, !tbaa !16
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds i32, ptr %37, i64 %39
  %41 = getelementptr inbounds i32, ptr %40, i64 -1
  store ptr %41, ptr %8, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %45, %31
  %43 = load i32, ptr %7, align 4, !tbaa !16
  %44 = icmp ugt i32 %43, 0
  br i1 %44, label %45, label %57

45:                                               ; preds = %42
  %46 = load i64, ptr %6, align 8, !tbaa !9
  %47 = shl i64 %46, 16
  store i64 %47, ptr %6, align 8, !tbaa !9
  %48 = load i64, ptr %6, align 8, !tbaa !9
  %49 = shl i64 %48, 16
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = getelementptr inbounds i32, ptr %50, i32 -1
  store ptr %51, ptr %8, align 8, !tbaa !5
  %52 = load i32, ptr %50, align 4, !tbaa !16
  %53 = zext i32 %52 to i64
  %54 = or i64 %49, %53
  store i64 %54, ptr %6, align 8, !tbaa !9
  %55 = load i32, ptr %7, align 4, !tbaa !16
  %56 = add i32 %55, -1
  store i32 %56, ptr %7, align 4, !tbaa !16
  br label %42, !llvm.loop !18

57:                                               ; preds = %42
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %72

60:                                               ; preds = %57
  %61 = load i8, ptr %9, align 1, !tbaa !14
  %62 = zext i8 %61 to i32
  %63 = icmp eq i32 %62, 1
  br i1 %63, label %64, label %67

64:                                               ; preds = %60
  %65 = load i64, ptr %6, align 8, !tbaa !9
  %66 = sub i64 0, %65
  br label %69

67:                                               ; preds = %60
  %68 = load i64, ptr %6, align 8, !tbaa !9
  br label %69

69:                                               ; preds = %67, %64
  %70 = phi i64 [ %66, %64 ], [ %68, %67 ]
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %70, ptr %71, align 8, !tbaa !9
  br label %72

72:                                               ; preds = %69, %57
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %73

73:                                               ; preds = %72, %30
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %74 = load i32, ptr %3, align 4
  ret i32 %74
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @mp_int_compare_value(ptr noundef, i64 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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !7, i64 24}
!12 = !{!"mpz", !13, i64 0, !6, i64 8, !13, i64 16, !13, i64 20, !7, i64 24}
!13 = !{!"int", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!12, !13, i64 20}
!16 = !{!13, !13, i64 0}
!17 = !{!12, !6, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"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"

@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@__PRETTY_FUNCTION__.mp_int_to_int = external hidden unnamed_addr constant [44 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
define dso_local range(i32 -3, 1) i32 @mp_int_to_int(ptr noundef %0, ptr noundef writeonly %1) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %3, label %4

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

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i8, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i8 %6, 0
  br i1 %7, label %8, label %11

8:                                                ; preds = %4
  %9 = tail call i32 @mp_int_compare_value(ptr noundef nonnull %0, i64 noundef 9223372036854775807)
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %36, label %11

11:                                               ; preds = %8, %4
  %12 = tail call i32 @mp_int_compare_value(ptr noundef nonnull %0, i64 noundef -9223372036854775808)
  %13 = icmp slt i32 %12, 0
  br i1 %13, label %36, label %14

14:                                               ; preds = %11
  %15 = getelementptr inbounds i8, ptr %0, i64 20
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %.not2325 = icmp eq i32 %16, 0
  br i1 %.not2325, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %14
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %19 = zext i32 %16 to i64
  %20 = getelementptr inbounds i32, ptr %18, i64 %19
  %xtraiter = and i32 %16, 3
  %21 = icmp ult i32 %16, 4
  br i1 %21, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %16, -4
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.pn28 = phi ptr [ %20, %.lr.ph.preheader.new ], [ %.018.3, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %.018.3 = getelementptr inbounds i8, ptr %.pn28, i64 -16
  %niter.next.3 = add i32 %niter, 4
  %niter.ncmp.3 = icmp eq i32 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa.loopexit, label %.lr.ph, !llvm.loop !13

._crit_edge.loopexit.unr-lcssa.loopexit:          ; preds = %.lr.ph
  %.018.2 = getelementptr inbounds i8, ptr %.pn28, i64 -12
  %22 = load i32, ptr %.018.2, align 4, !tbaa !15
  %23 = zext i32 %22 to i64
  %24 = shl nuw i64 %23, 32
  %25 = load i32, ptr %.018.3, align 4, !tbaa !15
  %26 = zext i32 %25 to i64
  %27 = or disjoint i64 %24, %26
  br label %._crit_edge.loopexit.unr-lcssa

._crit_edge.loopexit.unr-lcssa:                   ; preds = %._crit_edge.loopexit.unr-lcssa.loopexit, %.lr.ph.preheader
  %.lcssa.ph = phi i64 [ poison, %.lr.ph.preheader ], [ %27, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.pn28.unr = phi ptr [ %20, %.lr.ph.preheader ], [ %.018.3, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.02026.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %27, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.pn28.epil = phi ptr [ %.018.epil, %.lr.ph.epil ], [ %.pn28.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.02026.epil = phi i64 [ %31, %.lr.ph.epil ], [ %.02026.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %.018.epil = getelementptr inbounds i8, ptr %.pn28.epil, i64 -4
  %28 = shl i64 %.02026.epil, 32
  %29 = load i32, ptr %.018.epil, align 4, !tbaa !15
  %30 = zext i32 %29 to i64
  %31 = or disjoint i64 %28, %30
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !16

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %14
  %.020.lcssa = phi i64 [ 0, %14 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %31, %.lr.ph.epil ]
  %.not24 = icmp eq ptr %1, null
  br i1 %.not24, label %36, label %32

32:                                               ; preds = %._crit_edge
  %33 = icmp eq i8 %6, 1
  %34 = sub i64 0, %.020.lcssa
  %35 = select i1 %33, i64 %34, i64 %.020.lcssa
  store i64 %35, ptr %1, align 8, !tbaa !18
  br label %36

36:                                               ; preds = %._crit_edge, %32, %8, %11
  %.0 = phi i32 [ -3, %11 ], [ -3, %8 ], [ 0, %32 ], [ 0, %._crit_edge ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @mp_int_compare_value(ptr noundef, i64 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 = { 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, !8, i64 24}
!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, !7, i64 20}
!12 = !{!6, !10, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.unroll.disable"}
!18 = !{!19, !19, i64 0}
!19 = !{!"long", !8, i64 0}


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