; LLVM IR from nbosb/simdal :: src/simdal/db/db_sqlite.ll (ZN6simdal9db_sqlite9prep_stmtEPKcPP12sqlite3_stmt)

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

%"class.simdal::db_sqlite" = type { %"class.simdal::db", ptr, i32, i32, i8, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%"class.simdal::db" = type { ptr, %"class.std::__cxx11::basic_string", i32, i32, %"class.std::unique_ptr", %"class.std::unique_ptr.2", i8, i8, %"class.std::deque", %"class.std::mutex", %"class.std::condition_variable", %"class.std::condition_variable", i32, i32 }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"class.std::unique_ptr" = type { %"struct.std::__uniq_ptr_data" }
%"struct.std::__uniq_ptr_data" = type { %"class.std::__uniq_ptr_impl" }
%"class.std::__uniq_ptr_impl" = type { %"class.std::tuple" }
%"class.std::tuple" = type { %"struct.std::_Tuple_impl" }
%"struct.std::_Tuple_impl" = type { %"struct.std::_Head_base.1" }
%"struct.std::_Head_base.1" = type { ptr }
%"class.std::unique_ptr.2" = type { %"struct.std::__uniq_ptr_data.3" }
%"struct.std::__uniq_ptr_data.3" = type { %"class.std::__uniq_ptr_impl.4" }
%"class.std::__uniq_ptr_impl.4" = type { %"class.std::tuple.5" }
%"class.std::tuple.5" = type { %"struct.std::_Tuple_impl.6" }
%"struct.std::_Tuple_impl.6" = type { %"struct.std::_Head_base.9" }
%"struct.std::_Head_base.9" = type { ptr }
%"class.std::deque" = type { %"class.std::_Deque_base" }
%"class.std::_Deque_base" = type { %"struct.std::_Deque_base<simdal::entry_base *, std::allocator<simdal::entry_base *>>::_Deque_impl" }
%"struct.std::_Deque_base<simdal::entry_base *, std::allocator<simdal::entry_base *>>::_Deque_impl" = type { %"struct.std::_Deque_base<simdal::entry_base *, std::allocator<simdal::entry_base *>>::_Deque_impl_data" }
%"struct.std::_Deque_base<simdal::entry_base *, std::allocator<simdal::entry_base *>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator", %"struct.std::_Deque_iterator" }
%"struct.std::_Deque_iterator" = type { ptr, ptr, ptr, ptr }
%"class.std::mutex" = type { %"class.std::__mutex_base" }
%"class.std::__mutex_base" = type { %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%"class.std::condition_variable" = type { %"class.std::__condvar" }
%"class.std::__condvar" = type { %union.pthread_cond_t }
%union.pthread_cond_t = type { %struct.__pthread_cond_s }
%struct.__pthread_cond_s = type { %union.__atomic_wide_counter, %union.__atomic_wide_counter, [2 x i32], [2 x i32], i32, i32, [2 x i32] }
%union.__atomic_wide_counter = type { i64 }

@_ZN6simdal11log_fcn_ptrE = external global ptr, align 8
@.str.56 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.91 = external hidden unnamed_addr constant [37 x i8], align 1

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

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

declare ptr @sqlite3_errmsg(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN6simdal9db_sqlite9prep_stmtEPKcPP12sqlite3_stmt(ptr noundef nonnull align 8 dereferenceable(544) %0, ptr noundef %1, ptr noundef %2) #2 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %11 = getelementptr inbounds %"class.simdal::db_sqlite", ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = call i32 @sqlite3_prepare_v2(ptr noundef %12, ptr noundef %13, i32 noundef -1, ptr noundef %14, ptr noundef null)
  store i32 %15, ptr %8, align 4, !tbaa !38
  %16 = load i32, ptr %8, align 4, !tbaa !38
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %21, label %18

18:                                               ; preds = %3
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %30

21:                                               ; preds = %18, %3
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr @_ZN6simdal11log_fcn_ptrE, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %"class.simdal::db_sqlite", ptr %10, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = call ptr @sqlite3_errmsg(ptr noundef %26)
  call void (ptr, i32, ptr, ...) %23(ptr noundef @.str.56, i32 noundef 386, ptr noundef @.str.91, ptr noundef %24, ptr noundef %27)
  br label %28

28:                                               ; preds = %22
  br label %29

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

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

31:                                               ; preds = %30, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %32 = load i1, ptr %4, align 1
  ret i1 %32
}

declare i32 @sqlite3_prepare_v2(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !6, i64 296}
!10 = !{!"_ZTSN6simdal9db_sqliteE", !11, i64 0, !6, i64 296, !15, i64 304, !15, i64 308, !28, i64 312, !28, i64 313, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !6, i64 392, !6, i64 400, !6, i64 408, !6, i64 416, !6, i64 424, !6, i64 432, !6, i64 440, !6, i64 448, !6, i64 456, !6, i64 464, !6, i64 472, !6, i64 480, !6, i64 488, !6, i64 496, !6, i64 504, !6, i64 512, !6, i64 520, !6, i64 528, !6, i64 536}
!11 = !{!"_ZTSN6simdal2dbE", !12, i64 8, !15, i64 40, !15, i64 44, !16, i64 48, !22, i64 56, !28, i64 64, !28, i64 65, !29, i64 72, !34, i64 152, !36, i64 192, !36, i64 240, !15, i64 288, !15, i64 292}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !13, i64 0, !14, i64 8, !7, i64 16}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!"_ZTSSt10unique_ptrIN6simdal8csv_fileESt14default_deleteIS1_EE", !17, i64 0}
!17 = !{!"_ZTSSt15__uniq_ptr_dataIN6simdal8csv_fileESt14default_deleteIS1_ELb1ELb1EE", !18, i64 0}
!18 = !{!"_ZTSSt15__uniq_ptr_implIN6simdal8csv_fileESt14default_deleteIS1_EE", !19, i64 0}
!19 = !{!"_ZTSSt5tupleIJPN6simdal8csv_fileESt14default_deleteIS1_EEE", !20, i64 0}
!20 = !{!"_ZTSSt11_Tuple_implILm0EJPN6simdal8csv_fileESt14default_deleteIS1_EEE", !21, i64 0}
!21 = !{!"_ZTSSt10_Head_baseILm0EPN6simdal8csv_fileELb0EE", !6, i64 0}
!22 = !{!"_ZTSSt10unique_ptrISt6threadSt14default_deleteIS0_EE", !23, i64 0}
!23 = !{!"_ZTSSt15__uniq_ptr_dataISt6threadSt14default_deleteIS0_ELb1ELb1EE", !24, i64 0}
!24 = !{!"_ZTSSt15__uniq_ptr_implISt6threadSt14default_deleteIS0_EE", !25, i64 0}
!25 = !{!"_ZTSSt5tupleIJPSt6threadSt14default_deleteIS0_EEE", !26, i64 0}
!26 = !{!"_ZTSSt11_Tuple_implILm0EJPSt6threadSt14default_deleteIS0_EEE", !27, i64 0}
!27 = !{!"_ZTSSt10_Head_baseILm0EPSt6threadLb0EE", !6, i64 0}
!28 = !{!"bool", !7, i64 0}
!29 = !{!"_ZTSSt5dequeIPN6simdal10entry_baseESaIS2_EE", !30, i64 0}
!30 = !{!"_ZTSSt11_Deque_baseIPN6simdal10entry_baseESaIS2_EE", !31, i64 0}
!31 = !{!"_ZTSNSt11_Deque_baseIPN6simdal10entry_baseESaIS2_EE11_Deque_implE", !32, i64 0}
!32 = !{!"_ZTSNSt11_Deque_baseIPN6simdal10entry_baseESaIS2_EE16_Deque_impl_dataE", !6, i64 0, !14, i64 8, !33, i64 16, !33, i64 48}
!33 = !{!"_ZTSSt15_Deque_iteratorIPN6simdal10entry_baseERS2_PS2_E", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!34 = !{!"_ZTSSt5mutex", !35, i64 0}
!35 = !{!"_ZTSSt12__mutex_base", !7, i64 0}
!36 = !{!"_ZTSSt18condition_variable", !37, i64 0}
!37 = !{!"_ZTSSt9__condvar", !7, i64 0}
!38 = !{!15, !15, 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"

@_ZN6simdal11log_fcn_ptrE = external local_unnamed_addr global ptr, align 8
@.str.56 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.91 = external hidden unnamed_addr constant [37 x i8], align 1

declare ptr @sqlite3_errmsg(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN6simdal9db_sqlite9prep_stmtEPKcPP12sqlite3_stmt(ptr nocapture noundef nonnull readonly align 8 dereferenceable(544) %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 296
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = tail call i32 @sqlite3_prepare_v2(ptr noundef %5, ptr noundef %1, i32 noundef -1, ptr noundef %2, ptr noundef null)
  %7 = icmp eq i32 %6, 0
  %8 = icmp ne ptr %2, null
  %or.cond.not = and i1 %8, %7
  br i1 %or.cond.not, label %13, label %9

9:                                                ; preds = %3
  %10 = load ptr, ptr @_ZN6simdal11log_fcn_ptrE, align 8, !tbaa !37
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = tail call ptr @sqlite3_errmsg(ptr noundef %11)
  tail call void (ptr, i32, ptr, ...) %10(ptr noundef nonnull @.str.56, i32 noundef 386, ptr noundef nonnull @.str.91, ptr noundef %1, ptr noundef %12)
  br label %13

13:                                               ; preds = %3, %9
  ret i1 %or.cond.not
}

declare i32 @sqlite3_prepare_v2(ptr noundef, ptr noundef, i32 noundef, ptr noundef, 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 = { mustprogress 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, !10, i64 296}
!6 = !{!"_ZTSN6simdal9db_sqliteE", !7, i64 0, !10, i64 296, !14, i64 304, !14, i64 308, !27, i64 312, !27, i64 313, !10, i64 320, !10, i64 328, !10, i64 336, !10, i64 344, !10, i64 352, !10, i64 360, !10, i64 368, !10, i64 376, !10, i64 384, !10, i64 392, !10, i64 400, !10, i64 408, !10, i64 416, !10, i64 424, !10, i64 432, !10, i64 440, !10, i64 448, !10, i64 456, !10, i64 464, !10, i64 472, !10, i64 480, !10, i64 488, !10, i64 496, !10, i64 504, !10, i64 512, !10, i64 520, !10, i64 528, !10, i64 536}
!7 = !{!"_ZTSN6simdal2dbE", !8, i64 8, !14, i64 40, !14, i64 44, !15, i64 48, !21, i64 56, !27, i64 64, !27, i64 65, !28, i64 72, !33, i64 152, !35, i64 192, !35, i64 240, !14, i64 288, !14, i64 292}
!8 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !9, i64 0, !13, i64 8, !11, i64 16}
!9 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !10, i64 0}
!10 = !{!"any pointer", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"long", !11, i64 0}
!14 = !{!"int", !11, i64 0}
!15 = !{!"_ZTSSt10unique_ptrIN6simdal8csv_fileESt14default_deleteIS1_EE", !16, i64 0}
!16 = !{!"_ZTSSt15__uniq_ptr_dataIN6simdal8csv_fileESt14default_deleteIS1_ELb1ELb1EE", !17, i64 0}
!17 = !{!"_ZTSSt15__uniq_ptr_implIN6simdal8csv_fileESt14default_deleteIS1_EE", !18, i64 0}
!18 = !{!"_ZTSSt5tupleIJPN6simdal8csv_fileESt14default_deleteIS1_EEE", !19, i64 0}
!19 = !{!"_ZTSSt11_Tuple_implILm0EJPN6simdal8csv_fileESt14default_deleteIS1_EEE", !20, i64 0}
!20 = !{!"_ZTSSt10_Head_baseILm0EPN6simdal8csv_fileELb0EE", !10, i64 0}
!21 = !{!"_ZTSSt10unique_ptrISt6threadSt14default_deleteIS0_EE", !22, i64 0}
!22 = !{!"_ZTSSt15__uniq_ptr_dataISt6threadSt14default_deleteIS0_ELb1ELb1EE", !23, i64 0}
!23 = !{!"_ZTSSt15__uniq_ptr_implISt6threadSt14default_deleteIS0_EE", !24, i64 0}
!24 = !{!"_ZTSSt5tupleIJPSt6threadSt14default_deleteIS0_EEE", !25, i64 0}
!25 = !{!"_ZTSSt11_Tuple_implILm0EJPSt6threadSt14default_deleteIS0_EEE", !26, i64 0}
!26 = !{!"_ZTSSt10_Head_baseILm0EPSt6threadLb0EE", !10, i64 0}
!27 = !{!"bool", !11, i64 0}
!28 = !{!"_ZTSSt5dequeIPN6simdal10entry_baseESaIS2_EE", !29, i64 0}
!29 = !{!"_ZTSSt11_Deque_baseIPN6simdal10entry_baseESaIS2_EE", !30, i64 0}
!30 = !{!"_ZTSNSt11_Deque_baseIPN6simdal10entry_baseESaIS2_EE11_Deque_implE", !31, i64 0}
!31 = !{!"_ZTSNSt11_Deque_baseIPN6simdal10entry_baseESaIS2_EE16_Deque_impl_dataE", !10, i64 0, !13, i64 8, !32, i64 16, !32, i64 48}
!32 = !{!"_ZTSSt15_Deque_iteratorIPN6simdal10entry_baseERS2_PS2_E", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!33 = !{!"_ZTSSt5mutex", !34, i64 0}
!34 = !{!"_ZTSSt12__mutex_base", !11, i64 0}
!35 = !{!"_ZTSSt18condition_variable", !36, i64 0}
!36 = !{!"_ZTSSt9__condvar", !11, i64 0}
!37 = !{!10, !10, i64 0}


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