; LLVM IR from ggml-org/ggml :: examples/simple/simple-ctx.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 }
%struct.ggml_tensor = type { i32, ptr, [4 x i64], [4 x i64], i32, [16 x i32], i32, [10 x ptr], ptr, i64, ptr, [64 x i8], ptr, [8 x i8] }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10load_modelR12simple_modelPfS1_iiii(ptr noundef nonnull align 8 dereferenceable(24) %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 i64, align 8
  %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 @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  store i64 0, ptr %15, align 8, !tbaa !11
  %18 = load i32, ptr %11, align 4, !tbaa !9
  %19 = load i32, ptr %12, align 4, !tbaa !9
  %20 = mul nsw i32 %18, %19
  %21 = sext i32 %20 to i64
  %22 = call i64 @ggml_type_size(i32 noundef 0)
  %23 = mul i64 %21, %22
  %24 = load i64, ptr %15, align 8, !tbaa !11
  %25 = add i64 %24, %23
  store i64 %25, ptr %15, align 8, !tbaa !11
  %26 = load i32, ptr %13, align 4, !tbaa !9
  %27 = load i32, ptr %14, align 4, !tbaa !9
  %28 = mul nsw i32 %26, %27
  %29 = sext i32 %28 to i64
  %30 = call i64 @ggml_type_size(i32 noundef 0)
  %31 = mul i64 %29, %30
  %32 = load i64, ptr %15, align 8, !tbaa !11
  %33 = add i64 %32, %31
  store i64 %33, ptr %15, align 8, !tbaa !11
  %34 = call i64 @ggml_tensor_overhead()
  %35 = mul i64 2, %34
  %36 = load i64, ptr %15, align 8, !tbaa !11
  %37 = add i64 %36, %35
  store i64 %37, ptr %15, align 8, !tbaa !11
  %38 = call i64 @ggml_graph_overhead()
  %39 = load i64, ptr %15, align 8, !tbaa !11
  %40 = add i64 %39, %38
  store i64 %40, ptr %15, align 8, !tbaa !11
  %41 = load i64, ptr %15, align 8, !tbaa !11
  %42 = add i64 %41, 1024
  store i64 %42, ptr %15, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 24, ptr %16) #4
  %43 = getelementptr inbounds %struct.ggml_init_params, ptr %16, i32 0, i32 0
  %44 = load i64, ptr %15, align 8, !tbaa !11
  store i64 %44, ptr %43, align 8, !tbaa !13
  %45 = getelementptr inbounds %struct.ggml_init_params, ptr %16, i32 0, i32 1
  store ptr null, ptr %45, align 8, !tbaa !16
  %46 = getelementptr inbounds %struct.ggml_init_params, ptr %16, i32 0, i32 2
  store i8 0, ptr %46, align 8, !tbaa !17
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %17, ptr align 8 %16, i64 24, i1 false), !tbaa.struct !18
  %47 = call ptr @ggml_init(ptr noundef byval(%struct.ggml_init_params) align 8 %17)
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.simple_model, ptr %48, i32 0, i32 2
  store ptr %47, ptr %49, align 8, !tbaa !20
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.simple_model, ptr %50, i32 0, i32 2
  %52 = load ptr, ptr %51, align 8, !tbaa !20
  %53 = load i32, ptr %12, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = load i32, ptr %11, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = call ptr @ggml_new_tensor_2d(ptr noundef %52, i32 noundef 0, i64 noundef %54, i64 noundef %56)
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.simple_model, ptr %58, i32 0, i32 0
  store ptr %57, ptr %59, 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 !20
  %63 = load i32, ptr %14, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = load i32, ptr %13, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = call ptr @ggml_new_tensor_2d(ptr noundef %62, i32 noundef 0, i64 noundef %64, i64 noundef %66)
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.simple_model, ptr %68, i32 0, i32 1
  store ptr %67, ptr %69, align 8, !tbaa !23
  %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 !22
  %73 = getelementptr inbounds %struct.ggml_tensor, ptr %72, i32 0, i32 10
  %74 = load ptr, ptr %73, align 8, !tbaa !24
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.simple_model, ptr %76, i32 0, i32 0
  %78 = load ptr, ptr %77, align 8, !tbaa !22
  %79 = call i64 @ggml_nbytes(ptr noundef %78)
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %74, ptr align 4 %75, i64 %79, i1 false)
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.simple_model, ptr %80, i32 0, i32 1
  %82 = load ptr, ptr %81, align 8, !tbaa !23
  %83 = getelementptr inbounds %struct.ggml_tensor, ptr %82, i32 0, i32 10
  %84 = load ptr, ptr %83, align 8, !tbaa !24
  %85 = load ptr, ptr %10, align 8, !tbaa !5
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.simple_model, ptr %86, i32 0, i32 1
  %88 = load ptr, ptr %87, align 8, !tbaa !23
  %89 = call i64 @ggml_nbytes(ptr noundef %88)
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %84, ptr align 4 %85, i64 %89, i1 false)
  call void @llvm.lifetime.end.p0(i64 24, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  ret void
}

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

declare i64 @ggml_type_size(i32 noundef) #2

declare i64 @ggml_tensor_overhead() #2

declare i64 @ggml_graph_overhead() #2

declare ptr @ggml_init(ptr noundef byval(%struct.ggml_init_params) align 8) #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

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

declare i64 @ggml_nbytes(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 }

!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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_ZTS16ggml_init_params", !12, i64 0, !6, i64 8, !15, i64 16}
!15 = !{!"bool", !7, i64 0}
!16 = !{!14, !6, i64 8}
!17 = !{!14, !15, i64 16}
!18 = !{i64 0, i64 8, !11, i64 8, i64 8, !5, i64 16, i64 1, !19}
!19 = !{!15, !15, i64 0}
!20 = !{!21, !6, i64 16}
!21 = !{!"_ZTS12simple_model", !6, i64 0, !6, i64 8, !6, i64 16}
!22 = !{!21, !6, i64 0}
!23 = !{!21, !6, i64 8}
!24 = !{!25, !6, i64 248}
!25 = !{!"_ZTS11ggml_tensor", !26, i64 0, !6, i64 8, !7, i64 16, !7, i64 48, !27, i64 80, !7, i64 84, !10, i64 148, !7, i64 152, !6, i64 232, !12, i64 240, !6, i64 248, !7, i64 256, !6, i64 320, !7, i64 328}
!26 = !{!"_ZTS9ggml_type", !7, i64 0}
!27 = !{!"_ZTS7ggml_op", !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"

%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(24) %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %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
  %9 = mul nsw i32 %4, %3
  %10 = sext i32 %9 to i64
  %11 = tail call i64 @ggml_type_size(i32 noundef 0)
  %12 = mul i64 %11, %10
  %13 = mul nsw i32 %6, %5
  %14 = sext i32 %13 to i64
  %15 = tail call i64 @ggml_type_size(i32 noundef 0)
  %16 = mul i64 %15, %14
  %17 = tail call i64 @ggml_tensor_overhead()
  %18 = shl i64 %17, 1
  %19 = tail call i64 @ggml_graph_overhead()
  %20 = add i64 %12, 1024
  %21 = add i64 %20, %16
  %22 = add i64 %21, %18
  %23 = add i64 %22, %19
  store i64 %23, ptr %8, align 8, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %8, i64 8
  store ptr null, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !9
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %8, i64 16
  store i8 0, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !11
  %24 = tail call ptr @ggml_init(ptr noundef nonnull byval(%struct.ggml_init_params) align 8 %8)
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %24, ptr %25, align 8, !tbaa !13
  %26 = sext i32 %4 to i64
  %27 = sext i32 %3 to i64
  %28 = tail call ptr @ggml_new_tensor_2d(ptr noundef %24, i32 noundef 0, i64 noundef %26, i64 noundef %27)
  store ptr %28, ptr %0, align 8, !tbaa !15
  %29 = load ptr, ptr %25, align 8, !tbaa !13
  %30 = sext i32 %6 to i64
  %31 = sext i32 %5 to i64
  %32 = tail call ptr @ggml_new_tensor_2d(ptr noundef %29, i32 noundef 0, i64 noundef %30, i64 noundef %31)
  %33 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %32, ptr %33, align 8, !tbaa !16
  %34 = load ptr, ptr %0, align 8, !tbaa !15
  %35 = getelementptr inbounds i8, ptr %34, i64 248
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  %37 = tail call i64 @ggml_nbytes(ptr noundef %34)
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %36, ptr align 4 %1, i64 %37, i1 false)
  %38 = load ptr, ptr %33, align 8, !tbaa !16
  %39 = getelementptr inbounds i8, ptr %38, i64 248
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  %41 = tail call i64 @ggml_nbytes(ptr noundef %38)
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %40, ptr align 4 %2, i64 %41, i1 false)
  ret void
}

declare i64 @ggml_type_size(i32 noundef) local_unnamed_addr #1

declare i64 @ggml_tensor_overhead() local_unnamed_addr #1

declare i64 @ggml_graph_overhead() local_unnamed_addr #1

declare ptr @ggml_init(ptr noundef byval(%struct.ggml_init_params) align 8) 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

declare ptr @ggml_new_tensor_2d(ptr noundef, i32 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" }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !10, i64 16}
!14 = !{!"_ZTS12simple_model", !10, i64 0, !10, i64 8, !10, i64 16}
!15 = !{!14, !10, i64 0}
!16 = !{!14, !10, i64 8}
!17 = !{!18, !10, i64 248}
!18 = !{!"_ZTS11ggml_tensor", !19, i64 0, !10, i64 8, !7, i64 16, !7, i64 48, !20, i64 80, !7, i64 84, !21, i64 148, !7, i64 152, !10, i64 232, !6, i64 240, !10, i64 248, !7, i64 256, !10, i64 320, !7, i64 328}
!19 = !{!"_ZTS9ggml_type", !7, i64 0}
!20 = !{!"_ZTS7ggml_op", !7, i64 0}
!21 = !{!"int", !7, i64 0}


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