; LLVM IR from trabucayre/openFPGALoader :: src/lattice.ll (ZN7Lattice24getUFMStartPageFromJEDECEP9JedParseri)

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

; 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: mustprogress uwtable
define dso_local noundef zeroext i16 @_ZN7Lattice24getUFMStartPageFromJEDECEP9JedParseri(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca i16, align 2
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i16, align 2
  %10 = 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
  %11 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = call noundef i64 @_ZN9JedParser18offset_for_sectionEi(ptr noundef nonnull align 8 dereferenceable(656) %12, i32 noundef %13)
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #3
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = udiv i32 %16, 128
  %18 = trunc i32 %17 to i16
  store i16 %18, ptr %9, align 2, !tbaa !11
  %19 = load i16, ptr %9, align 2, !tbaa !11
  %20 = zext i16 %19 to i32
  %21 = icmp sgt i32 %20, 9211
  br i1 %21, label %22, label %28

22:                                               ; preds = %3
  %23 = load i16, ptr %9, align 2, !tbaa !11
  %24 = zext i16 %23 to i32
  %25 = sub nsw i32 %24, 9211
  %26 = sub nsw i32 %25, 1
  %27 = trunc i32 %26 to i16
  store i16 %27, ptr %4, align 2
  store i32 1, ptr %10, align 4
  br label %65

28:                                               ; preds = %3
  %29 = load i16, ptr %9, align 2, !tbaa !11
  %30 = zext i16 %29 to i32
  %31 = icmp sgt i32 %30, 5758
  br i1 %31, label %32, label %37

32:                                               ; preds = %28
  %33 = load i16, ptr %9, align 2, !tbaa !11
  %34 = zext i16 %33 to i32
  %35 = sub nsw i32 %34, 5758
  %36 = trunc i32 %35 to i16
  store i16 %36, ptr %4, align 2
  store i32 1, ptr %10, align 4
  br label %65

37:                                               ; preds = %28
  %38 = load i16, ptr %9, align 2, !tbaa !11
  %39 = zext i16 %38 to i32
  %40 = icmp sgt i32 %39, 3198
  br i1 %40, label %41, label %46

41:                                               ; preds = %37
  %42 = load i16, ptr %9, align 2, !tbaa !11
  %43 = zext i16 %42 to i32
  %44 = sub nsw i32 %43, 3198
  %45 = trunc i32 %44 to i16
  store i16 %45, ptr %4, align 2
  store i32 1, ptr %10, align 4
  br label %65

46:                                               ; preds = %37
  %47 = load i16, ptr %9, align 2, !tbaa !11
  %48 = zext i16 %47 to i32
  %49 = icmp sgt i32 %48, 2175
  br i1 %49, label %50, label %55

50:                                               ; preds = %46
  %51 = load i16, ptr %9, align 2, !tbaa !11
  %52 = zext i16 %51 to i32
  %53 = sub nsw i32 %52, 2175
  %54 = trunc i32 %53 to i16
  store i16 %54, ptr %4, align 2
  store i32 1, ptr %10, align 4
  br label %65

55:                                               ; preds = %46
  %56 = load i16, ptr %9, align 2, !tbaa !11
  %57 = zext i16 %56 to i32
  %58 = icmp sgt i32 %57, 1151
  br i1 %58, label %59, label %64

59:                                               ; preds = %55
  %60 = load i16, ptr %9, align 2, !tbaa !11
  %61 = zext i16 %60 to i32
  %62 = sub nsw i32 %61, 1151
  %63 = trunc i32 %62 to i16
  store i16 %63, ptr %4, align 2
  store i32 1, ptr %10, align 4
  br label %65

64:                                               ; preds = %55
  store i16 -1, ptr %4, align 2
  store i32 1, ptr %10, align 4
  br label %65

65:                                               ; preds = %64, %59, %50, %41, %32, %22
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %66 = load i16, ptr %4, align 2
  ret i16 %66
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN9JedParser18offset_for_sectionEi(ptr noundef nonnull align 8 dereferenceable(656), i32 noundef) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 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 }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}


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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext range(i16 -1, -9212) i16 @_ZN7Lattice24getUFMStartPageFromJEDECEP9JedParseri(ptr nocapture noundef nonnull readnone align 8 dereferenceable(152) %0, ptr noundef nonnull %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = tail call noundef i64 @_ZN9JedParser18offset_for_sectionEi(ptr noundef nonnull align 8 dereferenceable(656) %1, i32 noundef %2)
  %5 = trunc i64 %4 to i32
  %6 = lshr i32 %5, 7
  %7 = and i32 %6, 65535
  %8 = icmp ugt i32 %7, 9211
  br i1 %8, label %9, label %12

9:                                                ; preds = %3
  %10 = trunc i32 %6 to i16
  %11 = add i16 %10, -9212
  br label %32

12:                                               ; preds = %3
  %13 = icmp ugt i32 %7, 5758
  br i1 %13, label %14, label %17

14:                                               ; preds = %12
  %15 = trunc i32 %6 to i16
  %16 = add i16 %15, -5758
  br label %32

17:                                               ; preds = %12
  %18 = icmp ugt i32 %7, 3198
  br i1 %18, label %19, label %22

19:                                               ; preds = %17
  %20 = trunc i32 %6 to i16
  %21 = add i16 %20, -3198
  br label %32

22:                                               ; preds = %17
  %23 = icmp ugt i32 %7, 2175
  br i1 %23, label %24, label %27

24:                                               ; preds = %22
  %25 = trunc i32 %6 to i16
  %26 = add i16 %25, -2175
  br label %32

27:                                               ; preds = %22
  %28 = icmp ugt i32 %7, 1151
  br i1 %28, label %29, label %32

29:                                               ; preds = %27
  %30 = trunc i32 %6 to i16
  %31 = add i16 %30, -1151
  br label %32

32:                                               ; preds = %27, %29, %24, %19, %14, %9
  %.0 = phi i16 [ %11, %9 ], [ %16, %14 ], [ %21, %19 ], [ %26, %24 ], [ %31, %29 ], [ -1, %27 ]
  ret i16 %.0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN9JedParser18offset_for_sectionEi(ptr noundef nonnull align 8 dereferenceable(656), i32 noundef) local_unnamed_addr #0 align 2

attributes #0 = { mustprogress 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" }

!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)"}


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