; LLVM IR from ponylang/ponyc :: src/libponyrt/asio (asio)

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

@running_base = external hidden global %struct.asio_base_t, align 8

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @ponyint_asio_stop() #0 {
  %1 = alloca i1, align 1
  %2 = call zeroext i1 @ponyint_asio_stoppable()
  br i1 %2, label %4, label %3

3:                                                ; preds = %0
  store i1 false, ptr %1, align 1
  br label %14

4:                                                ; preds = %0
  %5 = load ptr, ptr getelementptr inbounds (%struct.asio_base_t, ptr @running_base, i32 0, i32 1), align 8, !tbaa !5
  %6 = icmp ne ptr %5, null
  br i1 %6, label %7, label %13

7:                                                ; preds = %4
  %8 = load ptr, ptr getelementptr inbounds (%struct.asio_base_t, ptr @running_base, i32 0, i32 1), align 8, !tbaa !5
  call void @ponyint_asio_backend_final(ptr noundef %8)
  %9 = load i64, ptr @running_base, align 8, !tbaa !11
  %10 = call zeroext i1 @ponyint_thread_join(i64 noundef %9)
  br i1 %10, label %12, label %11

11:                                               ; preds = %7
  store i1 false, ptr %1, align 1
  br label %14

12:                                               ; preds = %7
  store ptr null, ptr getelementptr inbounds (%struct.asio_base_t, ptr @running_base, i32 0, i32 1), align 8, !tbaa !5
  store i64 0, ptr @running_base, align 8, !tbaa !11
  br label %13

13:                                               ; preds = %12, %4
  store i1 true, ptr %1, align 1
  br label %14

14:                                               ; preds = %13, %11, %3
  %15 = load i1, ptr %1, align 1
  ret i1 %15
}

declare void @ponyint_asio_backend_final(ptr noundef) #1

declare zeroext i1 @ponyint_thread_join(i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @ponyint_asio_stoppable() #0

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

!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, !10, i64 8}
!6 = !{!"asio_base_t", !7, i64 0, !10, i64 8, !8, i64 16}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}


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

%struct.asio_base_t = type { i64, ptr, i64 }

@running_base = external hidden local_unnamed_addr global %struct.asio_base_t, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @ponyint_asio_stop() local_unnamed_addr #0 {
  %1 = tail call zeroext i1 @ponyint_asio_stoppable()
  br i1 %1, label %2, label %8

2:                                                ; preds = %0
  %3 = load ptr, ptr getelementptr inbounds (i8, ptr @running_base, i64 8), align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %8, label %4

4:                                                ; preds = %2
  tail call void @ponyint_asio_backend_final(ptr noundef nonnull %3) #3
  %5 = load i64, ptr @running_base, align 8, !tbaa !11
  %6 = tail call zeroext i1 @ponyint_thread_join(i64 noundef %5) #3
  br i1 %6, label %7, label %8

7:                                                ; preds = %4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) @running_base, i8 0, i64 16, i1 false)
  br label %8

8:                                                ; preds = %2, %7, %4, %0
  %.0 = phi i1 [ false, %0 ], [ false, %4 ], [ true, %7 ], [ true, %2 ]
  ret i1 %.0
}

declare void @ponyint_asio_backend_final(ptr noundef) local_unnamed_addr #1

declare zeroext i1 @ponyint_thread_join(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @ponyint_asio_stoppable() local_unnamed_addr #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 nounwind willreturn memory(argmem: write) }
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, !10, i64 8}
!6 = !{!"asio_base_t", !7, i64 0, !10, i64 8, !8, i64 16}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass