; LLVM IR from ponylang/ponyc :: src/libponyrt/lang (lsda)

; 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.lsda_t = type { i64, i64, i64, i64, ptr, ptr, ptr, i8, i8 }

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @ponyint_lsda_scan(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.lsda_t, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, 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 64, ptr %6) #2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call zeroext i1 @lsda_init(ptr noundef %6, ptr noundef %12)
  br i1 %13, label %15, label %14

14:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %61

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %16 = getelementptr inbounds %struct.lsda_t, ptr %6, i32 0, i32 5
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  store ptr %17, ptr %8, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %58, %15
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.lsda_t, ptr %6, i32 0, i32 6
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  %22 = icmp ult ptr %19, %21
  br i1 %22, label %23, label %59

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %24 = getelementptr inbounds %struct.lsda_t, ptr %6, i32 0, i32 8
  %25 = load i8, ptr %24, align 1, !tbaa !13
  %26 = call i64 @read_encoded_ptr(ptr noundef %8, i8 noundef zeroext %25)
  store i64 %26, ptr %9, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %27 = getelementptr inbounds %struct.lsda_t, ptr %6, i32 0, i32 8
  %28 = load i8, ptr %27, align 1, !tbaa !13
  %29 = call i64 @read_encoded_ptr(ptr noundef %8, i8 noundef zeroext %28)
  store i64 %29, ptr %10, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %30 = getelementptr inbounds %struct.lsda_t, ptr %6, i32 0, i32 8
  %31 = load i8, ptr %30, align 1, !tbaa !13
  %32 = call i64 @read_encoded_ptr(ptr noundef %8, i8 noundef zeroext %31)
  store i64 %32, ptr %11, align 8, !tbaa !14
  %33 = call i64 @read_uleb128(ptr noundef %8)
  %34 = load i64, ptr %9, align 8, !tbaa !14
  %35 = getelementptr inbounds %struct.lsda_t, ptr %6, i32 0, i32 2
  %36 = load i64, ptr %35, align 8, !tbaa !15
  %37 = icmp ule i64 %34, %36
  br i1 %37, label %38, label %55

38:                                               ; preds = %23
  %39 = getelementptr inbounds %struct.lsda_t, ptr %6, i32 0, i32 2
  %40 = load i64, ptr %39, align 8, !tbaa !15
  %41 = load i64, ptr %9, align 8, !tbaa !14
  %42 = load i64, ptr %10, align 8, !tbaa !14
  %43 = add i64 %41, %42
  %44 = icmp ult i64 %40, %43
  br i1 %44, label %45, label %55

45:                                               ; preds = %38
  %46 = load i64, ptr %11, align 8, !tbaa !14
  %47 = icmp eq i64 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %45
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %56

49:                                               ; preds = %45
  %50 = getelementptr inbounds %struct.lsda_t, ptr %6, i32 0, i32 3
  %51 = load i64, ptr %50, align 8, !tbaa !16
  %52 = load i64, ptr %11, align 8, !tbaa !14
  %53 = add i64 %51, %52
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %53, ptr %54, align 8, !tbaa !14
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %56

55:                                               ; preds = %38, %23
  store i32 0, ptr %7, align 4
  br label %56

56:                                               ; preds = %55, %49, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  %57 = load i32, ptr %7, align 4
  switch i32 %57, label %60 [
    i32 0, label %58
  ]

58:                                               ; preds = %56
  br label %18, !llvm.loop !17

59:                                               ; preds = %18
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %60

60:                                               ; preds = %59, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %61

61:                                               ; preds = %60, %14
  call void @llvm.lifetime.end.p0(i64 64, ptr %6) #2
  %62 = load i1, ptr %3, align 1
  ret i1 %62
}

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @lsda_init(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i64 @read_encoded_ptr(ptr noundef, i8 noundef zeroext) #0

; Function Attrs: nounwind uwtable
declare hidden i64 @read_uleb128(ptr noundef) #0

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !6, i64 40}
!10 = !{!"lsda_t", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !7, i64 56, !7, i64 57}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !6, i64 48}
!13 = !{!10, !7, i64 57}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 16}
!16 = !{!10, !11, i64 24}
!17 = distinct !{!17, !18}
!18 = !{!"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"

%struct.lsda_t = type { i64, i64, i64, i64, ptr, ptr, ptr, i8, i8 }

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @ponyint_lsda_scan(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = alloca %struct.lsda_t, align 8
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %3) #2
  %5 = call zeroext i1 @lsda_init(ptr noundef nonnull %3, ptr noundef %0)
  br i1 %5, label %6, label %33

6:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #2
  %7 = getelementptr inbounds i8, ptr %3, i64 40
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %8, ptr %4, align 8, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %3, i64 48
  %10 = getelementptr inbounds i8, ptr %3, i64 57
  %11 = getelementptr inbounds i8, ptr %3, i64 16
  br label %12

12:                                               ; preds = %16, %6
  %13 = load ptr, ptr %4, align 8, !tbaa !11
  %14 = load ptr, ptr %9, align 8, !tbaa !12
  %15 = icmp ult ptr %13, %14
  br i1 %15, label %16, label %.thread

16:                                               ; preds = %12
  %17 = load i8, ptr %10, align 1, !tbaa !13
  %18 = call i64 @read_encoded_ptr(ptr noundef nonnull %4, i8 noundef zeroext %17)
  %19 = load i8, ptr %10, align 1, !tbaa !13
  %20 = call i64 @read_encoded_ptr(ptr noundef nonnull %4, i8 noundef zeroext %19)
  %21 = load i8, ptr %10, align 1, !tbaa !13
  %22 = call i64 @read_encoded_ptr(ptr noundef nonnull %4, i8 noundef zeroext %21)
  %23 = call i64 @read_uleb128(ptr noundef nonnull %4)
  %24 = load i64, ptr %11, align 8, !tbaa !14
  %.not = icmp ule i64 %18, %24
  %25 = add i64 %20, %18
  %26 = icmp ult i64 %24, %25
  %or.cond = select i1 %.not, i1 %26, i1 false
  br i1 %or.cond, label %27, label %12, !llvm.loop !15

27:                                               ; preds = %16
  %28 = icmp eq i64 %22, 0
  br i1 %28, label %.thread, label %29

29:                                               ; preds = %27
  %30 = getelementptr inbounds i8, ptr %3, i64 24
  %31 = load i64, ptr %30, align 8, !tbaa !17
  %32 = add i64 %31, %22
  store i64 %32, ptr %1, align 8, !tbaa !18
  br label %.thread

.thread:                                          ; preds = %12, %27, %29
  %.2 = phi i1 [ false, %27 ], [ true, %29 ], [ false, %12 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #2
  br label %33

33:                                               ; preds = %2, %.thread
  %.3 = phi i1 [ %.2, %.thread ], [ false, %2 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #2
  ret i1 %.3
}

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @lsda_init(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i64 @read_encoded_ptr(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i64 @read_uleb128(ptr noundef) local_unnamed_addr #0

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !10, i64 40}
!6 = !{!"lsda_t", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !8, i64 56, !8, i64 57}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !10, i64 48}
!13 = !{!6, !8, i64 57}
!14 = !{!6, !7, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!6, !7, i64 24}
!18 = !{!7, !7, i64 0}


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