; LLVM IR from bjourne/fast_snn_fpga :: src (npy)

; 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.npy_arr = type { i32, i32, i8, i32, [10 x i32], i32, ptr, i32 }

; 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

; Function Attrs: nounwind uwtable
declare dso_local i64 @npy_n_elements(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @npy_init(i8 noundef signext %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, i1 noundef zeroext %5) #1 {
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i8, align 1
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  store i8 %0, ptr %7, align 1, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !8
  store i32 %2, ptr %9, align 4, !tbaa !8
  store ptr %3, ptr %10, align 8, !tbaa !10
  store ptr %4, ptr %11, align 8, !tbaa !10
  %15 = zext i1 %5 to i8
  store i8 %15, ptr %12, align 1, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %16 = call noalias ptr @malloc(i64 noundef 80) #5
  store ptr %16, ptr %13, align 8, !tbaa !10
  %17 = load ptr, ptr %13, align 8, !tbaa !10
  %18 = getelementptr inbounds %struct.npy_arr, ptr %17, i32 0, i32 0
  store i32 1, ptr %18, align 8, !tbaa !14
  %19 = load ptr, ptr %13, align 8, !tbaa !10
  %20 = getelementptr inbounds %struct.npy_arr, ptr %19, i32 0, i32 1
  store i32 0, ptr %20, align 4, !tbaa !16
  %21 = load i8, ptr %7, align 1, !tbaa !5
  %22 = load ptr, ptr %13, align 8, !tbaa !10
  %23 = getelementptr inbounds %struct.npy_arr, ptr %22, i32 0, i32 2
  store i8 %21, ptr %23, align 8, !tbaa !17
  %24 = load i32, ptr %8, align 4, !tbaa !8
  %25 = load ptr, ptr %13, align 8, !tbaa !10
  %26 = getelementptr inbounds %struct.npy_arr, ptr %25, i32 0, i32 3
  store i32 %24, ptr %26, align 4, !tbaa !18
  %27 = load ptr, ptr %13, align 8, !tbaa !10
  %28 = getelementptr inbounds %struct.npy_arr, ptr %27, i32 0, i32 4
  %29 = getelementptr inbounds [10 x i32], ptr %28, i64 0, i64 0
  %30 = load ptr, ptr %10, align 8, !tbaa !10
  %31 = load i32, ptr %9, align 4, !tbaa !8
  %32 = sext i32 %31 to i64
  %33 = mul i64 %32, 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %29, ptr align 4 %30, i64 %33, i1 false)
  %34 = load i32, ptr %9, align 4, !tbaa !8
  %35 = load ptr, ptr %13, align 8, !tbaa !10
  %36 = getelementptr inbounds %struct.npy_arr, ptr %35, i32 0, i32 5
  store i32 %34, ptr %36, align 8, !tbaa !19
  %37 = load i8, ptr %12, align 1, !tbaa !12, !range !20, !noundef !21
  %38 = trunc i8 %37 to i1
  br i1 %38, label %39, label %54

39:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %40 = load i32, ptr %8, align 4, !tbaa !8
  %41 = sext i32 %40 to i64
  %42 = load ptr, ptr %13, align 8, !tbaa !10
  %43 = call i64 @npy_n_elements(ptr noundef %42)
  %44 = mul i64 %41, %43
  store i64 %44, ptr %14, align 8, !tbaa !22
  %45 = load i64, ptr %14, align 8, !tbaa !22
  %46 = call noalias ptr @malloc(i64 noundef %45) #5
  %47 = load ptr, ptr %13, align 8, !tbaa !10
  %48 = getelementptr inbounds %struct.npy_arr, ptr %47, i32 0, i32 6
  store ptr %46, ptr %48, align 8, !tbaa !24
  %49 = load ptr, ptr %13, align 8, !tbaa !10
  %50 = getelementptr inbounds %struct.npy_arr, ptr %49, i32 0, i32 6
  %51 = load ptr, ptr %50, align 8, !tbaa !24
  %52 = load ptr, ptr %11, align 8, !tbaa !10
  %53 = load i64, ptr %14, align 8, !tbaa !22
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %51, ptr align 1 %52, i64 %53, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %58

54:                                               ; preds = %6
  %55 = load ptr, ptr %11, align 8, !tbaa !10
  %56 = load ptr, ptr %13, align 8, !tbaa !10
  %57 = getelementptr inbounds %struct.npy_arr, ptr %56, i32 0, i32 6
  store ptr %55, ptr %57, align 8, !tbaa !24
  br label %58

58:                                               ; preds = %54, %39
  %59 = load ptr, ptr %13, align 8, !tbaa !10
  %60 = getelementptr inbounds %struct.npy_arr, ptr %59, i32 0, i32 7
  store i32 0, ptr %60, align 8, !tbaa !25
  %61 = load ptr, ptr %13, align 8, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  ret ptr %61
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"_Bool", !6, i64 0}
!14 = !{!15, !9, i64 0}
!15 = !{!"", !9, i64 0, !9, i64 4, !6, i64 8, !9, i64 12, !6, i64 16, !9, i64 56, !11, i64 64, !9, i64 72}
!16 = !{!15, !9, i64 4}
!17 = !{!15, !6, i64 8}
!18 = !{!15, !9, i64 12}
!19 = !{!15, !9, i64 56}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!23, !23, i64 0}
!23 = !{!"long", !6, i64 0}
!24 = !{!15, !11, i64 64}
!25 = !{!15, !9, i64 72}


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

; Function Attrs: nounwind uwtable
declare dso_local i64 @npy_n_elements(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @npy_init(i8 noundef signext %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3, ptr noundef %4, i1 noundef zeroext %5) local_unnamed_addr #0 {
  %7 = tail call noalias dereferenceable_or_null(80) ptr @malloc(i64 noundef 80) #3
  store i32 1, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 4
  store i32 0, ptr %8, align 4, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %7, i64 8
  store i8 %0, ptr %9, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %7, i64 12
  store i32 %1, ptr %10, align 4, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %7, i64 16
  %12 = sext i32 %2 to i64
  %13 = shl nsw i64 %12, 2
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %11, ptr align 4 %3, i64 %13, i1 false)
  %14 = getelementptr inbounds i8, ptr %7, i64 56
  store i32 %2, ptr %14, align 8, !tbaa !14
  br i1 %5, label %15, label %20

15:                                               ; preds = %6
  %16 = sext i32 %1 to i64
  %17 = tail call i64 @npy_n_elements(ptr noundef nonnull %7)
  %18 = mul i64 %17, %16
  %19 = tail call noalias ptr @malloc(i64 noundef %18) #3
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %19, ptr align 1 %4, i64 %18, i1 false)
  br label %20

20:                                               ; preds = %6, %15
  %.sink = phi ptr [ %19, %15 ], [ %4, %6 ]
  %21 = getelementptr inbounds i8, ptr %7, i64 64
  store ptr %.sink, ptr %21, align 8
  %22 = getelementptr inbounds i8, ptr %7, i64 72
  store i32 0, ptr %22, align 8, !tbaa !15
  ret ptr %7
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind allocsize(0) }

!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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !8, i64 8, !7, i64 12, !8, i64 16, !7, i64 56, !10, i64 64, !7, i64 72}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !8, i64 8}
!13 = !{!6, !7, i64 12}
!14 = !{!6, !7, i64 56}
!15 = !{!6, !7, i64 72}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass