; LLVM IR from hans-ob1/neural_cam_ros :: src/detector (network)

; 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.network = type { ptr, i32, i32, ptr, float, i32, float, float, ptr, i32, ptr, i32, float, float, float, float, i32, i32, i32, ptr, ptr, i32, i32, i32, float, float, float, i32, i32, i32, i32, i32, i32, float, float, float, float, float, i32, ptr }
%struct.data = type { i32, i32, %struct.matrix, %struct.matrix, i32, ptr, ptr }
%struct.matrix = type { i32, i32, ptr }

; 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: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local float @train_network_datum(ptr noundef byval(%struct.network) align 8, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local float @train_network_sgd(ptr noundef byval(%struct.network) align 8 %0, ptr noundef byval(%struct.data) align 8 %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  store i32 %2, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %11 = getelementptr inbounds %struct.network, ptr %0, i32 0, i32 2
  %12 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %12, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = getelementptr inbounds %struct.data, ptr %1, i32 0, i32 2
  %15 = getelementptr inbounds %struct.matrix, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !13
  %17 = mul nsw i32 %13, %16
  %18 = sext i32 %17 to i64
  %19 = call noalias ptr @calloc(i64 noundef %18, i64 noundef 4) #6
  store ptr %19, ptr %6, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = getelementptr inbounds %struct.data, ptr %1, i32 0, i32 3
  %22 = getelementptr inbounds %struct.matrix, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !17
  %24 = mul nsw i32 %20, %23
  %25 = sext i32 %24 to i64
  %26 = call noalias ptr @calloc(i64 noundef %25, i64 noundef 4) #6
  store ptr %26, ptr %7, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store float 0.000000e+00, ptr %9, align 4, !tbaa !18
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %41, %3
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %31, label %44

31:                                               ; preds = %27
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = load ptr, ptr %6, align 8, !tbaa !16
  %34 = load ptr, ptr %7, align 8, !tbaa !16
  call void @get_random_batch(ptr noundef byval(%struct.data) align 8 %1, i32 noundef %32, ptr noundef %33, ptr noundef %34)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %35 = load ptr, ptr %6, align 8, !tbaa !16
  %36 = load ptr, ptr %7, align 8, !tbaa !16
  %37 = call float @train_network_datum(ptr noundef byval(%struct.network) align 8 %0, ptr noundef %35, ptr noundef %36)
  store float %37, ptr %10, align 4, !tbaa !18
  %38 = load float, ptr %10, align 4, !tbaa !18
  %39 = load float, ptr %9, align 4, !tbaa !18
  %40 = fadd float %39, %38
  store float %40, ptr %9, align 4, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %41

41:                                               ; preds = %31
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %8, align 4, !tbaa !5
  br label %27, !llvm.loop !19

44:                                               ; preds = %27
  %45 = load ptr, ptr %6, align 8, !tbaa !16
  call void @free(ptr noundef %45) #5
  %46 = load ptr, ptr %7, align 8, !tbaa !16
  call void @free(ptr noundef %46) #5
  %47 = load float, ptr %9, align 4, !tbaa !18
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = mul nsw i32 %48, %49
  %51 = sitofp i32 %50 to float
  %52 = fdiv float %47, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret float %52
}

declare void @get_random_batch(ptr noundef byval(%struct.data) align 8, i32 noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(0,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 = { 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 #3 = { "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 "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,1) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 12}
!10 = !{!"network", !11, i64 0, !6, i64 8, !6, i64 12, !11, i64 16, !12, i64 24, !6, i64 28, !12, i64 32, !12, i64 36, !11, i64 40, !6, i64 48, !11, i64 56, !6, i64 64, !12, i64 68, !12, i64 72, !12, i64 76, !12, i64 80, !6, i64 84, !6, i64 88, !6, i64 92, !11, i64 96, !11, i64 104, !6, i64 112, !6, i64 116, !6, i64 120, !12, i64 124, !12, i64 128, !12, i64 132, !6, i64 136, !6, i64 140, !6, i64 144, !6, i64 148, !6, i64 152, !6, i64 156, !12, i64 160, !12, i64 164, !12, i64 168, !12, i64 172, !12, i64 176, !6, i64 180, !11, i64 184}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !6, i64 12}
!14 = !{!"", !6, i64 0, !6, i64 4, !15, i64 8, !15, i64 24, !6, i64 40, !11, i64 48, !11, i64 56}
!15 = !{!"matrix", !6, i64 0, !6, i64 4, !11, i64 8}
!16 = !{!11, !11, i64 0}
!17 = !{!14, !6, i64 28}
!18 = !{!12, !12, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; 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.network = type { ptr, i32, i32, ptr, float, i32, float, float, ptr, i32, ptr, i32, float, float, float, float, i32, i32, i32, ptr, ptr, i32, i32, i32, float, float, float, i32, i32, i32, i32, i32, i32, float, float, float, float, float, i32, ptr }
%struct.data = type { i32, i32, %struct.matrix, %struct.matrix, i32, ptr, ptr }
%struct.matrix = type { i32, i32, ptr }

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local float @train_network_datum(ptr noundef byval(%struct.network) align 8, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local float @train_network_sgd(ptr noundef byval(%struct.network) align 8 %0, ptr noundef byval(%struct.data) align 8 %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !12
  %8 = mul nsw i32 %7, %5
  %9 = sext i32 %8 to i64
  %10 = tail call noalias ptr @calloc(i64 noundef %9, i64 noundef 4) #4
  %11 = getelementptr inbounds i8, ptr %1, i64 28
  %12 = load i32, ptr %11, align 4, !tbaa !15
  %13 = mul nsw i32 %12, %5
  %14 = sext i32 %13 to i64
  %15 = tail call noalias ptr @calloc(i64 noundef %14, i64 noundef 4) #4
  %16 = icmp sgt i32 %2, 0
  br i1 %16, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.019 = phi i32 [ %19, %.lr.ph ], [ 0, %3 ]
  %.01618 = phi float [ %18, %.lr.ph ], [ 0.000000e+00, %3 ]
  tail call void @get_random_batch(ptr noundef nonnull byval(%struct.data) align 8 %1, i32 noundef %5, ptr noundef %10, ptr noundef %15) #5
  %17 = tail call float @train_network_datum(ptr noundef nonnull byval(%struct.network) align 8 %0, ptr noundef %10, ptr noundef %15)
  %18 = fadd float %.01618, %17
  %19 = add nuw nsw i32 %.019, 1
  %exitcond.not = icmp eq i32 %19, %2
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.016.lcssa = phi float [ 0.000000e+00, %3 ], [ %18, %.lr.ph ]
  tail call void @free(ptr noundef %10) #5
  tail call void @free(ptr noundef %15) #5
  %20 = mul nsw i32 %5, %2
  %21 = sitofp i32 %20 to float
  %22 = fdiv float %.016.lcssa, %21
  ret float %22
}

declare void @get_random_batch(ptr noundef byval(%struct.data) align 8, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(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 = { "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 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 #4 = { nounwind allocsize(0,1) }
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, !10, i64 12}
!6 = !{!"network", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16, !11, i64 24, !10, i64 28, !11, i64 32, !11, i64 36, !7, i64 40, !10, i64 48, !7, i64 56, !10, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !7, i64 96, !7, i64 104, !10, i64 112, !10, i64 116, !10, i64 120, !11, i64 124, !11, i64 128, !11, i64 132, !10, i64 136, !10, i64 140, !10, i64 144, !10, i64 148, !10, i64 152, !10, i64 156, !11, i64 160, !11, i64 164, !11, i64 168, !11, i64 172, !11, i64 176, !10, i64 180, !7, i64 184}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!13, !10, i64 12}
!13 = !{!"", !10, i64 0, !10, i64 4, !14, i64 8, !14, i64 24, !10, i64 40, !7, i64 48, !7, i64 56}
!14 = !{!"matrix", !10, i64 0, !10, i64 4, !7, i64 8}
!15 = !{!13, !10, i64 28}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass