; LLVM IR from ggml-org/ggml :: examples/simple/simple-backend.ll (Z10load_modelR12simple_modelPfS1_iiii)

; 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.ggml_init_params = type { i64, ptr, i8 }
%struct.simple_model = type { ptr, ptr, ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10load_modelR12simple_modelPfS1_iiii(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6) #0 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca %struct.ggml_init_params, align 8
  %17 = alloca %struct.ggml_init_params, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !9
  store i32 %5, ptr %13, align 4, !tbaa !9
  store i32 %6, ptr %14, align 4, !tbaa !9
  call void @ggml_log_set(ptr noundef @_ZL25ggml_log_callback_default14ggml_log_levelPKcPv, ptr noundef null)
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.simple_model, ptr %18, i32 0, i32 2
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = icmp ne ptr %20, null
  br i1 %21, label %26, label %22

22:                                               ; preds = %7
  %23 = call ptr @ggml_backend_cpu_init()
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.simple_model, ptr %24, i32 0, i32 2
  store ptr %23, ptr %25, align 8, !tbaa !11
  br label %26

26:                                               ; preds = %22, %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 2, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %16) #4
  %27 = getelementptr inbounds %struct.ggml_init_params, ptr %16, i32 0, i32 0
  %28 = call i64 @ggml_tensor_overhead()
  %29 = load i32, ptr %15, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = mul i64 %28, %30
  store i64 %31, ptr %27, align 8, !tbaa !13
  %32 = getelementptr inbounds %struct.ggml_init_params, ptr %16, i32 0, i32 1
  store ptr null, ptr %32, align 8, !tbaa !17
  %33 = getelementptr inbounds %struct.ggml_init_params, ptr %16, i32 0, i32 2
  store i8 1, ptr %33, align 8, !tbaa !18
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %17, ptr align 8 %16, i64 24, i1 false), !tbaa.struct !19
  %34 = call ptr @ggml_init(ptr noundef byval(%struct.ggml_init_params) align 8 %17)
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.simple_model, ptr %35, i32 0, i32 4
  store ptr %34, ptr %36, align 8, !tbaa !22
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.simple_model, ptr %37, i32 0, i32 4
  %39 = load ptr, ptr %38, align 8, !tbaa !22
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = load i32, ptr %11, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = call ptr @ggml_new_tensor_2d(ptr noundef %39, i32 noundef 0, i64 noundef %41, i64 noundef %43)
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.simple_model, ptr %45, i32 0, i32 0
  store ptr %44, ptr %46, align 8, !tbaa !23
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.simple_model, ptr %47, i32 0, i32 4
  %49 = load ptr, ptr %48, align 8, !tbaa !22
  %50 = load i32, ptr %14, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = load i32, ptr %13, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = call ptr @ggml_new_tensor_2d(ptr noundef %49, i32 noundef 0, i64 noundef %51, i64 noundef %53)
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.simple_model, ptr %55, i32 0, i32 1
  store ptr %54, ptr %56, align 8, !tbaa !24
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.simple_model, ptr %57, i32 0, i32 4
  %59 = load ptr, ptr %58, align 8, !tbaa !22
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.simple_model, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !11
  %63 = call ptr @ggml_backend_alloc_ctx_tensors(ptr noundef %59, ptr noundef %62)
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.simple_model, ptr %64, i32 0, i32 3
  store ptr %63, ptr %65, align 8, !tbaa !25
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.simple_model, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !23
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.simple_model, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !23
  %73 = call i64 @ggml_nbytes(ptr noundef %72)
  call void @ggml_backend_tensor_set(ptr noundef %68, ptr noundef %69, i64 noundef 0, i64 noundef %73)
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.simple_model, ptr %74, i32 0, i32 1
  %76 = load ptr, ptr %75, align 8, !tbaa !24
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.simple_model, ptr %78, i32 0, i32 1
  %80 = load ptr, ptr %79, align 8, !tbaa !24
  %81 = call i64 @ggml_nbytes(ptr noundef %80)
  call void @ggml_backend_tensor_set(ptr noundef %76, ptr noundef %77, i64 noundef 0, i64 noundef %81)
  call void @llvm.lifetime.end.p0(i64 24, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  ret void
}

declare void @ggml_log_set(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL25ggml_log_callback_default14ggml_log_levelPKcPv(i32 noundef, ptr noundef, ptr noundef) #0

declare ptr @ggml_backend_cpu_init() #1

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

declare i64 @ggml_tensor_overhead() #1

declare ptr @ggml_init(ptr noundef byval(%struct.ggml_init_params) align 8) #1

; 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

declare ptr @ggml_new_tensor_2d(ptr noundef, i32 noundef, i64 noundef, i64 noundef) #1

declare ptr @ggml_backend_alloc_ctx_tensors(ptr noundef, ptr noundef) #1

declare void @ggml_backend_tensor_set(ptr noundef, ptr noundef, i64 noundef, i64 noundef) #1

declare i64 @ggml_nbytes(ptr noundef) #1

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

attributes #0 = { 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" }
attributes #1 = { "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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"_ZTS12simple_model", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTS16ggml_init_params", !15, i64 0, !6, i64 8, !16, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{!14, !6, i64 8}
!18 = !{!14, !16, i64 16}
!19 = !{i64 0, i64 8, !20, i64 8, i64 8, !5, i64 16, i64 1, !21}
!20 = !{!15, !15, i64 0}
!21 = !{!16, !16, i64 0}
!22 = !{!12, !6, i64 32}
!23 = !{!12, !6, i64 0}
!24 = !{!12, !6, i64 8}
!25 = !{!12, !6, i64 24}


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

%struct.ggml_init_params = type { i64, ptr, i8 }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10load_modelR12simple_modelPfS1_iiii(ptr nocapture noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6) local_unnamed_addr #0 {
  %8 = alloca %struct.ggml_init_params, align 8
  tail call void @ggml_log_set(ptr noundef nonnull @_ZL25ggml_log_callback_default14ggml_log_levelPKcPv, ptr noundef null)
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %11, label %13

11:                                               ; preds = %7
  %12 = tail call ptr @ggml_backend_cpu_init()
  store ptr %12, ptr %9, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %11, %7
  %14 = tail call i64 @ggml_tensor_overhead()
  %15 = shl i64 %14, 1
  store i64 %15, ptr %8, align 8, !tbaa !10
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %8, i64 8
  store ptr null, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !12
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %8, i64 16
  store i8 1, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !13
  %16 = tail call ptr @ggml_init(ptr noundef nonnull byval(%struct.ggml_init_params) align 8 %8)
  %17 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %16, ptr %17, align 8, !tbaa !15
  %18 = sext i32 %4 to i64
  %19 = sext i32 %3 to i64
  %20 = tail call ptr @ggml_new_tensor_2d(ptr noundef %16, i32 noundef 0, i64 noundef %18, i64 noundef %19)
  store ptr %20, ptr %0, align 8, !tbaa !16
  %21 = load ptr, ptr %17, align 8, !tbaa !15
  %22 = sext i32 %6 to i64
  %23 = sext i32 %5 to i64
  %24 = tail call ptr @ggml_new_tensor_2d(ptr noundef %21, i32 noundef 0, i64 noundef %22, i64 noundef %23)
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %24, ptr %25, align 8, !tbaa !17
  %26 = load ptr, ptr %17, align 8, !tbaa !15
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = tail call ptr @ggml_backend_alloc_ctx_tensors(ptr noundef %26, ptr noundef %27)
  %29 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %28, ptr %29, align 8, !tbaa !18
  %30 = load ptr, ptr %0, align 8, !tbaa !16
  %31 = tail call i64 @ggml_nbytes(ptr noundef %30)
  tail call void @ggml_backend_tensor_set(ptr noundef %30, ptr noundef %1, i64 noundef 0, i64 noundef %31)
  %32 = load ptr, ptr %25, align 8, !tbaa !17
  %33 = tail call i64 @ggml_nbytes(ptr noundef %32)
  tail call void @ggml_backend_tensor_set(ptr noundef %32, ptr noundef %2, i64 noundef 0, i64 noundef %33)
  ret void
}

declare void @ggml_log_set(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL25ggml_log_callback_default14ggml_log_levelPKcPv(i32 noundef, ptr noundef, ptr noundef) #0

declare ptr @ggml_backend_cpu_init() local_unnamed_addr #1

declare i64 @ggml_tensor_overhead() local_unnamed_addr #1

declare ptr @ggml_init(ptr noundef byval(%struct.ggml_init_params) align 8) local_unnamed_addr #1

declare ptr @ggml_new_tensor_2d(ptr noundef, i32 noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

declare ptr @ggml_backend_alloc_ctx_tensors(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @ggml_backend_tensor_set(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

declare i64 @ggml_nbytes(ptr noundef) local_unnamed_addr #1

attributes #0 = { 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" }
attributes #1 = { "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, !7, i64 16}
!6 = !{!"_ZTS12simple_model", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"bool", !8, i64 0}
!15 = !{!6, !7, i64 32}
!16 = !{!6, !7, i64 0}
!17 = !{!6, !7, i64 8}
!18 = !{!6, !7, i64 24}


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