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

; 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.1 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@__func__.safe_to_mutate = external hidden unnamed_addr constant [15 x i8], align 1

declare i32 @ast_id(ptr noundef) #0

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

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

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

declare ptr @ast_type(ptr noundef) #0

declare i32 @cap_single(ptr noundef) #0

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

declare ptr @ast_child(ptr noundef) #0

declare ptr @ast_sibling(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @safe_to_mutate(ptr noundef %0) #2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca [3 x ptr], align 16
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = call i32 @ast_id(ptr noundef %11)
  switch i32 %12, label %51 [
    i32 84, label %13
    i32 85, label %13
    i32 196, label %13
    i32 87, label %13
    i32 199, label %13
    i32 195, label %14
    i32 192, label %15
    i32 193, label %15
    i32 194, label %15
    i32 178, label %32
    i32 175, label %47
  ]

13:                                               ; preds = %1, %1, %1, %1, %1
  store i1 true, ptr %2, align 1
  br label %53

14:                                               ; preds = %1
  store i1 true, ptr %2, align 1
  br label %53

15:                                               ; preds = %1, %1, %1
  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 24, ptr %6) #3
  store ptr %4, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds ptr, ptr %6, i64 1
  store ptr %5, ptr %16, align 8, !tbaa !5
  %17 = getelementptr inbounds ptr, ptr %6, i64 2
  store ptr null, ptr %17, align 8, !tbaa !5
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds [3 x ptr], ptr %6, i64 0, i64 0
  call void @ast_get_children(ptr noundef %18, i64 noundef 2, ptr noundef %19)
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = call ptr @ast_type(ptr noundef %20)
  store ptr %21, ptr %7, align 8, !tbaa !5
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = call i32 @ast_id(ptr noundef %22)
  %24 = icmp ne i32 %23, 151
  br i1 %24, label %25, label %26

25:                                               ; preds = %15
  store i1 false, ptr %2, align 1
  store i32 1, ptr %8, align 4
  br label %31

26:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = call i32 @cap_single(ptr noundef %27)
  store i32 %28, ptr %9, align 4, !tbaa !9
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = call zeroext i1 @cap_mutable(i32 noundef %29)
  store i1 %30, ptr %2, align 1
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %31

31:                                               ; preds = %26, %25
  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
  br label %53

32:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = call ptr @ast_child(ptr noundef %33)
  store ptr %34, ptr %10, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %42, %32
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %45

38:                                               ; preds = %35
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = call zeroext i1 @safe_to_mutate(ptr noundef %39)
  br i1 %40, label %42, label %41

41:                                               ; preds = %38
  store i1 false, ptr %2, align 1
  store i32 1, ptr %8, align 4
  br label %46

42:                                               ; preds = %38
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = call ptr @ast_sibling(ptr noundef %43)
  store ptr %44, ptr %10, align 8, !tbaa !5
  br label %35, !llvm.loop !11

45:                                               ; preds = %35
  store i1 true, ptr %2, align 1
  store i32 1, ptr %8, align 4
  br label %46

46:                                               ; preds = %45, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %53

47:                                               ; preds = %1
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = call ptr @ast_child(ptr noundef %48)
  %50 = call zeroext i1 @safe_to_mutate(ptr noundef %49)
  store i1 %50, ptr %2, align 1
  br label %53

51:                                               ; preds = %1
  br label %52

52:                                               ; preds = %51
  call void @ponyint_assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i64 noundef 252, ptr noundef @__func__.safe_to_mutate)
  store i1 false, ptr %2, align 1
  br label %53

53:                                               ; preds = %52, %47, %46, %31, %14, %13
  %54 = load i1, ptr %2, align 1
  ret i1 %54
}

declare zeroext i1 @cap_mutable(i32 noundef) #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, !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.1 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@__func__.safe_to_mutate = external hidden unnamed_addr constant [15 x i8], align 1

declare i32 @ast_id(ptr noundef) local_unnamed_addr #0

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

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

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

declare ptr @ast_type(ptr noundef) local_unnamed_addr #0

declare i32 @cap_single(ptr noundef) local_unnamed_addr #0

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

declare ptr @ast_child(ptr noundef) local_unnamed_addr #0

declare ptr @ast_sibling(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @safe_to_mutate(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca [3 x ptr], align 16
  br label %tailrecurse

tailrecurse:                                      ; preds = %21, %1
  %.tr = phi ptr [ %0, %1 ], [ %22, %21 ]
  %5 = tail call i32 @ast_id(ptr noundef %.tr) #3
  switch i32 %5, label %23 [
    i32 84, label %.loopexit
    i32 85, label %.loopexit
    i32 196, label %.loopexit
    i32 87, label %.loopexit
    i32 199, label %.loopexit
    i32 195, label %.loopexit
    i32 192, label %6
    i32 193, label %6
    i32 194, label %6
    i32 178, label %16
    i32 175, label %21
  ]

6:                                                ; preds = %tailrecurse, %tailrecurse, %tailrecurse
  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 24, ptr nonnull %4) #3
  store ptr %2, ptr %4, align 16, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %3, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %4, i64 16
  store ptr null, ptr %8, align 16, !tbaa !5
  call void @ast_get_children(ptr noundef %.tr, i64 noundef 2, ptr noundef nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #3
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = call ptr @ast_type(ptr noundef %9) #3
  %11 = call i32 @ast_id(ptr noundef %10) #3
  %.not11 = icmp eq i32 %11, 151
  br i1 %.not11, label %12, label %15

12:                                               ; preds = %6
  %13 = call i32 @cap_single(ptr noundef %10) #3
  %14 = call zeroext i1 @cap_mutable(i32 noundef %13) #3
  br label %15

15:                                               ; preds = %6, %12
  %.010 = phi i1 [ %14, %12 ], [ false, %6 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  br label %.loopexit

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

.lr.ph:                                           ; preds = %16, %19
  %.017 = phi ptr [ %20, %19 ], [ %17, %16 ]
  %18 = tail call zeroext i1 @safe_to_mutate(ptr noundef nonnull %.017)
  br i1 %18, label %19, label %.loopexit

19:                                               ; preds = %.lr.ph
  %20 = tail call ptr @ast_sibling(ptr noundef nonnull %.017) #3
  %.not = icmp eq ptr %20, null
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !9

21:                                               ; preds = %tailrecurse
  %22 = tail call ptr @ast_child(ptr noundef %.tr) #3
  br label %tailrecurse

23:                                               ; preds = %tailrecurse
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i64 noundef 252, ptr noundef nonnull @__func__.safe_to_mutate) #3
  br label %.loopexit

.loopexit:                                        ; preds = %tailrecurse, %tailrecurse, %tailrecurse, %tailrecurse, %tailrecurse, %tailrecurse, %19, %.lr.ph, %16, %23, %15
  %.2 = phi i1 [ false, %23 ], [ %.010, %15 ], [ true, %16 ], [ %18, %.lr.ph ], [ %18, %19 ], [ true, %tailrecurse ], [ true, %tailrecurse ], [ true, %tailrecurse ], [ true, %tailrecurse ], [ true, %tailrecurse ], [ true, %tailrecurse ]
  ret i1 %.2
}

declare zeroext i1 @cap_mutable(i32 noundef) 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 = { mustprogress 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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