; LLVM IR from ggml-org/ggml :: src (ggml-opt)

; 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_context = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %"class.std::mersenne_twister_engine", ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i32, i32, i8, ptr, ptr, ptr }
%"class.std::mersenne_twister_engine" = type { [624 x i64], i64 }

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @ggml_opt_reset(ptr noundef, i1 noundef zeroext) #1

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL19ggml_opt_eval_graphP16ggml_opt_contextP11ggml_cgraphP15ggml_opt_result(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @ggml_opt_forward_backward(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.ggml_opt_context, ptr %6, i32 0, i32 20
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = icmp eq i32 %8, 1
  br i1 %9, label %10, label %16

10:                                               ; preds = %2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ggml_opt_context, ptr %12, i32 0, i32 18
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZL19ggml_opt_eval_graphP16ggml_opt_contextP11ggml_cgraphP15ggml_opt_result(ptr noundef %11, ptr noundef %14, ptr noundef %15)
  br label %44

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ggml_opt_context, ptr %17, i32 0, i32 21
  %19 = load i32, ptr %18, align 4, !tbaa !16
  %20 = add nsw i32 %19, 1
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ggml_opt_context, ptr %21, i32 0, i32 20
  %23 = load i32, ptr %22, align 8, !tbaa !9
  %24 = srem i32 %20, %23
  store i32 %24, ptr %5, align 4, !tbaa !17
  %25 = load i32, ptr %5, align 4, !tbaa !17
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %34

27:                                               ; preds = %16
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ggml_opt_context, ptr %29, i32 0, i32 18
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZL19ggml_opt_eval_graphP16ggml_opt_contextP11ggml_cgraphP15ggml_opt_result(ptr noundef %28, ptr noundef %31, ptr noundef %32)
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  call void @ggml_opt_reset(ptr noundef %33, i1 noundef zeroext false)
  br label %40

34:                                               ; preds = %16
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ggml_opt_context, ptr %36, i32 0, i32 17
  %38 = load ptr, ptr %37, align 8, !tbaa !18
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZL19ggml_opt_eval_graphP16ggml_opt_contextP11ggml_cgraphP15ggml_opt_result(ptr noundef %35, ptr noundef %38, ptr noundef %39)
  br label %40

40:                                               ; preds = %34, %27
  %41 = load i32, ptr %5, align 4, !tbaa !17
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.ggml_opt_context, ptr %42, i32 0, i32 21
  store i32 %41, ptr %43, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %44

44:                                               ; preds = %40, %10
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !13, i64 5152}
!10 = !{!"_ZTS16ggml_opt_context", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !11, i64 72, !6, i64 5072, !6, i64 5080, !6, i64 5088, !6, i64 5096, !6, i64 5104, !6, i64 5112, !6, i64 5120, !6, i64 5128, !6, i64 5136, !12, i64 5144, !13, i64 5152, !13, i64 5156, !14, i64 5160, !6, i64 5168, !6, i64 5176, !6, i64 5184}
!11 = !{!"_ZTSSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE", !7, i64 0, !12, i64 4992}
!12 = !{!"long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!10, !6, i64 5136}
!16 = !{!10, !13, i64 5156}
!17 = !{!13, !13, i64 0}
!18 = !{!10, !6, i64 5128}


; 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 uwtable
declare dso_local void @ggml_opt_reset(ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @ggml_opt_forward_backward(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 5152
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp eq i32 %4, 1
  br i1 %5, label %6, label %9

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 5136
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  tail call void @_ZL19ggml_opt_eval_graphP16ggml_opt_contextP11ggml_cgraphP15ggml_opt_result(ptr noundef nonnull %0, ptr noundef %8, ptr noundef %1)
  br label %22

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %0, i64 5156
  %11 = load i32, ptr %10, align 4, !tbaa !15
  %12 = add nsw i32 %11, 1
  %13 = srem i32 %12, %4
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %18

15:                                               ; preds = %9
  %16 = getelementptr inbounds i8, ptr %0, i64 5136
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  tail call void @_ZL19ggml_opt_eval_graphP16ggml_opt_contextP11ggml_cgraphP15ggml_opt_result(ptr noundef nonnull %0, ptr noundef %17, ptr noundef %1)
  tail call void @ggml_opt_reset(ptr noundef nonnull %0, i1 noundef zeroext false)
  br label %21

18:                                               ; preds = %9
  %19 = getelementptr inbounds i8, ptr %0, i64 5128
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  tail call void @_ZL19ggml_opt_eval_graphP16ggml_opt_contextP11ggml_cgraphP15ggml_opt_result(ptr noundef nonnull %0, ptr noundef %20, ptr noundef %1)
  br label %21

21:                                               ; preds = %18, %15
  store i32 %13, ptr %10, align 4, !tbaa !15
  br label %22

22:                                               ; preds = %21, %6
  ret void
}

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

!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, !12, i64 5152}
!6 = !{!"_ZTS16ggml_opt_context", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !10, i64 72, !7, i64 5072, !7, i64 5080, !7, i64 5088, !7, i64 5096, !7, i64 5104, !7, i64 5112, !7, i64 5120, !7, i64 5128, !7, i64 5136, !11, i64 5144, !12, i64 5152, !12, i64 5156, !13, i64 5160, !7, i64 5168, !7, i64 5176, !7, i64 5184}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EE", !8, i64 0, !11, i64 4992}
!11 = !{!"long", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"bool", !8, i64 0}
!14 = !{!6, !7, i64 5136}
!15 = !{!6, !12, i64 5156}
!16 = !{!6, !7, i64 5128}


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