; 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_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_graph_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 @onnxInitGraph(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i32 noundef %4, ptr noundef %5, ptr noundef %6) #4 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store i64 %2, ptr %11, align 8, !tbaa !9
  store ptr %3, ptr %12, align 8, !tbaa !5
  store i32 %4, ptr %13, align 4, !tbaa !11
  store ptr %5, ptr %14, align 8, !tbaa !5
  store ptr %6, ptr %15, align 8, !tbaa !5
  %20 = load ptr, ptr %15, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %7
  store i32 259, ptr %8, align 4
  br label %83

23:                                               ; preds = %7
  %24 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr null, ptr %24, align 8, !tbaa !5
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %23
  store i32 262, ptr %8, align 4
  br label %83

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %29, ptr %16, align 8, !tbaa !5
  %30 = load ptr, ptr %16, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.onnxifi_backend_wrapper, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !13
  %33 = icmp ne i32 %32, 1268459778
  br i1 %33, label %34, label %35

34:                                               ; preds = %28
  store i32 262, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %82

35:                                               ; preds = %28
  %36 = load ptr, ptr %16, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.onnxifi_backend_wrapper, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  %39 = icmp eq ptr %38, null
  br i1 %39, label %40, label %41

40:                                               ; preds = %35
  store i32 262, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %82

41:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #5
  %42 = call noalias ptr @malloc(i64 noundef 24) #6
  store ptr %42, ptr %18, align 8, !tbaa !5
  %43 = load ptr, ptr %18, align 8, !tbaa !5
  %44 = icmp eq ptr %43, null
  br i1 %44, label %45, label %46

45:                                               ; preds = %41
  store i32 1025, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %81

46:                                               ; preds = %41
  %47 = load ptr, ptr %18, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %47, i8 0, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #5
  %48 = load ptr, ptr %16, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.onnxifi_backend_wrapper, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  %51 = getelementptr inbounds %struct.onnxifi_library, ptr %50, i32 0, i32 2
  %52 = getelementptr inbounds %struct.anon, ptr %51, i32 0, i32 11
  %53 = load ptr, ptr %52, align 8, !tbaa !16
  %54 = load ptr, ptr %16, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.onnxifi_backend_wrapper, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !17
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = load i64, ptr %11, align 8, !tbaa !9
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  %60 = load i32, ptr %13, align 4, !tbaa !11
  %61 = load ptr, ptr %14, align 8, !tbaa !5
  %62 = load ptr, ptr %18, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.onnxifi_graph_wrapper, ptr %62, i32 0, i32 1
  %64 = call i32 %53(ptr noundef %56, ptr noundef %57, i64 noundef %58, ptr noundef %59, i32 noundef %60, ptr noundef %61, ptr noundef %63)
  store i32 %64, ptr %19, align 4, !tbaa !11
  %65 = load i32, ptr %19, align 4, !tbaa !11
  switch i32 %65, label %77 [
    i32 0, label %66
    i32 1, label %66
  ]

66:                                               ; preds = %46, %46
  %67 = load ptr, ptr %18, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.onnxifi_graph_wrapper, ptr %67, i32 0, i32 0
  store i32 -642975027, ptr %68, align 8, !tbaa !18
  %69 = load ptr, ptr %16, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.onnxifi_backend_wrapper, ptr %69, i32 0, i32 2
  %71 = load ptr, ptr %70, align 8, !tbaa !15
  %72 = load ptr, ptr %18, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.onnxifi_graph_wrapper, ptr %72, i32 0, i32 2
  store ptr %71, ptr %73, align 8, !tbaa !20
  %74 = load ptr, ptr %18, align 8, !tbaa !5
  %75 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr %74, ptr %75, align 8, !tbaa !5
  %76 = load i32, ptr %19, align 4, !tbaa !11
  store i32 %76, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %80

77:                                               ; preds = %46
  %78 = load ptr, ptr %18, align 8, !tbaa !5
  call void @free(ptr noundef %78) #5
  %79 = load i32, ptr %19, align 4, !tbaa !11
  store i32 %79, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %80

80:                                               ; preds = %77, %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #5
  br label %81

81:                                               ; preds = %80, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #5
  br label %82

82:                                               ; preds = %81, %40, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  br label %83

83:                                               ; preds = %82, %27, %22
  %84 = load i32, ptr %8, align 4
  ret i32 %84
}

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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"onnxifi_backend_wrapper", !12, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!14, !6, i64 16}
!16 = !{!7, !7, i64 0}
!17 = !{!14, !6, i64 8}
!18 = !{!19, !12, i64 0}
!19 = !{!"onnxifi_graph_wrapper", !12, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!19, !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 @onnxInitGraph(ptr noundef readonly %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i32 noundef %4, ptr noundef %5, ptr noundef writeonly %6) local_unnamed_addr #1 {
  %8 = icmp eq ptr %6, null
  br i1 %8, label %30, label %9

9:                                                ; preds = %7
  store ptr null, ptr %6, align 8, !tbaa !5
  %10 = icmp eq ptr %0, null
  br i1 %10, label %30, label %11

11:                                               ; preds = %9
  %12 = load i32, ptr %0, align 8, !tbaa !9
  %.not = icmp eq i32 %12, 1268459778
  br i1 %.not, label %13, label %30

13:                                               ; preds = %11
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = icmp eq ptr %15, null
  br i1 %16, label %30, label %17

17:                                               ; preds = %13
  %calloc = tail call dereferenceable_or_null(24) ptr @calloc(i64 1, i64 24)
  %18 = icmp eq ptr %calloc, null
  br i1 %18, label %30, label %19

19:                                               ; preds = %17
  %20 = getelementptr inbounds i8, ptr %15, i64 104
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = getelementptr inbounds i8, ptr %calloc, i64 8
  %25 = tail call i32 %21(ptr noundef %23, ptr noundef %1, i64 noundef %2, ptr noundef %3, i32 noundef %4, ptr noundef %5, ptr noundef nonnull %24) #3
  %switch = icmp ult i32 %25, 2
  br i1 %switch, label %26, label %29

26:                                               ; preds = %19
  store i32 -642975027, ptr %calloc, align 8, !tbaa !15
  %27 = load ptr, ptr %14, align 8, !tbaa !12
  %28 = getelementptr inbounds i8, ptr %calloc, i64 16
  store ptr %27, ptr %28, align 8, !tbaa !17
  store ptr %calloc, ptr %6, align 8, !tbaa !5
  br label %30

29:                                               ; preds = %19
  tail call void @free(ptr noundef nonnull %calloc) #3
  br label %30

30:                                               ; preds = %11, %13, %26, %29, %17, %9, %7
  %.3 = phi i32 [ 259, %7 ], [ 262, %9 ], [ 262, %11 ], [ 262, %13 ], [ 1025, %17 ], [ %25, %29 ], [ %25, %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_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_graph_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