; LLVM IR from ponylang/ponyc :: src/libponyc/type (subtype)

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

@.str.1 = external hidden unnamed_addr constant [76 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [2 x i8], align 1
@__func__.is_entity = external hidden unnamed_addr constant [10 x i8], align 1

declare i32 @ast_id(ptr noundef) #0

declare void @ponyint_assert_fail(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #0

declare ptr @ast_childidx(ptr noundef, i64 noundef) #0

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

declare ptr @ast_child(ptr noundef) #0

declare ptr @ast_sibling(ptr noundef) #0

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

declare ptr @ast_data(ptr noundef) #0

declare ptr @typeparam_constraint(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @is_entity(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  store i1 false, ptr %3, align 1
  br label %68

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call i32 @ast_id(ptr noundef %14)
  switch i32 %15, label %66 [
    i32 150, label %16
    i32 149, label %17
    i32 56, label %33
    i32 151, label %49
    i32 17, label %56
    i32 187, label %61
  ]

16:                                               ; preds = %13
  store i1 false, ptr %3, align 1
  br label %68

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = call ptr @ast_child(ptr noundef %18)
  store ptr %19, ptr %6, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %28, %17
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %31

23:                                               ; preds = %20
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = call zeroext i1 @is_entity(ptr noundef %24, i32 noundef %25)
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %32

28:                                               ; preds = %23
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call ptr @ast_sibling(ptr noundef %29)
  store ptr %30, ptr %6, align 8, !tbaa !5
  br label %20, !llvm.loop !11

31:                                               ; preds = %20
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %32

32:                                               ; preds = %31, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %68

33:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = call ptr @ast_child(ptr noundef %34)
  store ptr %35, ptr %8, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %44, %33
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %47

39:                                               ; preds = %36
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = call zeroext i1 @is_entity(ptr noundef %40, i32 noundef %41)
  br i1 %42, label %43, label %44

43:                                               ; preds = %39
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %48

44:                                               ; preds = %39
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = call ptr @ast_sibling(ptr noundef %45)
  store ptr %46, ptr %8, align 8, !tbaa !5
  br label %36, !llvm.loop !13

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

48:                                               ; preds = %47, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %68

49:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = call ptr @ast_data(ptr noundef %50)
  store ptr %51, ptr %9, align 8, !tbaa !5
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = call i32 @ast_id(ptr noundef %52)
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = icmp eq i32 %53, %54
  store i1 %55, ptr %3, align 1
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %68

56:                                               ; preds = %13
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = call ptr @ast_childidx(ptr noundef %57, i64 noundef 1)
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = call zeroext i1 @is_entity(ptr noundef %58, i32 noundef %59)
  store i1 %60, ptr %3, align 1
  br label %68

61:                                               ; preds = %13
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = call ptr @typeparam_constraint(ptr noundef %62)
  %64 = load i32, ptr %5, align 4, !tbaa !9
  %65 = call zeroext i1 @is_entity(ptr noundef %63, i32 noundef %64)
  store i1 %65, ptr %3, align 1
  br label %68

66:                                               ; preds = %13
  br label %67

67:                                               ; preds = %66
  call void @ponyint_assert_fail(ptr noundef @.str.24, ptr noundef @.str.1, i64 noundef 2201, ptr noundef @__func__.is_entity)
  store i1 false, ptr %3, align 1
  br label %68

68:                                               ; preds = %67, %61, %56, %49, %48, %32, %16, %12
  %69 = load i1, ptr %3, align 1
  ret i1 %69
}

attributes #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 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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 [76 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [2 x i8], align 1
@__func__.is_entity = external hidden unnamed_addr constant [10 x i8], align 1

declare i32 @ast_id(ptr noundef) local_unnamed_addr #0

declare void @ponyint_assert_fail(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

declare ptr @ast_childidx(ptr noundef, i64 noundef) local_unnamed_addr #0

declare ptr @ast_child(ptr noundef) local_unnamed_addr #0

declare ptr @ast_sibling(ptr noundef) local_unnamed_addr #0

declare ptr @ast_data(ptr noundef) local_unnamed_addr #0

declare ptr @typeparam_constraint(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @is_entity(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %2, %tailrecurse.backedge
  %.tr31 = phi ptr [ %.tr.be, %tailrecurse.backedge ], [ %0, %2 ]
  %4 = tail call i32 @ast_id(ptr noundef nonnull %.tr31) #2
  switch i32 %4, label %24 [
    i32 150, label %.loopexit
    i32 149, label %5
    i32 56, label %10
    i32 151, label %15
    i32 17, label %19
    i32 187, label %22
  ]

5:                                                ; preds = %.lr.ph
  %6 = tail call ptr @ast_child(ptr noundef nonnull %.tr31) #2
  %.not2237 = icmp eq ptr %6, null
  br i1 %.not2237, label %.loopexit, label %.lr.ph39

.lr.ph39:                                         ; preds = %5, %8
  %.02038 = phi ptr [ %9, %8 ], [ %6, %5 ]
  %7 = tail call zeroext i1 @is_entity(ptr noundef nonnull %.02038, i32 noundef %1)
  br i1 %7, label %8, label %.loopexit

8:                                                ; preds = %.lr.ph39
  %9 = tail call ptr @ast_sibling(ptr noundef nonnull %.02038) #2
  %.not22 = icmp eq ptr %9, null
  br i1 %.not22, label %.loopexit, label %.lr.ph39, !llvm.loop !5

10:                                               ; preds = %.lr.ph
  %11 = tail call ptr @ast_child(ptr noundef nonnull %.tr31) #2
  %.not.not32 = icmp eq ptr %11, null
  br i1 %.not.not32, label %.loopexit, label %.lr.ph34

.lr.ph34:                                         ; preds = %10, %13
  %.01933 = phi ptr [ %14, %13 ], [ %11, %10 ]
  %12 = tail call zeroext i1 @is_entity(ptr noundef nonnull %.01933, i32 noundef %1)
  br i1 %12, label %.loopexit, label %13

13:                                               ; preds = %.lr.ph34
  %14 = tail call ptr @ast_sibling(ptr noundef nonnull %.01933) #2
  %.not.not = icmp eq ptr %14, null
  br i1 %.not.not, label %.loopexit, label %.lr.ph34, !llvm.loop !7

15:                                               ; preds = %.lr.ph
  %16 = tail call ptr @ast_data(ptr noundef nonnull %.tr31) #2
  %17 = tail call i32 @ast_id(ptr noundef %16) #2
  %18 = icmp eq i32 %17, %1
  br label %.loopexit

19:                                               ; preds = %.lr.ph
  %20 = tail call ptr @ast_childidx(ptr noundef nonnull %.tr31, i64 noundef 1) #2
  br label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %19, %22
  %.tr.be = phi ptr [ %20, %19 ], [ %23, %22 ]
  %21 = icmp eq ptr %.tr.be, null
  br i1 %21, label %.loopexit, label %.lr.ph

22:                                               ; preds = %.lr.ph
  %23 = tail call ptr @typeparam_constraint(ptr noundef nonnull %.tr31) #2
  br label %tailrecurse.backedge

24:                                               ; preds = %.lr.ph
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.24, ptr noundef nonnull @.str.1, i64 noundef 2201, ptr noundef nonnull @__func__.is_entity) #2
  br label %.loopexit

.loopexit:                                        ; preds = %tailrecurse.backedge, %.lr.ph, %13, %.lr.ph34, %8, %.lr.ph39, %2, %10, %5, %24, %15
  %.2 = phi i1 [ false, %24 ], [ %18, %15 ], [ true, %5 ], [ false, %10 ], [ false, %2 ], [ %7, %.lr.ph39 ], [ %7, %8 ], [ %12, %.lr.ph34 ], [ %12, %13 ], [ false, %.lr.ph ], [ false, %tailrecurse.backedge ]
  ret i1 %.2
}

attributes #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 = { 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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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