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

; 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 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [78 x i8], align 1
@__func__.typeparam_constraint = external hidden unnamed_addr constant [21 x i8], align 1

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

11:                                               ; preds = %1
  br label %13

12:                                               ; preds = %1
  call void @ponyint_assert_fail(ptr noundef @.str, ptr noundef @.str.1, i64 noundef 502, ptr noundef @__func__.typeparam_constraint)
  br label %13

13:                                               ; preds = %12, %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = call ptr @ast_data(ptr noundef %14)
  store ptr %15, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call ptr @ast_childidx(ptr noundef %16, i64 noundef 1)
  store ptr %17, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = call ptr @astlist_push(ptr noundef null, ptr noundef %18)
  store ptr %19, ptr %5, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %40, %13
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = call i32 @ast_id(ptr noundef %21)
  %23 = icmp eq i32 %22, 187
  br i1 %23, label %24, label %41

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = call ptr @ast_data(ptr noundef %25)
  store ptr %26, ptr %6, align 8, !tbaa !5
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = call ptr @astlist_find(ptr noundef %27, ptr noundef %28)
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %32

31:                                               ; preds = %24
  store ptr null, ptr %4, align 8, !tbaa !5
  store i32 3, ptr %7, align 4
  br label %38

32:                                               ; preds = %24
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = call ptr @astlist_push(ptr noundef %33, ptr noundef %34)
  store ptr %35, ptr %5, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = call ptr @ast_childidx(ptr noundef %36, i64 noundef 1)
  store ptr %37, ptr %4, align 8, !tbaa !5
  store i32 0, ptr %7, align 4
  br label %38

38:                                               ; preds = %32, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %39 = load i32, ptr %7, align 4
  switch i32 %39, label %44 [
    i32 0, label %40
    i32 3, label %41
  ]

40:                                               ; preds = %38
  br label %20, !llvm.loop !9

41:                                               ; preds = %38, %20
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  call void @astlist_free(ptr noundef %42)
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %43

44:                                               ; preds = %38
  unreachable
}

declare i32 @ast_id(ptr noundef) #1

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

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

declare ptr @ast_data(ptr noundef) #1

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

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

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

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

declare void @astlist_free(ptr noundef) #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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!9, !10}
!10 = !{!"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 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [78 x i8], align 1
@__func__.typeparam_constraint = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @typeparam_constraint(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @ast_id(ptr noundef %0) #2
  %3 = icmp eq i32 %2, 187
  br i1 %3, label %5, label %4

4:                                                ; preds = %1
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i64 noundef 502, ptr noundef nonnull @__func__.typeparam_constraint) #2
  br label %5

5:                                                ; preds = %1, %4
  %6 = tail call ptr @ast_data(ptr noundef %0) #2
  %7 = tail call ptr @ast_childidx(ptr noundef %6, i64 noundef 1) #2
  %8 = tail call ptr @astlist_push(ptr noundef null, ptr noundef %6) #2
  %9 = tail call i32 @ast_id(ptr noundef %7) #2
  %10 = icmp eq i32 %9, 187
  br i1 %10, label %.lr.ph, label %.thread

.lr.ph:                                           ; preds = %5, %13
  %.01322 = phi ptr [ %15, %13 ], [ %7, %5 ]
  %.01421 = phi ptr [ %14, %13 ], [ %8, %5 ]
  %11 = tail call ptr @ast_data(ptr noundef %.01322) #2
  %12 = tail call ptr @astlist_find(ptr noundef %.01421, ptr noundef %11) #2
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %13, label %.thread

13:                                               ; preds = %.lr.ph
  %14 = tail call ptr @astlist_push(ptr noundef %.01421, ptr noundef %11) #2
  %15 = tail call ptr @ast_childidx(ptr noundef %11, i64 noundef 1) #2
  %16 = tail call i32 @ast_id(ptr noundef %15) #2
  %17 = icmp eq i32 %16, 187
  br i1 %17, label %.lr.ph, label %.thread

.thread:                                          ; preds = %13, %.lr.ph, %5
  %.014.lcssa = phi ptr [ %8, %5 ], [ %.01421, %.lr.ph ], [ %14, %13 ]
  %.2 = phi ptr [ %7, %5 ], [ null, %.lr.ph ], [ %15, %13 ]
  tail call void @astlist_free(ptr noundef %.014.lcssa) #2
  ret ptr %.2
}

declare i32 @ast_id(ptr noundef) local_unnamed_addr #1

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

declare ptr @ast_data(ptr noundef) local_unnamed_addr #1

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

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

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

declare void @astlist_free(ptr noundef) local_unnamed_addr #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 = { "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)"}


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