; LLVM IR from ggml-org/ggml :: examples/mnist/mnist-common.ll (Z16mnist_model_evalR11mnist_modelP16ggml_opt_dataset)

; 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_opt_params = type { ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr }
%struct.mnist_model = type { %"class.std::__cxx11::basic_string", ptr, %"class.std::vector", i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon.0 }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon.0 = type { i64, [8 x i8] }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<ggml_backend *, std::allocator<ggml_backend *>>::_Vector_impl" }
%"struct.std::_Vector_base<ggml_backend *, std::allocator<ggml_backend *>>::_Vector_impl" = type { %"struct.std::_Vector_base<ggml_backend *, std::allocator<ggml_backend *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<ggml_backend *, std::allocator<ggml_backend *>>::_Vector_impl_data" = 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] }

@stderr = external global ptr, align 8
@.str.105 = external hidden unnamed_addr constant [65 x i8], align 1
@__func__._Z16mnist_model_evalR11mnist_modelP16ggml_opt_dataset = external hidden unnamed_addr constant [17 x i8], align 1

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

declare ptr @ggml_opt_dataset_data(ptr noundef) #2

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

; 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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z16mnist_model_evalR11mnist_modelP16ggml_opt_dataset(ptr noundef nonnull align 8 dereferenceable(208) %0, ptr noundef %1) #4 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.ggml_opt_params, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.ggml_opt_params, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %13 = call ptr @ggml_opt_result_init()
  store ptr %13, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %6) #5
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.mnist_model, ptr %14, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.mnist_model, ptr %17, i32 0, i32 19
  %19 = load ptr, ptr %18, align 8, !tbaa !19
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.mnist_model, ptr %20, i32 0, i32 5
  %22 = load ptr, ptr %21, align 8, !tbaa !20
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.mnist_model, ptr %23, i32 0, i32 6
  %25 = load ptr, ptr %24, align 8, !tbaa !21
  call void @ggml_opt_default_params(ptr dead_on_unwind writable sret(%struct.ggml_opt_params) align 8 %6, ptr noundef %16, ptr noundef %19, ptr noundef %22, ptr noundef %25, i32 noundef 2)
  %26 = getelementptr inbounds %struct.ggml_opt_params, ptr %6, i32 0, i32 5
  store i32 0, ptr %26, align 4, !tbaa !22
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %6, i64 64, i1 false), !tbaa.struct !26
  %27 = call ptr @ggml_opt_init(ptr noundef byval(%struct.ggml_opt_params) align 8 %8)
  store ptr %27, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %28 = call i64 @ggml_time_us()
  store i64 %28, ptr %9, align 8, !tbaa !30
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  call void @ggml_opt_epoch(ptr noundef %29, ptr noundef %30, ptr noundef null, ptr noundef %31, i64 noundef 0, ptr noundef null, ptr noundef null)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %32 = call i64 @ggml_time_us()
  %33 = load i64, ptr %9, align 8, !tbaa !30
  %34 = sub nsw i64 %32, %33
  store i64 %34, ptr %10, align 8, !tbaa !30
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %35 = load i64, ptr %10, align 8, !tbaa !30
  %36 = sitofp i64 %35 to double
  %37 = fmul double 1.000000e-03, %36
  store double %37, ptr %11, align 8, !tbaa !31
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = call ptr @ggml_opt_dataset_data(ptr noundef %38)
  %40 = getelementptr inbounds %struct.ggml_tensor, ptr %39, i32 0, i32 2
  %41 = getelementptr inbounds [4 x i64], ptr %40, i64 0, i64 1
  %42 = load i64, ptr %41, align 8, !tbaa !30
  %43 = trunc i64 %42 to i32
  store i32 %43, ptr %12, align 4, !tbaa !29
  %44 = load ptr, ptr @stderr, align 8, !tbaa !5
  %45 = load i32, ptr %12, align 4, !tbaa !29
  %46 = load double, ptr %11, align 8, !tbaa !31
  %47 = load i64, ptr %10, align 8, !tbaa !30
  %48 = sitofp i64 %47 to double
  %49 = load i32, ptr %12, align 4, !tbaa !29
  %50 = sitofp i32 %49 to double
  %51 = fdiv double %48, %50
  %52 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %44, ptr noundef @.str.105, ptr noundef @__func__._Z16mnist_model_evalR11mnist_modelP16ggml_opt_dataset, i32 noundef %45, double noundef %46, double noundef %51) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ggml_opt_free(ptr noundef %53)
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret ptr %54
}

declare ptr @ggml_opt_result_init() #2

declare void @ggml_opt_default_params(ptr dead_on_unwind writable sret(%struct.ggml_opt_params) align 8, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

declare ptr @ggml_opt_init(ptr noundef byval(%struct.ggml_opt_params) align 8) #2

declare i64 @ggml_time_us() #2

declare void @ggml_opt_epoch(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

declare void @ggml_opt_free(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 #5 = { 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, !6, i64 32}
!10 = !{!"_ZTS11mnist_model", !11, i64 0, !6, i64 32, !14, i64 40, !18, i64 64, !18, i64 68, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200}
!11 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !12, i64 0, !13, i64 8, !7, i64 16}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_ZTSSt6vectorIP12ggml_backendSaIS1_EE", !15, i64 0}
!15 = !{!"_ZTSSt12_Vector_baseIP12ggml_backendSaIS1_EE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIP12ggml_backendSaIS1_EE12_Vector_implE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIP12ggml_backendSaIS1_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!"int", !7, i64 0}
!19 = !{!10, !6, i64 184}
!20 = !{!10, !6, i64 72}
!21 = !{!10, !6, i64 80}
!22 = !{!23, !25, i64 36}
!23 = !{!"_ZTS15ggml_opt_params", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !24, i64 32, !25, i64 36, !18, i64 40, !6, i64 48, !6, i64 56}
!24 = !{!"_ZTS18ggml_opt_loss_type", !7, i64 0}
!25 = !{!"_ZTS19ggml_opt_build_type", !7, i64 0}
!26 = !{i64 0, i64 8, !5, i64 8, i64 8, !5, i64 16, i64 8, !5, i64 24, i64 8, !5, i64 32, i64 4, !27, i64 36, i64 4, !28, i64 40, i64 4, !29, i64 48, i64 8, !5, i64 56, i64 8, !5}
!27 = !{!24, !24, i64 0}
!28 = !{!25, !25, i64 0}
!29 = !{!18, !18, i64 0}
!30 = !{!13, !13, i64 0}
!31 = !{!32, !32, i64 0}
!32 = !{!"double", !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_opt_params = type { ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr }

@stderr = external local_unnamed_addr global ptr, align 8
@.str.105 = external hidden unnamed_addr constant [65 x i8], align 1
@__func__._Z16mnist_model_evalR11mnist_modelP16ggml_opt_dataset = external hidden unnamed_addr constant [17 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

declare ptr @ggml_opt_dataset_data(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z16mnist_model_evalR11mnist_modelP16ggml_opt_dataset(ptr nocapture noundef nonnull readonly align 8 dereferenceable(208) %0, ptr noundef %1) local_unnamed_addr #3 {
  %3 = alloca %struct.ggml_opt_params, align 8
  %4 = tail call ptr @ggml_opt_result_init()
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %3) #4
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 184
  %8 = load ptr, ptr %7, align 8, !tbaa !18
  %9 = getelementptr inbounds i8, ptr %0, i64 72
  %10 = load ptr, ptr %9, align 8, !tbaa !19
  %11 = getelementptr inbounds i8, ptr %0, i64 80
  %12 = load ptr, ptr %11, align 8, !tbaa !20
  call void @ggml_opt_default_params(ptr dead_on_unwind nonnull writable sret(%struct.ggml_opt_params) align 8 %3, ptr noundef %6, ptr noundef %8, ptr noundef %10, ptr noundef %12, i32 noundef 2)
  %13 = getelementptr inbounds i8, ptr %3, i64 36
  store i32 0, ptr %13, align 4, !tbaa !21
  %14 = call ptr @ggml_opt_init(ptr noundef nonnull byval(%struct.ggml_opt_params) align 8 %3)
  %15 = call i64 @ggml_time_us()
  call void @ggml_opt_epoch(ptr noundef %14, ptr noundef %1, ptr noundef null, ptr noundef %4, i64 noundef 0, ptr noundef null, ptr noundef null)
  %16 = call i64 @ggml_time_us()
  %17 = sub nsw i64 %16, %15
  %18 = sitofp i64 %17 to double
  %19 = fmul double %18, 1.000000e-03
  %20 = call ptr @ggml_opt_dataset_data(ptr noundef %1)
  %21 = getelementptr inbounds i8, ptr %20, i64 24
  %22 = load i64, ptr %21, align 8, !tbaa !25
  %23 = trunc i64 %22 to i32
  %24 = load ptr, ptr @stderr, align 8, !tbaa !26
  %25 = sitofp i32 %23 to double
  %26 = fdiv double %18, %25
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str.105, ptr noundef nonnull @__func__._Z16mnist_model_evalR11mnist_modelP16ggml_opt_dataset, i32 noundef %23, double noundef %19, double noundef %26) #5
  call void @ggml_opt_free(ptr noundef %14)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #4
  ret ptr %4
}

declare ptr @ggml_opt_result_init() local_unnamed_addr #2

declare void @ggml_opt_default_params(ptr dead_on_unwind writable sret(%struct.ggml_opt_params) align 8, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare ptr @ggml_opt_init(ptr noundef byval(%struct.ggml_opt_params) align 8) local_unnamed_addr #2

declare i64 @ggml_time_us() local_unnamed_addr #2

declare void @ggml_opt_epoch(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @ggml_opt_free(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree 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 #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 = { 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 #4 = { nounwind }
attributes #5 = { cold 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, !9, i64 32}
!6 = !{!"_ZTS11mnist_model", !7, i64 0, !9, i64 32, !13, i64 40, !17, i64 64, !17, i64 68, !9, i64 72, !9, i64 80, !9, i64 88, !9, i64 96, !9, i64 104, !9, i64 112, !9, i64 120, !9, i64 128, !9, i64 136, !9, i64 144, !9, i64 152, !9, i64 160, !9, i64 168, !9, i64 176, !9, i64 184, !9, i64 192, !9, i64 200}
!7 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !8, i64 0, !12, i64 8, !10, i64 16}
!8 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !9, i64 0}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"long", !10, i64 0}
!13 = !{!"_ZTSSt6vectorIP12ggml_backendSaIS1_EE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIP12ggml_backendSaIS1_EE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIP12ggml_backendSaIS1_EE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIP12ggml_backendSaIS1_EE17_Vector_impl_dataE", !9, i64 0, !9, i64 8, !9, i64 16}
!17 = !{!"int", !10, i64 0}
!18 = !{!6, !9, i64 184}
!19 = !{!6, !9, i64 72}
!20 = !{!6, !9, i64 80}
!21 = !{!22, !24, i64 36}
!22 = !{!"_ZTS15ggml_opt_params", !9, i64 0, !9, i64 8, !9, i64 16, !9, i64 24, !23, i64 32, !24, i64 36, !17, i64 40, !9, i64 48, !9, i64 56}
!23 = !{!"_ZTS18ggml_opt_loss_type", !10, i64 0}
!24 = !{!"_ZTS19ggml_opt_build_type", !10, i64 0}
!25 = !{!12, !12, i64 0}
!26 = !{!9, !9, i64 0}


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