; 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_binary = external hidden unnamed_addr constant [59 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
declare hidden void @s_2comp(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @mp_int_read_binary(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 ptr, align 8
  %12 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %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 i32, ptr %7, align 4, !tbaa !9
  %20 = icmp sgt i32 %19, 0
  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.19, ptr noundef @.str.1, i32 noundef 1857, ptr noundef @__PRETTY_FUNCTION__.mp_int_read_binary) #4
  unreachable

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

34:                                               ; preds = %23
  store i32 -2, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %81

35:                                               ; preds = %23
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  call void @mp_int_zero(ptr noundef %36)
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 0
  %39 = load i8, ptr %38, align 1, !tbaa !11
  %40 = zext i8 %39 to i32
  %41 = ashr i32 %40, 7
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %48

43:                                               ; preds = %35
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.mpz, ptr %44, i32 0, i32 4
  store i8 1, ptr %45, align 8, !tbaa !12
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !9
  call void @s_2comp(ptr noundef %46, i32 noundef %47)
  br label %48

48:                                               ; preds = %43, %35
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.mpz, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !14
  store ptr %51, ptr %11, align 8, !tbaa !5
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %52, ptr %10, align 8, !tbaa !5
  %53 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %53, ptr %9, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %66, %48
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = icmp ugt i32 %55, 0
  br i1 %56, label %57, label %71

57:                                               ; preds = %54
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = call i32 @s_qmul(ptr noundef %58, i32 noundef 8)
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = load i8, ptr %60, align 1, !tbaa !11
  %62 = zext i8 %61 to i32
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = or i32 %64, %62
  store i32 %65, ptr %63, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %57
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = add i32 %67, -1
  store i32 %68, ptr %9, align 4, !tbaa !9
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = getelementptr inbounds i8, ptr %69, i32 1
  store ptr %70, ptr %10, align 8, !tbaa !5
  br label %54, !llvm.loop !15

71:                                               ; preds = %54
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.mpz, ptr %72, i32 0, i32 4
  %74 = load i8, ptr %73, align 8, !tbaa !12
  %75 = zext i8 %74 to i32
  %76 = icmp eq i32 %75, 1
  br i1 %76, label %77, label %80

77:                                               ; preds = %71
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = load i32, ptr %7, align 4, !tbaa !9
  call void @s_2comp(ptr noundef %78, i32 noundef %79)
  br label %80

80:                                               ; preds = %77, %71
  store i32 0, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %81

81:                                               ; preds = %80, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  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
  %82 = load i32, ptr %4, align 4
  ret i32 %82
}

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, !7, i64 24}
!13 = !{!"mpz", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !7, i64 24}
!14 = !{!13, !6, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"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_binary = external hidden unnamed_addr constant [59 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
declare hidden void @s_2comp(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -2, 1) i32 @mp_int_read_binary(ptr noundef %0, ptr noundef %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 1857, ptr noundef nonnull @__PRETTY_FUNCTION__.mp_int_read_binary) #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 %32, label %12

12:                                               ; preds = %8
  tail call void @mp_int_zero(ptr noundef nonnull %0)
  %13 = load i8, ptr %1, align 1, !tbaa !5
  %.not31 = icmp sgt i8 %13, -1
  br i1 %.not31, label %16, label %14

14:                                               ; preds = %12
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  store i8 1, ptr %15, align 8, !tbaa !8
  tail call void @s_2comp(ptr noundef nonnull %1, i32 noundef %2)
  br label %16

16:                                               ; preds = %14, %12
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  br label %19

19:                                               ; preds = %16, %19
  %.02634 = phi ptr [ %1, %16 ], [ %26, %19 ]
  %.02733 = phi i32 [ %2, %16 ], [ %25, %19 ]
  %20 = tail call i32 @s_qmul(ptr noundef nonnull %0, i32 noundef 8)
  %21 = load i8, ptr %.02634, align 1, !tbaa !5
  %22 = zext i8 %21 to i32
  %23 = load i32, ptr %18, align 4, !tbaa !13
  %24 = or i32 %23, %22
  store i32 %24, ptr %18, align 4, !tbaa !13
  %25 = add nsw i32 %.02733, -1
  %26 = getelementptr inbounds i8, ptr %.02634, i64 1
  %.not32 = icmp eq i32 %25, 0
  br i1 %.not32, label %27, label %19, !llvm.loop !14

27:                                               ; preds = %19
  %28 = getelementptr inbounds i8, ptr %0, i64 24
  %29 = load i8, ptr %28, align 8, !tbaa !8
  %30 = icmp eq i8 %29, 1
  br i1 %30, label %31, label %32

31:                                               ; preds = %27
  tail call void @s_2comp(ptr noundef nonnull %1, i32 noundef %2)
  br label %32

32:                                               ; preds = %27, %31, %8
  %.0 = phi i32 [ -2, %8 ], [ 0, %31 ], [ 0, %27 ]
  ret i32 %.0
}

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, !6, i64 24}
!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 = !{!9, !11, i64 8}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass