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

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

@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.48 = external hidden unnamed_addr constant [17 x i8], align 1
@__func__.ast_replace = external hidden unnamed_addr constant [12 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @ast_dup(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @hasparent(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @ast_free(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @ast_swap(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @ast_replace(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.ast_t, ptr %6, i32 0, i32 8
  %8 = load i8, ptr %7, align 4, !tbaa !9, !range !13, !noundef !14
  %9 = trunc i8 %8 to i1
  br i1 %9, label %11, label %10

10:                                               ; preds = %2
  br label %12

11:                                               ; preds = %2
  call void @ponyint_assert_fail(ptr noundef @.str.48, ptr noundef @.str.1, i64 noundef 1602, ptr noundef @__func__.ast_replace)
  br label %12

12:                                               ; preds = %11, %10
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = icmp eq ptr %14, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %12
  br label %37

18:                                               ; preds = %12
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = call zeroext i1 @hasparent(ptr noundef %19)
  br i1 %20, label %21, label %24

21:                                               ; preds = %18
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = call ptr @ast_dup(ptr noundef %22)
  store ptr %23, ptr %4, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %21, %18
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = call zeroext i1 @hasparent(ptr noundef %26)
  br i1 %27, label %28, label %32

28:                                               ; preds = %24
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  call void @ast_swap(ptr noundef %30, ptr noundef %31)
  br label %32

32:                                               ; preds = %28, %24
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  call void @ast_free(ptr noundef %34)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %35, ptr %36, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %32, %17
  ret void
}

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

!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, !12, i64 60}
!10 = !{!"ast_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !11, i64 56, !12, i64 60}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}


; 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 [71 x i8], align 1
@.str.48 = external hidden unnamed_addr constant [17 x i8], align 1
@__func__.ast_replace = external hidden unnamed_addr constant [12 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 @ast_dup(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @ast_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @ast_swap(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @ast_replace(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 60
  %5 = load i8, ptr %4, align 4, !tbaa !9, !range !13, !noundef !14
  %6 = trunc nuw i8 %5 to i1
  br i1 %6, label %7, label %8

7:                                                ; preds = %2
  tail call void @ponyint_assert_fail(ptr noundef nonnull @.str.48, ptr noundef nonnull @.str.1, i64 noundef 1602, ptr noundef nonnull @__func__.ast_replace) #2
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %2, %7
  %9 = phi ptr [ %3, %2 ], [ %.pre, %7 ]
  %10 = icmp eq ptr %9, %1
  br i1 %10, label %22, label %11

11:                                               ; preds = %8
  %12 = tail call zeroext i1 @hasparent(ptr noundef %1)
  br i1 %12, label %13, label %15

13:                                               ; preds = %11
  %14 = tail call ptr @ast_dup(ptr noundef %1)
  br label %15

15:                                               ; preds = %13, %11
  %.0 = phi ptr [ %14, %13 ], [ %1, %11 ]
  %16 = load ptr, ptr %0, align 8, !tbaa !5
  %17 = tail call zeroext i1 @hasparent(ptr noundef %16)
  br i1 %17, label %18, label %20

18:                                               ; preds = %15
  %19 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void @ast_swap(ptr noundef %19, ptr noundef %.0)
  br label %20

20:                                               ; preds = %18, %15
  %21 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void @ast_free(ptr noundef %21)
  store ptr %.0, ptr %0, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %8, %20
  ret void
}

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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 60}
!10 = !{!"ast_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !11, i64 56, !12, i64 60}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass