; 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_set_cap = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @typeparam_constraint(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @typeparam_set_cap(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 [4 x ptr], align 16
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = call i32 @ast_id(ptr noundef %9)
  %11 = icmp eq i32 %10, 187
  br i1 %11, label %12, label %13

12:                                               ; preds = %1
  br label %14

13:                                               ; preds = %1
  call void @ponyint_assert_fail(ptr noundef @.str, ptr noundef @.str.1, i64 noundef 546, ptr noundef @__func__.typeparam_set_cap)
  br label %14

14:                                               ; preds = %13, %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %6) #3
  store ptr %3, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds ptr, ptr %6, i64 1
  store ptr %4, ptr %15, align 8, !tbaa !5
  %16 = getelementptr inbounds ptr, ptr %6, i64 2
  store ptr %5, ptr %16, align 8, !tbaa !5
  %17 = getelementptr inbounds ptr, ptr %6, i64 3
  store ptr null, ptr %17, align 8, !tbaa !5
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds [4 x ptr], ptr %6, i64 0, i64 0
  call void @ast_get_children(ptr noundef %18, i64 noundef 3, ptr noundef %19)
  call void @llvm.lifetime.end.p0(i64 32, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = call ptr @typeparam_constraint(ptr noundef %20)
  store ptr %21, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = call i32 @cap_from_constraint(ptr noundef %22)
  store i32 %23, ptr %8, align 4, !tbaa !9
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = call ptr @ast_setid(ptr noundef %24, i32 noundef %25)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  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 void
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @cap_from_constraint(ptr noundef) #0

declare ptr @ast_setid(ptr noundef, i32 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


; 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_set_cap = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @typeparam_constraint(ptr noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @typeparam_set_cap(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [4 x ptr], align 16
  %6 = tail call i32 @ast_id(ptr noundef %0) #3
  %7 = icmp eq i32 %6, 187
  br i1 %7, label %9, label %8

8:                                                ; preds = %1
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i64 noundef 546, ptr noundef nonnull @__func__.typeparam_set_cap) #3
  br label %9

9:                                                ; preds = %1, %8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #3
  store ptr %2, ptr %5, align 16, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %3, ptr %10, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %5, i64 16
  store ptr %4, ptr %11, align 16, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %5, i64 24
  store ptr null, ptr %12, align 8, !tbaa !5
  call void @ast_get_children(ptr noundef %0, i64 noundef 3, ptr noundef nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #3
  %13 = call ptr @typeparam_constraint(ptr noundef %0)
  %14 = call i32 @cap_from_constraint(ptr noundef %13)
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = call ptr @ast_setid(ptr noundef %15, i32 noundef %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  ret void
}

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

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

declare ptr @ast_setid(ptr noundef, i32 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 = { mustprogress 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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass