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

@.str.23 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [80 x i8], align 1
@__PRETTY_FUNCTION__.train_network = external hidden unnamed_addr constant [35 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: 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
declare void @free(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local float @train_network(ptr noundef byval(%struct.network) align 8 %0, ptr noundef byval(%struct.data) align 8 %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = getelementptr inbounds %struct.data, ptr %1, i32 0, i32 2
  %11 = getelementptr inbounds %struct.matrix, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.network, ptr %0, i32 0, i32 2
  %14 = load i32, ptr %13, align 4, !tbaa !12
  %15 = srem i32 %12, %14
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %2
  br label %19

18:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.23, ptr noundef @.str.24, i32 noundef 265, ptr noundef @__PRETTY_FUNCTION__.train_network) #6
  unreachable

19:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #7
  %20 = getelementptr inbounds %struct.network, ptr %0, i32 0, i32 2
  %21 = load i32, ptr %20, align 4, !tbaa !12
  store i32 %21, ptr %3, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  %22 = getelementptr inbounds %struct.data, ptr %1, i32 0, i32 2
  %23 = getelementptr inbounds %struct.matrix, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !5
  %25 = load i32, ptr %3, align 4, !tbaa !15
  %26 = sdiv i32 %24, %25
  store i32 %26, ptr %4, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  %27 = load i32, ptr %3, align 4, !tbaa !15
  %28 = getelementptr inbounds %struct.data, ptr %1, i32 0, i32 2
  %29 = getelementptr inbounds %struct.matrix, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !16
  %31 = mul nsw i32 %27, %30
  %32 = sext i32 %31 to i64
  %33 = call noalias ptr @calloc(i64 noundef %32, i64 noundef 4) #8
  store ptr %33, ptr %5, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  %34 = load i32, ptr %3, align 4, !tbaa !15
  %35 = getelementptr inbounds %struct.data, ptr %1, i32 0, i32 3
  %36 = getelementptr inbounds %struct.matrix, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !18
  %38 = mul nsw i32 %34, %37
  %39 = sext i32 %38 to i64
  %40 = call noalias ptr @calloc(i64 noundef %39, i64 noundef 4) #8
  store ptr %40, ptr %6, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  store float 0.000000e+00, ptr %8, align 4, !tbaa !19
  store i32 0, ptr %7, align 4, !tbaa !15
  br label %41

41:                                               ; preds = %58, %19
  %42 = load i32, ptr %7, align 4, !tbaa !15
  %43 = load i32, ptr %4, align 4, !tbaa !15
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %45, label %61

45:                                               ; preds = %41
  %46 = load i32, ptr %3, align 4, !tbaa !15
  %47 = load i32, ptr %7, align 4, !tbaa !15
  %48 = load i32, ptr %3, align 4, !tbaa !15
  %49 = mul nsw i32 %47, %48
  %50 = load ptr, ptr %5, align 8, !tbaa !17
  %51 = load ptr, ptr %6, align 8, !tbaa !17
  call void @get_next_batch(ptr noundef byval(%struct.data) align 8 %1, i32 noundef %46, i32 noundef %49, ptr noundef %50, ptr noundef %51)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  %52 = load ptr, ptr %5, align 8, !tbaa !17
  %53 = load ptr, ptr %6, align 8, !tbaa !17
  %54 = call float @train_network_datum(ptr noundef byval(%struct.network) align 8 %0, ptr noundef %52, ptr noundef %53)
  store float %54, ptr %9, align 4, !tbaa !19
  %55 = load float, ptr %9, align 4, !tbaa !19
  %56 = load float, ptr %8, align 4, !tbaa !19
  %57 = fadd float %56, %55
  store float %57, ptr %8, align 4, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  br label %58

58:                                               ; preds = %45
  %59 = load i32, ptr %7, align 4, !tbaa !15
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %7, align 4, !tbaa !15
  br label %41, !llvm.loop !20

61:                                               ; preds = %41
  %62 = load ptr, ptr %5, align 8, !tbaa !17
  call void @free(ptr noundef %62) #7
  %63 = load ptr, ptr %6, align 8, !tbaa !17
  call void @free(ptr noundef %63) #7
  %64 = load float, ptr %8, align 4, !tbaa !19
  %65 = load i32, ptr %4, align 4, !tbaa !15
  %66 = load i32, ptr %3, align 4, !tbaa !15
  %67 = mul nsw i32 %65, %66
  %68 = sitofp i32 %67 to float
  %69 = fdiv float %64, %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #7
  ret float %69
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #4

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

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

@.str.23 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [80 x i8], align 1
@__PRETTY_FUNCTION__.train_network = external hidden unnamed_addr constant [35 x i8], align 1

; 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: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local float @train_network(ptr noundef byval(%struct.network) align 8 %0, ptr noundef byval(%struct.data) align 8 %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 12
  %6 = load i32, ptr %5, align 4, !tbaa !12
  %7 = srem i32 %4, %6
  %8 = sdiv i32 %4, %6
  %9 = icmp eq i32 %7, 0
  br i1 %9, label %11, label %10

10:                                               ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.23, ptr noundef nonnull @.str.24, i32 noundef 265, ptr noundef nonnull @__PRETTY_FUNCTION__.train_network) #5
  unreachable

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %1, i64 12
  %13 = load i32, ptr %12, align 4, !tbaa !15
  %14 = mul nsw i32 %13, %6
  %15 = sext i32 %14 to i64
  %16 = tail call noalias ptr @calloc(i64 noundef %15, i64 noundef 4) #6
  %17 = getelementptr inbounds i8, ptr %1, i64 28
  %18 = load i32, ptr %17, align 4, !tbaa !16
  %19 = mul nsw i32 %18, %6
  %20 = sext i32 %19 to i64
  %21 = tail call noalias ptr @calloc(i64 noundef %20, i64 noundef 4) #6
  %22 = icmp sgt i32 %8, 0
  br i1 %22, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %11, %.lr.ph
  %.022 = phi i32 [ %26, %.lr.ph ], [ 0, %11 ]
  %.01921 = phi float [ %25, %.lr.ph ], [ 0.000000e+00, %11 ]
  %23 = mul nsw i32 %.022, %6
  tail call void @get_next_batch(ptr noundef nonnull byval(%struct.data) align 8 %1, i32 noundef %6, i32 noundef %23, ptr noundef %16, ptr noundef %21) #7
  %24 = tail call float @train_network_datum(ptr noundef nonnull byval(%struct.network) align 8 %0, ptr noundef %16, ptr noundef %21)
  %25 = fadd float %.01921, %24
  %26 = add nuw nsw i32 %.022, 1
  %exitcond.not = icmp eq i32 %26, %8
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %.lr.ph, %11
  %.019.lcssa = phi float [ 0.000000e+00, %11 ], [ %25, %.lr.ph ]
  tail call void @free(ptr noundef %16) #7
  tail call void @free(ptr noundef %21) #7
  %27 = mul nsw i32 %8, %6
  %28 = sitofp i32 %27 to float
  %29 = fdiv float %.019.lcssa, %28
  ret float %29
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

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

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


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