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

; 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.deferred_reification_t = type { ptr, ptr, ptr, ptr, ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [93 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [77 x i8], align 1
@__func__.deferred_reify_add_method_typeparams = external hidden unnamed_addr constant [37 x i8], align 1

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

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

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

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

declare ptr @ast_dup(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @deferred_reify_add_method_typeparams(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.deferred_reification_t, ptr %10, i32 0, i32 3
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %20

14:                                               ; preds = %4
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.deferred_reification_t, ptr %15, i32 0, i32 4
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %14
  br label %21

20:                                               ; preds = %14, %4
  call void @ponyint_assert_fail(ptr noundef @.str.10, ptr noundef @.str.1, i64 noundef 281, ptr noundef @__func__.deferred_reify_add_method_typeparams)
  br label %21

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

24:                                               ; preds = %21
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %33, label %27

27:                                               ; preds = %24, %21
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = icmp eq ptr %28, null
  br i1 %29, label %30, label %34

30:                                               ; preds = %27
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %34

33:                                               ; preds = %30, %24
  br label %35

34:                                               ; preds = %30, %27
  call void @ponyint_assert_fail(ptr noundef @.str.9, ptr noundef @.str.1, i64 noundef 284, ptr noundef @__func__.deferred_reify_add_method_typeparams)
  br label %35

35:                                               ; preds = %34, %33
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %39

38:                                               ; preds = %35
  br label %75

39:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = call ptr @ast_dup(ptr noundef %40)
  store ptr %41, ptr %9, align 8, !tbaa !5
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = call ptr @ast_dup(ptr noundef %42)
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.deferred_reification_t, ptr %44, i32 0, i32 4
  store ptr %43, ptr %45, align 8, !tbaa !11
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.deferred_reification_t, ptr %46, i32 0, i32 5
  %48 = load ptr, ptr %47, align 8, !tbaa !12
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %56

50:                                               ; preds = %39
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.deferred_reification_t, ptr %52, i32 0, i32 5
  %54 = load ptr, ptr %53, align 8, !tbaa !12
  %55 = call ptr @viewpoint_replacethis(ptr noundef %51, ptr noundef %54, i1 noundef zeroext false)
  store ptr %55, ptr %9, align 8, !tbaa !5
  br label %56

56:                                               ; preds = %50, %39
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.deferred_reification_t, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !13
  %60 = icmp ne ptr %59, null
  br i1 %60, label %61, label %71

61:                                               ; preds = %56
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.deferred_reification_t, ptr %63, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !13
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.deferred_reification_t, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !14
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = call ptr @reify(ptr noundef %62, ptr noundef %65, ptr noundef %68, ptr noundef %69, i1 noundef zeroext false)
  store ptr %70, ptr %9, align 8, !tbaa !5
  br label %71

71:                                               ; preds = %61, %56
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.deferred_reification_t, ptr %73, i32 0, i32 3
  store ptr %72, ptr %74, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %75

75:                                               ; preds = %71, %38
  ret void
}

declare ptr @viewpoint_replacethis(ptr noundef, ptr noundef, i1 noundef zeroext) #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, !6, i64 24}
!10 = !{!"deferred_reification_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!11 = !{!10, !6, i64 32}
!12 = !{!10, !6, i64 40}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !6, i64 16}


; 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 [74 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [93 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [77 x i8], align 1
@__func__.deferred_reify_add_method_typeparams = external hidden unnamed_addr constant [37 x i8], align 1

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

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

declare ptr @ast_dup(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @deferred_reify_add_method_typeparams(ptr nocapture noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %12

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = load ptr, ptr %9, align 8, !tbaa !10
  %11 = icmp eq ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %8, %4
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.1, i64 noundef 281, ptr noundef nonnull @__func__.deferred_reify_add_method_typeparams) #2
  br label %13

13:                                               ; preds = %8, %12
  %14 = icmp ne ptr %1, null
  %15 = icmp ne ptr %2, null
  %or.cond = and i1 %14, %15
  br i1 %or.cond, label %.thread27, label %16

16:                                               ; preds = %13
  %17 = icmp eq ptr %1, null
  %18 = icmp eq ptr %2, null
  %or.cond3 = and i1 %17, %18
  br i1 %or.cond3, label %.thread, label %19

19:                                               ; preds = %16
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.1, i64 noundef 284, ptr noundef nonnull @__func__.deferred_reify_add_method_typeparams) #2
  br i1 %17, label %.thread, label %.thread27

.thread27:                                        ; preds = %13, %19
  %20 = tail call ptr @ast_dup(ptr noundef nonnull %1) #2
  %21 = tail call ptr @ast_dup(ptr noundef %2) #2
  %22 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %21, ptr %22, align 8, !tbaa !10
  %23 = getelementptr inbounds i8, ptr %0, i64 40
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %.not = icmp eq ptr %24, null
  br i1 %.not, label %27, label %25

25:                                               ; preds = %.thread27
  %26 = tail call ptr @viewpoint_replacethis(ptr noundef %20, ptr noundef nonnull %24, i1 noundef zeroext false) #2
  br label %27

27:                                               ; preds = %25, %.thread27
  %.0 = phi ptr [ %26, %25 ], [ %20, %.thread27 ]
  %28 = getelementptr inbounds i8, ptr %0, i64 8
  %29 = load ptr, ptr %28, align 8, !tbaa !12
  %.not26 = icmp eq ptr %29, null
  br i1 %.not26, label %34, label %30

30:                                               ; preds = %27
  %31 = getelementptr inbounds i8, ptr %0, i64 16
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = tail call ptr @reify(ptr noundef %.0, ptr noundef nonnull %29, ptr noundef %32, ptr noundef %3, i1 noundef zeroext false)
  br label %34

34:                                               ; preds = %30, %27
  %.1 = phi ptr [ %33, %30 ], [ %.0, %27 ]
  store ptr %.1, ptr %5, align 8, !tbaa !5
  br label %.thread

.thread:                                          ; preds = %16, %19, %34
  ret void
}

declare ptr @viewpoint_replacethis(ptr noundef, ptr noundef, i1 noundef zeroext) 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 = !{!6, !7, i64 24}
!6 = !{!"deferred_reification_t", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 32}
!11 = !{!6, !7, i64 40}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !7, i64 16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass