; LLVM IR from Meow8p/nmf :: src (libnmf)

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

@nmf_malloc_pool = external dso_local global ptr, align 8
@nmf_malloc_max = external dso_local global i32, align 4
@nmf_initialized = external dso_local global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @nmf_init() #0 {
  %1 = alloca i32, align 4
  %2 = load i32, ptr @nmf_initialized, align 4, !tbaa !5
  %3 = icmp ne i32 %2, 0
  br i1 %3, label %4, label %5

4:                                                ; preds = %0
  store i32 0, ptr %1, align 4
  br label %17

5:                                                ; preds = %0
  %6 = load i32, ptr @nmf_malloc_max, align 4, !tbaa !5
  %7 = zext i32 %6 to i64
  %8 = mul i64 %7, 16
  %9 = call noalias ptr @malloc(i64 noundef %8) #4
  store ptr %9, ptr @nmf_malloc_pool, align 8, !tbaa !9
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %5
  call void @exit(i32 noundef -1) #5
  unreachable

12:                                               ; preds = %5
  %13 = load ptr, ptr @nmf_malloc_pool, align 8, !tbaa !9
  %14 = load i32, ptr @nmf_malloc_max, align 4, !tbaa !5
  %15 = zext i32 %14 to i64
  %16 = mul i64 %15, 16
  call void @llvm.memset.p0.i64(ptr align 8 %13, i8 0, i64 %16, i1 false)
  store i32 1, ptr @nmf_initialized, align 4, !tbaa !5
  store i32 1, ptr %1, align 4
  br label %17

17:                                               ; preds = %12, %4
  %18 = load i32, ptr %1, align 4
  ret i32 %18
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

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

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 = { nounwind allocsize(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 = { noreturn nounwind "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind allocsize(0) }
attributes #5 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/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"

@nmf_malloc_pool = external dso_local local_unnamed_addr global ptr, align 8
@nmf_malloc_max = external dso_local local_unnamed_addr global i32, align 4
@nmf_initialized = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @nmf_init() local_unnamed_addr #0 {
  %1 = load i32, ptr @nmf_initialized, align 4, !tbaa !5
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %2, label %9

2:                                                ; preds = %0
  %3 = load i32, ptr @nmf_malloc_max, align 4, !tbaa !5
  %4 = zext i32 %3 to i64
  %5 = shl nuw nsw i64 %4, 4
  %calloc = tail call ptr @calloc(i64 1, i64 %5)
  store ptr %calloc, ptr @nmf_malloc_pool, align 8, !tbaa !9
  %6 = icmp eq ptr %calloc, null
  br i1 %6, label %7, label %8

7:                                                ; preds = %2
  tail call void @exit(i32 noundef -1) #3
  unreachable

8:                                                ; preds = %2
  store i32 1, ptr @nmf_initialized, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %0, %8
  %.0 = phi i32 [ 1, %8 ], [ 0, %0 ]
  ret i32 %.0
}

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #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 = { noreturn nounwind "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 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #3 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


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