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

; 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.4 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1
@__func__.set_cap_and_ephemeral = external hidden unnamed_addr constant [22 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

declare ptr @ast_from(ptr noundef, i32 noundef) #1

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

declare i32 @ast_id(ptr noundef) #1

declare ptr @ast_append(ptr noundef, ptr noundef) #1

declare void @ast_get_children(ptr noundef, i64 noundef, ptr noundef) #1

declare ptr @ast_setid(ptr noundef, i32 noundef) #1

declare ptr @ast_child(ptr noundef) #1

declare ptr @ast_sibling(ptr noundef) #1

declare ptr @ast_dup(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @set_cap_and_ephemeral(ptr noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca [6 x ptr], align 16
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca [4 x ptr], align 16
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call i32 @ast_id(ptr noundef %19)
  switch i32 %20, label %88 [
    i32 149, label %21
    i32 56, label %21
    i32 150, label %21
    i32 151, label %42
    i32 187, label %63
    i32 17, label %82
  ]

21:                                               ; preds = %3, %3, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call ptr @ast_child(ptr noundef %22)
  store ptr %23, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = call i32 @ast_id(ptr noundef %25)
  %27 = call ptr @ast_from(ptr noundef %24, i32 noundef %26)
  store ptr %27, ptr %5, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %31, %21
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %40

31:                                               ; preds = %28
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = call ptr @set_cap_and_ephemeral(ptr noundef %33, i32 noundef %34, i32 noundef %35)
  %37 = call ptr @ast_append(ptr noundef %32, ptr noundef %36)
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = call ptr @ast_sibling(ptr noundef %38)
  store ptr %39, ptr %8, align 8, !tbaa !5
  br label %28, !llvm.loop !11

40:                                               ; preds = %28
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %41, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %90

42:                                               ; preds = %3
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = call ptr @ast_dup(ptr noundef %43)
  store ptr %44, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 48, ptr %14) #3
  store ptr %9, ptr %14, align 8, !tbaa !5
  %45 = getelementptr inbounds ptr, ptr %14, i64 1
  store ptr %10, ptr %45, align 8, !tbaa !5
  %46 = getelementptr inbounds ptr, ptr %14, i64 2
  store ptr %11, ptr %46, align 8, !tbaa !5
  %47 = getelementptr inbounds ptr, ptr %14, i64 3
  store ptr %12, ptr %47, align 8, !tbaa !5
  %48 = getelementptr inbounds ptr, ptr %14, i64 4
  store ptr %13, ptr %48, align 8, !tbaa !5
  %49 = getelementptr inbounds ptr, ptr %14, i64 5
  store ptr null, ptr %49, align 8, !tbaa !5
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds [6 x ptr], ptr %14, i64 0, i64 0
  call void @ast_get_children(ptr noundef %50, i64 noundef 5, ptr noundef %51)
  call void @llvm.lifetime.end.p0(i64 48, ptr %14) #3
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = icmp ne i32 %52, 2
  br i1 %53, label %54, label %58

54:                                               ; preds = %42
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = call ptr @ast_setid(ptr noundef %55, i32 noundef %56)
  br label %58

58:                                               ; preds = %54, %42
  %59 = load ptr, ptr %13, align 8, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = call ptr @ast_setid(ptr noundef %59, i32 noundef %60)
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %62, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  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 8, ptr %9) #3
  br label %90

63:                                               ; preds = %3
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = call ptr @ast_dup(ptr noundef %64)
  store ptr %65, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %18) #3
  store ptr %15, ptr %18, align 8, !tbaa !5
  %66 = getelementptr inbounds ptr, ptr %18, i64 1
  store ptr %16, ptr %66, align 8, !tbaa !5
  %67 = getelementptr inbounds ptr, ptr %18, i64 2
  store ptr %17, ptr %67, align 8, !tbaa !5
  %68 = getelementptr inbounds ptr, ptr %18, i64 3
  store ptr null, ptr %68, align 8, !tbaa !5
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds [4 x ptr], ptr %18, i64 0, i64 0
  call void @ast_get_children(ptr noundef %69, i64 noundef 3, ptr noundef %70)
  call void @llvm.lifetime.end.p0(i64 32, ptr %18) #3
  %71 = load i32, ptr %6, align 4, !tbaa !9
  %72 = icmp ne i32 %71, 2
  br i1 %72, label %73, label %77

73:                                               ; preds = %63
  %74 = load ptr, ptr %16, align 8, !tbaa !5
  %75 = load i32, ptr %6, align 4, !tbaa !9
  %76 = call ptr @ast_setid(ptr noundef %74, i32 noundef %75)
  br label %77

77:                                               ; preds = %73, %63
  %78 = load ptr, ptr %17, align 8, !tbaa !5
  %79 = load i32, ptr %7, align 4, !tbaa !9
  %80 = call ptr @ast_setid(ptr noundef %78, i32 noundef %79)
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %81, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  br label %90

82:                                               ; preds = %3
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = call ptr @ast_childidx(ptr noundef %83, i64 noundef 1)
  %85 = load i32, ptr %6, align 4, !tbaa !9
  %86 = load i32, ptr %7, align 4, !tbaa !9
  %87 = call ptr @set_cap_and_ephemeral(ptr noundef %84, i32 noundef %85, i32 noundef %86)
  store ptr %87, ptr %4, align 8
  br label %90

88:                                               ; preds = %3
  br label %89

89:                                               ; preds = %88
  call void @ponyint_assert_fail(ptr noundef @.str.6, ptr noundef @.str.4, i64 noundef 455, ptr noundef @__func__.set_cap_and_ephemeral)
  store ptr null, ptr %4, align 8
  br label %90

90:                                               ; preds = %89, %82, %77, %58, %40
  %91 = load ptr, ptr %4, align 8
  ret ptr %91
}

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

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

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


; 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.4 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1
@__func__.set_cap_and_ephemeral = external hidden unnamed_addr constant [22 x i8], align 1

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

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

declare ptr @ast_from(ptr noundef, i32 noundef) local_unnamed_addr #1

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

declare i32 @ast_id(ptr noundef) local_unnamed_addr #1

declare ptr @ast_append(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @ast_get_children(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

declare ptr @ast_setid(ptr noundef, i32 noundef) local_unnamed_addr #1

declare ptr @ast_child(ptr noundef) local_unnamed_addr #1

declare ptr @ast_sibling(ptr noundef) local_unnamed_addr #1

declare ptr @ast_dup(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @set_cap_and_ephemeral(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca [6 x ptr], align 16
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca [4 x ptr], align 16
  br label %tailrecurse

tailrecurse:                                      ; preds = %46, %3
  %.tr = phi ptr [ %0, %3 ], [ %47, %46 ]
  %14 = tail call i32 @ast_id(ptr noundef %.tr) #3
  switch i32 %14, label %48 [
    i32 149, label %15
    i32 56, label %15
    i32 150, label %15
    i32 151, label %22
    i32 187, label %35
    i32 17, label %46
  ]

15:                                               ; preds = %tailrecurse, %tailrecurse, %tailrecurse
  %16 = tail call ptr @ast_child(ptr noundef %.tr) #3
  %17 = tail call i32 @ast_id(ptr noundef %.tr) #3
  %18 = tail call ptr @ast_from(ptr noundef %.tr, i32 noundef %17) #3
  %.not2935 = icmp eq ptr %16, null
  br i1 %.not2935, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %15, %.lr.ph
  %.036 = phi ptr [ %21, %.lr.ph ], [ %16, %15 ]
  %19 = tail call ptr @set_cap_and_ephemeral(ptr noundef nonnull %.036, i32 noundef %1, i32 noundef %2)
  %20 = tail call ptr @ast_append(ptr noundef %18, ptr noundef %19) #3
  %21 = tail call ptr @ast_sibling(ptr noundef nonnull %.036) #3
  %.not29 = icmp eq ptr %21, null
  br i1 %.not29, label %.loopexit, label %.lr.ph, !llvm.loop !5

22:                                               ; preds = %tailrecurse
  %23 = tail call ptr @ast_dup(ptr noundef %.tr) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #3
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %9) #3
  store ptr %4, ptr %9, align 16, !tbaa !7
  %24 = getelementptr inbounds i8, ptr %9, i64 8
  store ptr %5, ptr %24, align 8, !tbaa !7
  %25 = getelementptr inbounds i8, ptr %9, i64 16
  store ptr %6, ptr %25, align 16, !tbaa !7
  %26 = getelementptr inbounds i8, ptr %9, i64 24
  store ptr %7, ptr %26, align 8, !tbaa !7
  %27 = getelementptr inbounds i8, ptr %9, i64 32
  store ptr %8, ptr %27, align 16, !tbaa !7
  %28 = getelementptr inbounds i8, ptr %9, i64 40
  store ptr null, ptr %28, align 8, !tbaa !7
  call void @ast_get_children(ptr noundef %23, i64 noundef 5, ptr noundef nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %9) #3
  %.not28 = icmp eq i32 %1, 2
  br i1 %.not28, label %32, label %29

29:                                               ; preds = %22
  %30 = load ptr, ptr %7, align 8, !tbaa !7
  %31 = call ptr @ast_setid(ptr noundef %30, i32 noundef %1) #3
  br label %32

32:                                               ; preds = %29, %22
  %33 = load ptr, ptr %8, align 8, !tbaa !7
  %34 = call ptr @ast_setid(ptr noundef %33, i32 noundef %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  br label %.loopexit

35:                                               ; preds = %tailrecurse
  %36 = tail call ptr @ast_dup(ptr noundef %.tr) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %12) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %13) #3
  store ptr %10, ptr %13, align 16, !tbaa !7
  %37 = getelementptr inbounds i8, ptr %13, i64 8
  store ptr %11, ptr %37, align 8, !tbaa !7
  %38 = getelementptr inbounds i8, ptr %13, i64 16
  store ptr %12, ptr %38, align 16, !tbaa !7
  %39 = getelementptr inbounds i8, ptr %13, i64 24
  store ptr null, ptr %39, align 8, !tbaa !7
  call void @ast_get_children(ptr noundef %36, i64 noundef 3, ptr noundef nonnull %13) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %13) #3
  %.not = icmp eq i32 %1, 2
  br i1 %.not, label %43, label %40

40:                                               ; preds = %35
  %41 = load ptr, ptr %11, align 8, !tbaa !7
  %42 = call ptr @ast_setid(ptr noundef %41, i32 noundef %1) #3
  br label %43

43:                                               ; preds = %40, %35
  %44 = load ptr, ptr %12, align 8, !tbaa !7
  %45 = call ptr @ast_setid(ptr noundef %44, i32 noundef %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #3
  br label %.loopexit

46:                                               ; preds = %tailrecurse
  %47 = tail call ptr @ast_childidx(ptr noundef %.tr, i64 noundef 1) #3
  br label %tailrecurse

48:                                               ; preds = %tailrecurse
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.4, i64 noundef 455, ptr noundef nonnull @__func__.set_cap_and_ephemeral) #3
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %15, %48, %43, %32
  %.026 = phi ptr [ null, %48 ], [ %36, %43 ], [ %23, %32 ], [ %18, %15 ], [ %18, %.lr.ph ]
  ret ptr %.026
}

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

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

!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 = !{!8, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}


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