; LLVM IR from ponylang/ponyc :: src/libponyc/pass (flatten)

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

%struct.pass_opt_t = type { i32, i32, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i32, i64, i8, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %struct.typecheck_t, ptr, ptr }
%struct.typecheck_t = type { ptr, %struct.typecheck_stats_t, ptr }
%struct.typecheck_stats_t = type { i64, i64, i64, i64 }

@.str = external hidden unnamed_addr constant [75 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [73 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @constraint_contains_tuple(ptr noundef, ptr noundef, ptr noundef) #0

declare i32 @ast_id(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 i32 @flatten_typeparamref(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call ptr @cap_fetch(ptr noundef %13)
  store ptr %14, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = call i32 @ast_id(ptr noundef %15)
  store i32 %16, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call ptr @typeparam_constraint(ptr noundef %17)
  store ptr %18, ptr %8, align 8, !tbaa !5
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %32

21:                                               ; preds = %2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = call zeroext i1 @constraint_contains_tuple(ptr noundef %22, ptr noundef %23, ptr noundef %24)
  br i1 %25, label %26, label %32

26:                                               ; preds = %21
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.pass_opt_t, ptr %27, i32 0, i32 36
  %29 = getelementptr inbounds %struct.typecheck_t, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  call void (ptr, ptr, ptr, ...) @ast_error(ptr noundef %30, ptr noundef %31, ptr noundef @.str)
  store i32 2, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %85

32:                                               ; preds = %21, %2
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  call void @typeparam_set_cap(ptr noundef %33)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = call i32 @ast_id(ptr noundef %34)
  store i32 %35, ptr %10, align 4, !tbaa !9
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = icmp ne i32 %36, 2
  br i1 %37, label %38, label %83

38:                                               ; preds = %32
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = icmp ne i32 %39, %40
  br i1 %41, label %42, label %83

42:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = call ptr @ast_data(ptr noundef %43)
  store ptr %44, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = call ptr @typeparam_constraint(ptr noundef %45)
  store ptr %46, ptr %12, align 8, !tbaa !5
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %71

49:                                               ; preds = %42
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.pass_opt_t, ptr %50, i32 0, i32 36
  %52 = getelementptr inbounds %struct.typecheck_t, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  call void (ptr, ptr, ptr, ...) @ast_error(ptr noundef %53, ptr noundef %54, ptr noundef @.str.1)
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.pass_opt_t, ptr %55, i32 0, i32 36
  %57 = getelementptr inbounds %struct.typecheck_t, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %57, align 8, !tbaa !11
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  call void (ptr, ptr, ptr, ...) @ast_error_continue(ptr noundef %58, ptr noundef %59, ptr noundef @.str.2)
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  %61 = call ptr @ast_parent(ptr noundef %60)
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = icmp ne ptr %61, %62
  br i1 %63, label %64, label %70

64:                                               ; preds = %49
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.pass_opt_t, ptr %65, i32 0, i32 36
  %67 = getelementptr inbounds %struct.typecheck_t, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !11
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  call void (ptr, ptr, ptr, ...) @ast_error_continue(ptr noundef %68, ptr noundef %69, ptr noundef @.str.3)
  br label %70

70:                                               ; preds = %64, %49
  br label %82

71:                                               ; preds = %42
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.pass_opt_t, ptr %72, i32 0, i32 36
  %74 = getelementptr inbounds %struct.typecheck_t, ptr %73, i32 0, i32 2
  %75 = load ptr, ptr %74, align 8, !tbaa !11
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  call void (ptr, ptr, ptr, ...) @ast_error(ptr noundef %75, ptr noundef %76, ptr noundef @.str.4)
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.pass_opt_t, ptr %77, i32 0, i32 36
  %79 = getelementptr inbounds %struct.typecheck_t, ptr %78, i32 0, i32 2
  %80 = load ptr, ptr %79, align 8, !tbaa !11
  %81 = load ptr, ptr %11, align 8, !tbaa !5
  call void (ptr, ptr, ptr, ...) @ast_error_continue(ptr noundef %80, ptr noundef %81, ptr noundef @.str.3)
  br label %82

82:                                               ; preds = %71, %70
  store i32 2, ptr %3, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %84

83:                                               ; preds = %38, %32
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %84

84:                                               ; preds = %83, %82
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %85

85:                                               ; preds = %84, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %86 = load i32, ptr %3, align 4
  ret i32 %86
}

declare ptr @cap_fetch(ptr noundef) #1

declare ptr @typeparam_constraint(ptr noundef) #1

declare void @ast_error(ptr noundef, ptr noundef, ptr noundef, ...) #1

declare void @typeparam_set_cap(ptr noundef) #1

declare ptr @ast_data(ptr noundef) #1

declare void @ast_error_continue(ptr noundef, ptr noundef, ptr noundef, ...) #1

declare ptr @ast_parent(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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 216}
!12 = !{!"pass_opt_t", !10, i64 0, !10, i64 4, !13, i64 8, !13, i64 9, !13, i64 10, !13, i64 11, !13, i64 12, !13, i64 13, !13, i64 14, !13, i64 15, !13, i64 16, !13, i64 17, !13, i64 18, !13, i64 19, !13, i64 20, !13, i64 21, !10, i64 24, !14, i64 32, !13, i64 40, !13, i64 41, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !15, i64 176, !6, i64 224, !6, i64 232}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"typecheck_t", !6, i64 0, !16, i64 8, !6, i64 40}
!16 = !{!"typecheck_stats_t", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24}


; 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 [75 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [73 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @constraint_contains_tuple(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare i32 @ast_id(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @flatten_typeparamref(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @cap_fetch(ptr noundef %1) #2
  %4 = tail call i32 @ast_id(ptr noundef %3) #2
  %5 = tail call ptr @typeparam_constraint(ptr noundef %1) #2
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %11, label %6

6:                                                ; preds = %2
  %7 = tail call zeroext i1 @constraint_contains_tuple(ptr noundef %0, ptr noundef nonnull %5, ptr noundef nonnull %5)
  br i1 %7, label %8, label %11

8:                                                ; preds = %6
  %9 = getelementptr inbounds i8, ptr %0, i64 216
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  tail call void (ptr, ptr, ptr, ...) @ast_error(ptr noundef %10, ptr noundef nonnull %5, ptr noundef nonnull @.str) #2
  br label %25

11:                                               ; preds = %6, %2
  tail call void @typeparam_set_cap(ptr noundef %1) #2
  %12 = tail call i32 @ast_id(ptr noundef %3) #2
  %.not33 = icmp eq i32 %4, 2
  %.not34 = icmp eq i32 %4, %12
  %or.cond = select i1 %.not33, i1 true, i1 %.not34
  br i1 %or.cond, label %25, label %13

13:                                               ; preds = %11
  %14 = tail call ptr @ast_data(ptr noundef %1) #2
  %15 = tail call ptr @typeparam_constraint(ptr noundef %1) #2
  %.not35 = icmp eq ptr %15, null
  %16 = getelementptr inbounds i8, ptr %0, i64 216
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  br i1 %.not35, label %23, label %18

18:                                               ; preds = %13
  tail call void (ptr, ptr, ptr, ...) @ast_error(ptr noundef %17, ptr noundef %3, ptr noundef nonnull @.str.1) #2
  %19 = load ptr, ptr %16, align 8, !tbaa !5
  tail call void (ptr, ptr, ptr, ...) @ast_error_continue(ptr noundef %19, ptr noundef nonnull %15, ptr noundef nonnull @.str.2) #2
  %20 = tail call ptr @ast_parent(ptr noundef nonnull %15) #2
  %.not36 = icmp eq ptr %20, %14
  br i1 %.not36, label %25, label %21

21:                                               ; preds = %18
  %22 = load ptr, ptr %16, align 8, !tbaa !5
  tail call void (ptr, ptr, ptr, ...) @ast_error_continue(ptr noundef %22, ptr noundef %14, ptr noundef nonnull @.str.3) #2
  br label %25

23:                                               ; preds = %13
  tail call void (ptr, ptr, ptr, ...) @ast_error(ptr noundef %17, ptr noundef %3, ptr noundef nonnull @.str.4) #2
  %24 = load ptr, ptr %16, align 8, !tbaa !5
  tail call void (ptr, ptr, ptr, ...) @ast_error_continue(ptr noundef %24, ptr noundef %14, ptr noundef nonnull @.str.3) #2
  br label %25

25:                                               ; preds = %18, %21, %23, %11, %8
  %.1 = phi i32 [ 2, %8 ], [ 2, %18 ], [ 2, %21 ], [ 2, %23 ], [ 0, %11 ]
  ret i32 %.1
}

declare ptr @cap_fetch(ptr noundef) local_unnamed_addr #1

declare ptr @typeparam_constraint(ptr noundef) local_unnamed_addr #1

declare void @ast_error(ptr noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #1

declare void @typeparam_set_cap(ptr noundef) local_unnamed_addr #1

declare ptr @ast_data(ptr noundef) local_unnamed_addr #1

declare void @ast_error_continue(ptr noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #1

declare ptr @ast_parent(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)"}
!5 = !{!6, !12, i64 216}
!6 = !{!"pass_opt_t", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 9, !10, i64 10, !10, i64 11, !10, i64 12, !10, i64 13, !10, i64 14, !10, i64 15, !10, i64 16, !10, i64 17, !10, i64 18, !10, i64 19, !10, i64 20, !10, i64 21, !7, i64 24, !11, i64 32, !10, i64 40, !10, i64 41, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !13, i64 176, !12, i64 224, !12, i64 232}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"typecheck_t", !12, i64 0, !14, i64 8, !12, i64 40}
!14 = !{!"typecheck_stats_t", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}


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