; 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_autorecover = external hidden unnamed_addr constant [20 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

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

declare i32 @cap_single(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @safe_field_move(i32 noundef, ptr noundef, i32 noundef) #2

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_autorecover(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca i1, align 1
  %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 ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i8, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call i32 @ast_id(ptr noundef %13)
  switch i32 %14, label %76 [
    i32 56, label %15
    i32 149, label %32
    i32 151, label %49
    i32 187, label %49
    i32 17, label %55
  ]

15:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = call ptr @ast_child(ptr noundef %16)
  store ptr %17, ptr %8, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %27, %15
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %30

21:                                               ; preds = %18
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = call zeroext i1 @safe_to_autorecover(ptr noundef %22, ptr noundef %23, i32 noundef %24)
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %31

27:                                               ; preds = %21
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = call ptr @ast_sibling(ptr noundef %28)
  store ptr %29, ptr %8, align 8, !tbaa !5
  br label %18, !llvm.loop !11

30:                                               ; preds = %18
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %31

31:                                               ; preds = %30, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %78

32:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %33 = load ptr, ptr %5, 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 = %44, %32
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %47

38:                                               ; preds = %35
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = call zeroext i1 @safe_to_autorecover(ptr noundef %39, ptr noundef %40, i32 noundef %41)
  br i1 %42, label %44, label %43

43:                                               ; preds = %38
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %48

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

47:                                               ; preds = %35
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %48

48:                                               ; preds = %47, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %78

49:                                               ; preds = %3, %3
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = call i32 @cap_single(ptr noundef %50)
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = call zeroext i1 @safe_field_move(i32 noundef %51, ptr noundef %52, i32 noundef %53)
  store i1 %54, ptr %4, align 1
  br label %78

55:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = call ptr @viewpoint_upper(ptr noundef %56)
  store ptr %57, ptr %11, align 8, !tbaa !5
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  %59 = icmp eq ptr %58, null
  br i1 %59, label %60, label %61

60:                                               ; preds = %55
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %75

61:                                               ; preds = %55
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #3
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = call zeroext i1 @safe_to_autorecover(ptr noundef %62, ptr noundef %63, i32 noundef %64)
  %66 = zext i1 %65 to i8
  store i8 %66, ptr %12, align 1, !tbaa !14
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = icmp ne ptr %67, %68
  br i1 %69, label %70, label %72

70:                                               ; preds = %61
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  call void @ast_free_unattached(ptr noundef %71)
  br label %72

72:                                               ; preds = %70, %61
  %73 = load i8, ptr %12, align 1, !tbaa !14, !range !16, !noundef !17
  %74 = trunc i8 %73 to i1
  store i1 %74, ptr %4, align 1
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #3
  br label %75

75:                                               ; preds = %72, %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %78

76:                                               ; preds = %3
  br label %77

77:                                               ; preds = %76
  call void @ponyint_assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i64 noundef 192, ptr noundef @__func__.safe_to_autorecover)
  store i1 false, ptr %4, align 1
  br label %78

78:                                               ; preds = %77, %75, %49, %48, %31
  %79 = load i1, ptr %4, align 1
  ret i1 %79
}

declare ptr @viewpoint_upper(ptr noundef) #0

declare void @ast_free_unattached(ptr 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"}
!13 = distinct !{!13, !12}
!14 = !{!15, !15, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}


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

declare i32 @ast_id(ptr noundef) local_unnamed_addr #0

declare i32 @cap_single(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @safe_field_move(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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_autorecover(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = tail call i32 @ast_id(ptr noundef %0) #2
  switch i32 %4, label %24 [
    i32 56, label %5
    i32 149, label %10
    i32 151, label %15
    i32 187, label %15
    i32 17, label %18
  ]

5:                                                ; preds = %3
  %6 = tail call ptr @ast_child(ptr noundef %0) #2
  %.not29.not36 = icmp eq ptr %6, null
  br i1 %.not29.not36, label %.loopexit, label %.lr.ph38

.lr.ph38:                                         ; preds = %5, %8
  %.02537 = phi ptr [ %9, %8 ], [ %6, %5 ]
  %7 = tail call zeroext i1 @safe_to_autorecover(ptr noundef nonnull %.02537, ptr noundef %1, i32 noundef %2)
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %.lr.ph38
  %9 = tail call ptr @ast_sibling(ptr noundef nonnull %.02537) #2
  %.not29.not = icmp eq ptr %9, null
  br i1 %.not29.not, label %.loopexit, label %.lr.ph38, !llvm.loop !5

10:                                               ; preds = %3
  %11 = tail call ptr @ast_child(ptr noundef %0) #2
  %.not2832 = icmp eq ptr %11, null
  br i1 %.not2832, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %10, %13
  %.02633 = phi ptr [ %14, %13 ], [ %11, %10 ]
  %12 = tail call zeroext i1 @safe_to_autorecover(ptr noundef nonnull %.02633, ptr noundef %1, i32 noundef %2)
  br i1 %12, label %13, label %.loopexit

13:                                               ; preds = %.lr.ph
  %14 = tail call ptr @ast_sibling(ptr noundef nonnull %.02633) #2
  %.not28 = icmp eq ptr %14, null
  br i1 %.not28, label %.loopexit, label %.lr.ph, !llvm.loop !7

15:                                               ; preds = %3, %3
  %16 = tail call i32 @cap_single(ptr noundef %0) #2
  %17 = tail call zeroext i1 @safe_field_move(i32 noundef %16, ptr noundef %1, i32 noundef %2)
  br label %.loopexit

18:                                               ; preds = %3
  %19 = tail call ptr @viewpoint_upper(ptr noundef %0) #2
  %20 = icmp eq ptr %19, null
  br i1 %20, label %.loopexit, label %21

21:                                               ; preds = %18
  %22 = tail call zeroext i1 @safe_to_autorecover(ptr noundef nonnull %19, ptr noundef %1, i32 noundef %2)
  %.not = icmp eq ptr %19, %0
  br i1 %.not, label %.loopexit, label %23

23:                                               ; preds = %21
  tail call void @ast_free_unattached(ptr noundef nonnull %19) #2
  br label %.loopexit

24:                                               ; preds = %3
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i64 noundef 192, ptr noundef nonnull @__func__.safe_to_autorecover) #2
  br label %.loopexit

.loopexit:                                        ; preds = %13, %.lr.ph, %8, %.lr.ph38, %10, %5, %18, %23, %21, %24, %15
  %.3 = phi i1 [ false, %24 ], [ %17, %15 ], [ false, %18 ], [ %22, %23 ], [ %22, %21 ], [ false, %5 ], [ true, %10 ], [ %7, %.lr.ph38 ], [ %7, %8 ], [ %12, %.lr.ph ], [ %12, %13 ]
  ret i1 %.3
}

declare ptr @viewpoint_upper(ptr noundef) local_unnamed_addr #0

declare void @ast_free_unattached(ptr 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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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