; LLVM IR from IlyaGrebnov/libbsc :: libbsc/platform (platform)

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

@_ZL13bsc_malloc_fn = external hidden global ptr, align 8
@_ZL18bsc_zero_malloc_fn = external hidden global ptr, align 8
@_ZL11bsc_free_fn = external hidden global ptr, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local i32 @bsc_platform_init(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  %9 = load ptr, ptr %7, align 8, !tbaa !9
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %13

11:                                               ; preds = %4
  %12 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %12, ptr @_ZL18bsc_zero_malloc_fn, align 8, !tbaa !9
  br label %18

13:                                               ; preds = %4
  %14 = load ptr, ptr %6, align 8, !tbaa !9
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  store ptr @_ZL20bsc_wrap_zero_mallocm, ptr @_ZL18bsc_zero_malloc_fn, align 8, !tbaa !9
  br label %17

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

18:                                               ; preds = %17, %11
  %19 = load ptr, ptr %6, align 8, !tbaa !9
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %23

21:                                               ; preds = %18
  %22 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %22, ptr @_ZL13bsc_malloc_fn, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %21, %18
  %24 = load ptr, ptr %8, align 8, !tbaa !9
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %28

26:                                               ; preds = %23
  %27 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %27, ptr @_ZL11bsc_free_fn, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %26, %23
  ret i32 0
}

; Function Attrs: mustprogress uwtable
declare hidden noundef ptr @_ZL20bsc_wrap_zero_mallocm(i64 noundef) #1

attributes #0 = { mustprogress 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 = { 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

@_ZL13bsc_malloc_fn = external hidden local_unnamed_addr global ptr, align 8
@_ZL18bsc_zero_malloc_fn = external hidden local_unnamed_addr global ptr, align 8
@_ZL11bsc_free_fn = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @bsc_platform_init(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %5, label %6

5:                                                ; preds = %4
  %cond = icmp eq ptr %1, null
  br i1 %cond, label %8, label %.thread

.thread:                                          ; preds = %5
  store ptr @_ZL20bsc_wrap_zero_mallocm, ptr @_ZL18bsc_zero_malloc_fn, align 8, !tbaa !5
  br label %7

6:                                                ; preds = %4
  store ptr %2, ptr @_ZL18bsc_zero_malloc_fn, align 8, !tbaa !5
  %.not10 = icmp eq ptr %1, null
  br i1 %.not10, label %8, label %7

7:                                                ; preds = %.thread, %6
  store ptr %1, ptr @_ZL13bsc_malloc_fn, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %5, %7, %6
  %.not11 = icmp eq ptr %3, null
  br i1 %.not11, label %10, label %9

9:                                                ; preds = %8
  store ptr %3, ptr @_ZL11bsc_free_fn, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %9, %8
  ret i32 0
}

; Function Attrs: mustprogress uwtable
declare hidden noundef ptr @_ZL20bsc_wrap_zero_mallocm(i64 noundef) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, 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" }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass