; LLVM IR from xhub/reshop :: src/utils (error_handling)

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

@internal_jmp_buf_err = external dso_local thread_local global ptr, align 8
@external_jmp_buf_err = external dso_local thread_local global ptr, align 8

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0

; Function Attrs: nounwind uwtable
define dso_local ptr @reshop_fatal_error_msg() #1 {
  %1 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  store ptr null, ptr %1, align 8, !tbaa !5
  %2 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @internal_jmp_buf_err)
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp ne ptr %3, null
  br i1 %4, label %5, label %9

5:                                                ; preds = %0
  %6 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @internal_jmp_buf_err)
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %7, ptr %1, align 8, !tbaa !5
  %8 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @internal_jmp_buf_err)
  store ptr null, ptr %8, align 8, !tbaa !5
  br label %18

9:                                                ; preds = %0
  %10 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @external_jmp_buf_err)
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %17

13:                                               ; preds = %9
  %14 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @external_jmp_buf_err)
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %15, ptr %1, align 8, !tbaa !5
  %16 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @external_jmp_buf_err)
  store ptr null, ptr %16, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %13, %9
  br label %18

18:                                               ; preds = %17, %5
  %19 = load ptr, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret ptr %19
}

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

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

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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"}


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

@internal_jmp_buf_err = external dso_local thread_local local_unnamed_addr global ptr, align 8
@external_jmp_buf_err = external dso_local thread_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: none) uwtable
define dso_local ptr @reshop_fatal_error_msg() local_unnamed_addr #1 {
  %1 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @internal_jmp_buf_err)
  %2 = load ptr, ptr %1, align 8, !tbaa !5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %3, label %.sink.split

3:                                                ; preds = %0
  %4 = tail call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @external_jmp_buf_err)
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %.not3 = icmp eq ptr %5, null
  br i1 %.not3, label %6, label %.sink.split

.sink.split:                                      ; preds = %3, %0
  %.sink = phi ptr [ %1, %0 ], [ %4, %3 ]
  %.0.ph = phi ptr [ %2, %0 ], [ %5, %3 ]
  store ptr null, ptr %.sink, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %.sink.split, %3
  %.0 = phi ptr [ null, %3 ], [ %.0.ph, %.sink.split ]
  ret ptr %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: none) 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"}


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