; LLVM IR from PaddlePaddle/FastDeploy :: third_party/onnx/onnx (onnxifi_wrapper)

; 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.onnxifi_backend_id_wrapper = type { i32, ptr, ptr }
%struct.onnxifi_library = type { ptr, i32, %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.onnxifi_backend_wrapper = type { i32, ptr, ptr }

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

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

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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @onnxInitBackend(ptr noundef %0, ptr noundef %1, ptr noundef %2) #4 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = 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
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  store i32 259, ptr %4, align 4
  br label %71

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

19:                                               ; preds = %15
  store i32 257, ptr %4, align 4
  br label %71

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %21, ptr %8, align 8, !tbaa !5
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.onnxifi_backend_id_wrapper, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !9
  %25 = icmp ne i32 %24, 786249572
  br i1 %25, label %26, label %27

26:                                               ; preds = %20
  store i32 257, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %70

27:                                               ; preds = %20
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.onnxifi_backend_id_wrapper, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !12
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %33

32:                                               ; preds = %27
  store i32 257, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %70

33:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %34 = call noalias ptr @malloc(i64 noundef 24) #6
  store ptr %34, ptr %10, align 8, !tbaa !5
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = icmp eq ptr %35, null
  br i1 %36, label %37, label %38

37:                                               ; preds = %33
  store i32 1025, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %69

38:                                               ; preds = %33
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %39, i8 0, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.onnxifi_backend_id_wrapper, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !12
  %43 = getelementptr inbounds %struct.onnxifi_library, ptr %42, i32 0, i32 2
  %44 = getelementptr inbounds %struct.anon, ptr %43, i32 0, i32 4
  %45 = load ptr, ptr %44, align 8, !tbaa !13
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.onnxifi_backend_id_wrapper, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.onnxifi_backend_wrapper, ptr %50, i32 0, i32 1
  %52 = call i32 %45(ptr noundef %48, ptr noundef %49, ptr noundef %51)
  store i32 %52, ptr %11, align 4, !tbaa !15
  %53 = load i32, ptr %11, align 4, !tbaa !15
  %54 = icmp eq i32 %53, 0
  br i1 %54, label %55, label %65

55:                                               ; preds = %38
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.onnxifi_backend_wrapper, ptr %56, i32 0, i32 0
  store i32 1268459778, ptr %57, align 8, !tbaa !16
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.onnxifi_backend_id_wrapper, ptr %58, i32 0, i32 2
  %60 = load ptr, ptr %59, align 8, !tbaa !12
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.onnxifi_backend_wrapper, ptr %61, i32 0, i32 2
  store ptr %60, ptr %62, align 8, !tbaa !18
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %63, ptr %64, align 8, !tbaa !5
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %68

65:                                               ; preds = %38
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %66) #5
  %67 = load i32, ptr %11, align 4, !tbaa !15
  store i32 %67, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %68

68:                                               ; preds = %65, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %69

69:                                               ; preds = %68, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %70

70:                                               ; preds = %69, %32, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %71

71:                                               ; preds = %70, %19, %14
  %72 = load i32, ptr %4, align 4
  ret i32 %72
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"onnxifi_backend_id_wrapper", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!7, !7, i64 0}
!14 = !{!10, !6, i64 8}
!15 = !{!11, !11, i64 0}
!16 = !{!17, !11, i64 0}
!17 = !{!"onnxifi_backend_wrapper", !11, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!17, !6, i64 16}


; 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: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @onnxInitBackend(ptr noundef readonly %0, ptr noundef %1, ptr noundef writeonly %2) local_unnamed_addr #1 {
  %4 = icmp eq ptr %2, null
  br i1 %4, label %27, label %5

5:                                                ; preds = %3
  store ptr null, ptr %2, align 8, !tbaa !5
  %6 = icmp eq ptr %0, null
  br i1 %6, label %27, label %7

7:                                                ; preds = %5
  %8 = load i32, ptr %0, align 8, !tbaa !9
  %.not = icmp eq i32 %8, 786249572
  br i1 %.not, label %9, label %27

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = icmp eq ptr %11, null
  br i1 %12, label %27, label %13

13:                                               ; preds = %9
  %calloc = tail call dereferenceable_or_null(24) ptr @calloc(i64 1, i64 24)
  %14 = icmp eq ptr %calloc, null
  br i1 %14, label %27, label %15

15:                                               ; preds = %13
  %16 = getelementptr inbounds i8, ptr %11, i64 48
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %calloc, i64 8
  %21 = tail call i32 %17(ptr noundef %19, ptr noundef %1, ptr noundef nonnull %20) #3
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %26

23:                                               ; preds = %15
  store i32 1268459778, ptr %calloc, align 8, !tbaa !15
  %24 = load ptr, ptr %10, align 8, !tbaa !12
  %25 = getelementptr inbounds i8, ptr %calloc, i64 16
  store ptr %24, ptr %25, align 8, !tbaa !17
  store ptr %calloc, ptr %2, align 8, !tbaa !5
  br label %27

26:                                               ; preds = %15
  tail call void @free(ptr noundef nonnull %calloc) #3
  br label %27

27:                                               ; preds = %7, %9, %23, %26, %13, %5, %3
  %.3 = phi i32 [ 259, %3 ], [ 257, %5 ], [ 257, %7 ], [ 257, %9 ], [ 1025, %13 ], [ 0, %23 ], [ %21, %26 ]
  ret i32 %.3
}

; 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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #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 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
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"}
!9 = !{!10, !11, i64 0}
!10 = !{!"onnxifi_backend_id_wrapper", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!7, !7, i64 0}
!14 = !{!10, !6, i64 8}
!15 = !{!16, !11, i64 0}
!16 = !{!"onnxifi_backend_wrapper", !11, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!16, !6, i64 16}


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