; 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_top_type = external hidden unnamed_addr constant [12 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

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

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

16:                                               ; preds = %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call i32 @ast_id(ptr noundef %17)
  switch i32 %18, label %84 [
    i32 149, label %19
    i32 56, label %19
    i32 151, label %36
    i32 17, label %62
    i32 150, label %83
    i32 187, label %83
    i32 153, label %83
    i32 157, label %83
    i32 158, label %83
    i32 156, label %83
  ]

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

22:                                               ; preds = %31, %19
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %34

25:                                               ; preds = %22
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load i8, ptr %5, align 1, !tbaa !9, !range !11, !noundef !12
  %28 = trunc i8 %27 to i1
  %29 = call zeroext i1 @is_top_type(ptr noundef %26, i1 noundef zeroext %28)
  br i1 %29, label %31, label %30

30:                                               ; preds = %25
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %35

31:                                               ; preds = %25
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = call ptr @ast_sibling(ptr noundef %32)
  store ptr %33, ptr %6, align 8, !tbaa !5
  br label %22, !llvm.loop !13

34:                                               ; preds = %22
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %35

35:                                               ; preds = %34, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %86

36:                                               ; preds = %16
  %37 = load i8, ptr %5, align 1, !tbaa !9, !range !11, !noundef !12
  %38 = trunc i8 %37 to i1
  br i1 %38, label %45, label %39

39:                                               ; preds = %36
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = call ptr @cap_fetch(ptr noundef %40)
  %42 = call i32 @ast_id(ptr noundef %41)
  %43 = icmp ne i32 %42, 96
  br i1 %43, label %44, label %45

44:                                               ; preds = %39
  store i1 false, ptr %3, align 1
  br label %86

45:                                               ; preds = %39, %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = call ptr @ast_data(ptr noundef %46)
  store ptr %47, ptr %8, align 8, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = call i32 @ast_id(ptr noundef %48)
  %50 = icmp ne i32 %49, 72
  br i1 %50, label %51, label %52

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

52:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = call ptr @ast_childidx(ptr noundef %53, i64 noundef 4)
  store ptr %54, ptr %9, align 8, !tbaa !5
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = call i64 @ast_childcount(ptr noundef %55)
  %57 = icmp ne i64 %56, 0
  br i1 %57, label %58, label %59

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

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

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

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

62:                                               ; preds = %16
  %63 = load i8, ptr %5, align 1, !tbaa !9, !range !11, !noundef !12
  %64 = trunc i8 %63 to i1
  br i1 %64, label %65, label %69

65:                                               ; preds = %62
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = call ptr @ast_childidx(ptr noundef %66, i64 noundef 1)
  %68 = call zeroext i1 @is_top_type(ptr noundef %67, i1 noundef zeroext true)
  store i1 %68, ptr %3, align 1
  br label %86

69:                                               ; preds = %62
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = call ptr @viewpoint_lower(ptr noundef %70)
  store ptr %71, ptr %10, align 8, !tbaa !5
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = icmp eq ptr %72, null
  br i1 %73, label %74, label %75

74:                                               ; preds = %69
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %82

75:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #3
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = call zeroext i1 @is_top_type(ptr noundef %76, i1 noundef zeroext false)
  %78 = zext i1 %77 to i8
  store i8 %78, ptr %11, align 1, !tbaa !9
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  call void @ast_free_unattached(ptr noundef %79)
  %80 = load i8, ptr %11, align 1, !tbaa !9, !range !11, !noundef !12
  %81 = trunc i8 %80 to i1
  store i1 %81, ptr %3, align 1
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #3
  br label %82

82:                                               ; preds = %75, %74
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %86

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

84:                                               ; preds = %16
  br label %85

85:                                               ; preds = %84
  call void @ponyint_assert_fail(ptr noundef @.str.24, ptr noundef @.str.1, i64 noundef 2142, ptr noundef @__func__.is_top_type)
  store i1 false, ptr %3, align 1
  br label %86

86:                                               ; preds = %85, %83, %82, %65, %61, %44, %35, %15
  %87 = load i1, ptr %3, align 1
  ret i1 %87
}

declare ptr @cap_fetch(ptr noundef) #0

declare i64 @ast_childcount(ptr noundef) #0

declare ptr @viewpoint_lower(ptr noundef) #0

declare void @ast_free_unattached(ptr noundef) #0

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 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"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 [76 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [2 x i8], align 1
@__func__.is_top_type = external hidden unnamed_addr constant [12 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

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

.lr.ph.preheader:                                 ; preds = %2
  %4 = tail call i32 @ast_id(ptr noundef nonnull %0) #2
  switch i32 %4, label %.loopexit [
    i32 149, label %.loopexit58
    i32 56, label %.loopexit58
    i32 151, label %.loopexit59
    i32 17, label %5
    i32 150, label %common.ret81
    i32 187, label %common.ret81
    i32 153, label %common.ret81
    i32 157, label %common.ret81
    i32 158, label %common.ret81
    i32 156, label %common.ret81
  ]

5:                                                ; preds = %.lr.ph.preheader
  br i1 %1, label %tailrecurse.peel, label %23

tailrecurse.peel:                                 ; preds = %5
  %6 = tail call ptr @ast_childidx(ptr noundef nonnull %0, i64 noundef 1) #2
  %7 = icmp eq ptr %6, null
  br i1 %7, label %common.ret81, label %.lr.ph

.lr.ph:                                           ; preds = %tailrecurse.peel, %tailrecurse
  %.tr36 = phi ptr [ %21, %tailrecurse ], [ %6, %tailrecurse.peel ]
  %8 = tail call i32 @ast_id(ptr noundef nonnull %.tr36) #2
  switch i32 %8, label %.loopexit [
    i32 149, label %.loopexit58
    i32 56, label %.loopexit58
    i32 151, label %.loopexit59.thread
    i32 17, label %tailrecurse
    i32 150, label %common.ret81
    i32 187, label %common.ret81
    i32 153, label %common.ret81
    i32 157, label %common.ret81
    i32 158, label %common.ret81
    i32 156, label %common.ret81
  ]

.loopexit58:                                      ; preds = %.lr.ph, %.lr.ph, %.lr.ph.preheader, %.lr.ph.preheader
  %.tr2637.lcssa53 = phi i1 [ %1, %.lr.ph.preheader ], [ %1, %.lr.ph.preheader ], [ true, %.lr.ph ], [ true, %.lr.ph ]
  %.tr36.lcssa49 = phi ptr [ %0, %.lr.ph.preheader ], [ %0, %.lr.ph.preheader ], [ %.tr36, %.lr.ph ], [ %.tr36, %.lr.ph ]
  %9 = tail call ptr @ast_child(ptr noundef nonnull %.tr36.lcssa49) #2
  %.not2543 = icmp eq ptr %9, null
  br i1 %.not2543, label %common.ret81, label %.lr.ph45

.lr.ph45:                                         ; preds = %.loopexit58, %11
  %.02044 = phi ptr [ %12, %11 ], [ %9, %.loopexit58 ]
  %10 = tail call zeroext i1 @is_top_type(ptr noundef nonnull %.02044, i1 noundef zeroext %.tr2637.lcssa53)
  br i1 %10, label %11, label %common.ret81

11:                                               ; preds = %.lr.ph45
  %12 = tail call ptr @ast_sibling(ptr noundef nonnull %.02044) #2
  %.not25 = icmp eq ptr %12, null
  br i1 %.not25, label %common.ret81, label %.lr.ph45, !llvm.loop !5

.loopexit59:                                      ; preds = %.lr.ph.preheader
  br i1 %1, label %.loopexit59.thread, label %13

13:                                               ; preds = %.loopexit59
  %14 = tail call ptr @cap_fetch(ptr noundef nonnull %0) #2
  %15 = tail call i32 @ast_id(ptr noundef %14) #2
  %.not = icmp eq i32 %15, 96
  br i1 %.not, label %.loopexit59.thread, label %common.ret81

.loopexit59.thread:                               ; preds = %.lr.ph, %13, %.loopexit59
  %.tr36.lcssa5063 = phi ptr [ %0, %13 ], [ %0, %.loopexit59 ], [ %.tr36, %.lr.ph ]
  %16 = tail call ptr @ast_data(ptr noundef nonnull %.tr36.lcssa5063) #2
  %17 = tail call i32 @ast_id(ptr noundef %16) #2
  %.not23 = icmp eq i32 %17, 72
  br i1 %.not23, label %18, label %common.ret81

18:                                               ; preds = %.loopexit59.thread
  %19 = tail call ptr @ast_childidx(ptr noundef %16, i64 noundef 4) #2
  %20 = tail call i64 @ast_childcount(ptr noundef %19) #2
  %.not24 = icmp eq i64 %20, 0
  br label %common.ret81

tailrecurse:                                      ; preds = %.lr.ph
  %21 = tail call ptr @ast_childidx(ptr noundef nonnull %.tr36, i64 noundef 1) #2
  %22 = icmp eq ptr %21, null
  br i1 %22, label %common.ret81, label %.lr.ph, !llvm.loop !7

23:                                               ; preds = %5
  %24 = tail call ptr @viewpoint_lower(ptr noundef nonnull %0) #2
  %25 = icmp eq ptr %24, null
  br i1 %25, label %common.ret81, label %26

common.ret81:                                     ; preds = %23, %18, %.loopexit59.thread, %13, %.loopexit, %.loopexit58, %2, %tailrecurse.peel, %.lr.ph.preheader, %.lr.ph.preheader, %.lr.ph.preheader, %.lr.ph.preheader, %.lr.ph.preheader, %.lr.ph.preheader, %11, %.lr.ph45, %tailrecurse, %.lr.ph, %.lr.ph, %.lr.ph, %.lr.ph, %.lr.ph, %.lr.ph, %26
  %common.ret81.op = phi i1 [ %27, %26 ], [ false, %.loopexit ], [ false, %13 ], [ %.not24, %18 ], [ false, %.loopexit59.thread ], [ false, %23 ], [ true, %.loopexit58 ], [ false, %2 ], [ false, %tailrecurse.peel ], [ false, %.lr.ph.preheader ], [ false, %.lr.ph.preheader ], [ false, %.lr.ph.preheader ], [ false, %.lr.ph.preheader ], [ false, %.lr.ph.preheader ], [ false, %.lr.ph.preheader ], [ %10, %11 ], [ %10, %.lr.ph45 ], [ false, %tailrecurse ], [ false, %.lr.ph ], [ false, %.lr.ph ], [ false, %.lr.ph ], [ false, %.lr.ph ], [ false, %.lr.ph ], [ false, %.lr.ph ]
  ret i1 %common.ret81.op

26:                                               ; preds = %23
  %27 = tail call zeroext i1 @is_top_type(ptr noundef nonnull %24, i1 noundef zeroext false)
  tail call void @ast_free_unattached(ptr noundef nonnull %24) #2
  br label %common.ret81

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph.preheader
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.24, ptr noundef nonnull @.str.1, i64 noundef 2142, ptr noundef nonnull @__func__.is_top_type) #2
  br label %common.ret81
}

declare ptr @cap_fetch(ptr noundef) local_unnamed_addr #0

declare i64 @ast_childcount(ptr noundef) local_unnamed_addr #0

declare ptr @viewpoint_lower(ptr noundef) local_unnamed_addr #0

declare void @ast_free_unattached(ptr noundef) local_unnamed_addr #0

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, !8}
!8 = !{!"llvm.loop.peeled.count", i32 1}


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