; 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.19 = external hidden unnamed_addr constant [48 x i8], align 1
@__PRETTY_FUNCTION__.mp_int_read_unsigned = external hidden unnamed_addr constant [61 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 i32 @s_pad(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @mp_int_zero(ptr noundef) #2

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

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

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

17:                                               ; preds = %14
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  br label %22

21:                                               ; preds = %17, %14, %3
  call void @__assert_fail(ptr noundef @.str.19, ptr noundef @.str.1, i32 noundef 1919, ptr noundef @__PRETTY_FUNCTION__.mp_int_read_unsigned) #4
  unreachable

22:                                               ; preds = %20
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = mul nsw i32 %23, 8
  %25 = sext i32 %24 to i64
  %26 = add i64 %25, 31
  %27 = udiv i64 %26, 32
  %28 = trunc i64 %27 to i32
  store i32 %28, ptr %8, align 4, !tbaa !9
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = call i32 @s_pad(ptr noundef %29, i32 noundef %30)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %22
  store i32 -2, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %58

34:                                               ; preds = %22
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  call void @mp_int_zero(ptr noundef %35)
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %36, ptr %10, align 8, !tbaa !5
  %37 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %37, ptr %9, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %52, %34
  %39 = load i32, ptr %9, align 4, !tbaa !9
  %40 = icmp ugt i32 %39, 0
  br i1 %40, label %41, label %57

41:                                               ; preds = %38
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = call i32 @s_qmul(ptr noundef %42, i32 noundef 8)
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = load i8, ptr %44, align 1, !tbaa !11
  %46 = zext i8 %45 to i32
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.mpz, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !12
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = or i32 %50, %46
  store i32 %51, ptr %49, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %41
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = add i32 %53, -1
  store i32 %54, ptr %9, align 4, !tbaa !9
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %55, i32 1
  store ptr %56, ptr %10, align 8, !tbaa !5
  br label %38, !llvm.loop !14

57:                                               ; preds = %38
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %58

58:                                               ; preds = %57, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %59 = load i32, ptr %4, align 4
  ret i32 %59
}

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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 8}
!13 = !{!"mpz", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !7, i64 24}
!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"

@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [48 x i8], align 1
@__PRETTY_FUNCTION__.mp_int_read_unsigned = external hidden unnamed_addr constant [61 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 i32 @s_pad(ptr noundef, i32 noundef) local_unnamed_addr #1

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

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

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

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

8:                                                ; preds = %3
  %9 = shl nsw i32 %2, 3
  %narrow = add nuw i32 %9, 31
  %10 = lshr i32 %narrow, 5
  %11 = tail call i32 @s_pad(ptr noundef nonnull %0, i32 noundef %10)
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %.loopexit, label %12

12:                                               ; preds = %8
  tail call void @mp_int_zero(ptr noundef nonnull %0)
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  br label %14

14:                                               ; preds = %12, %14
  %.025 = phi ptr [ %1, %12 ], [ %22, %14 ]
  %.01824 = phi i32 [ %2, %12 ], [ %21, %14 ]
  %15 = tail call i32 @s_qmul(ptr noundef nonnull %0, i32 noundef 8)
  %16 = load i8, ptr %.025, align 1, !tbaa !5
  %17 = zext i8 %16 to i32
  %18 = load ptr, ptr %13, align 8, !tbaa !8
  %19 = load i32, ptr %18, align 4, !tbaa !12
  %20 = or i32 %19, %17
  store i32 %20, ptr %18, align 4, !tbaa !12
  %21 = add nsw i32 %.01824, -1
  %22 = getelementptr inbounds i8, ptr %.025, i64 1
  %.not23 = icmp eq i32 %21, 0
  br i1 %.not23, label %.loopexit, label %14, !llvm.loop !13

.loopexit:                                        ; preds = %14, %8
  %.019 = phi i32 [ -2, %8 ], [ 0, %14 ]
  ret i32 %.019
}

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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !11, i64 8}
!9 = !{!"mpz", !10, i64 0, !11, i64 8, !10, i64 16, !10, i64 20, !6, i64 24}
!10 = !{!"int", !6, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!10, !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass