; 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.network_state = type { ptr, ptr, ptr, ptr, i32, i32, %struct.network }
%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 uwtable
declare dso_local void @forward_network(ptr noundef byval(%struct.network) align 8, ptr noundef byval(%struct.network_state) align 8) #1

; 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) #2

; Function Attrs: nounwind uwtable
declare dso_local void @update_network(ptr noundef byval(%struct.network) align 8) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @backward_network(ptr noundef byval(%struct.network) align 8, ptr noundef byval(%struct.network_state) align 8) #1

; Function Attrs: nounwind uwtable
define dso_local float @train_network_batch(ptr noundef byval(%struct.network) align 8 %0, ptr noundef byval(%struct.data) align 8 %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.network_state, align 8
  %8 = alloca float, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %2, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 232, ptr %7) #4
  %11 = getelementptr inbounds %struct.network_state, ptr %7, i32 0, i32 5
  store i32 0, ptr %11, align 4, !tbaa !9
  %12 = getelementptr inbounds %struct.network_state, ptr %7, i32 0, i32 6
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 8 %0, i64 192, i1 false), !tbaa.struct !14
  %13 = getelementptr inbounds %struct.network_state, ptr %7, i32 0, i32 4
  store i32 1, ptr %13, align 8, !tbaa !17
  %14 = getelementptr inbounds %struct.network_state, ptr %7, i32 0, i32 2
  store ptr null, ptr %14, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store float 0.000000e+00, ptr %8, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 2, ptr %9, align 4, !tbaa !5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %53, %3
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %56

19:                                               ; preds = %15
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %49, %19
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = load i32, ptr %9, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %24, label %52

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %25 = call i32 @rand() #4
  %26 = getelementptr inbounds %struct.data, ptr %1, i32 0, i32 2
  %27 = getelementptr inbounds %struct.matrix, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !19
  %29 = srem i32 %25, %28
  store i32 %29, ptr %10, align 4, !tbaa !5
  %30 = getelementptr inbounds %struct.data, ptr %1, i32 0, i32 2
  %31 = getelementptr inbounds %struct.matrix, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !22
  %33 = load i32, ptr %10, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds ptr, ptr %32, i64 %34
  %36 = load ptr, ptr %35, align 8, !tbaa !15
  %37 = getelementptr inbounds %struct.network_state, ptr %7, i32 0, i32 1
  store ptr %36, ptr %37, align 8, !tbaa !23
  %38 = getelementptr inbounds %struct.data, ptr %1, i32 0, i32 3
  %39 = getelementptr inbounds %struct.matrix, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !24
  %41 = load i32, ptr %10, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds ptr, ptr %40, i64 %42
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  %45 = getelementptr inbounds %struct.network_state, ptr %7, i32 0, i32 0
  store ptr %44, ptr %45, align 8, !tbaa !25
  call void @forward_network(ptr noundef byval(%struct.network) align 8 %0, ptr noundef byval(%struct.network_state) align 8 %7)
  call void @backward_network(ptr noundef byval(%struct.network) align 8 %0, ptr noundef byval(%struct.network_state) align 8 %7)
  %46 = call float @get_network_cost(ptr noundef byval(%struct.network) align 8 %0)
  %47 = load float, ptr %8, align 4, !tbaa !16
  %48 = fadd float %47, %46
  store float %48, ptr %8, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %49

49:                                               ; preds = %24
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %6, align 4, !tbaa !5
  br label %20, !llvm.loop !26

52:                                               ; preds = %20
  call void @update_network(ptr noundef byval(%struct.network) align 8 %0)
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %5, align 4, !tbaa !5
  br label %15, !llvm.loop !28

56:                                               ; preds = %15
  %57 = load float, ptr %8, align 4, !tbaa !16
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = load i32, ptr %9, align 4, !tbaa !5
  %60 = mul nsw i32 %58, %59
  %61 = sitofp i32 %60 to float
  %62 = fdiv float %57, %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 232, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret float %62
}

; Function Attrs: nounwind
declare i32 @rand() #3

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


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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @forward_network(ptr noundef byval(%struct.network) align 8, ptr noundef byval(%struct.network_state) 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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local float @train_network_batch(ptr noundef byval(%struct.network) align 8 %0, ptr nocapture noundef readonly byval(%struct.data) align 8 %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca %struct.network_state, align 8
  call void @llvm.lifetime.start.p0(i64 232, ptr nonnull %4) #4
  %5 = getelementptr inbounds i8, ptr %4, i64 36
  store i32 0, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %4, i64 40
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(192) %6, ptr noundef nonnull align 8 dereferenceable(192) %0, i64 192, i1 false), !tbaa.struct !13
  %7 = getelementptr inbounds i8, ptr %4, i64 32
  store i32 1, ptr %7, align 8, !tbaa !17
  %8 = getelementptr inbounds i8, ptr %4, i64 16
  store ptr null, ptr %8, align 8, !tbaa !18
  %9 = icmp sgt i32 %2, 0
  br i1 %9, label %.preheader.lr.ph, label %._crit_edge

.preheader.lr.ph:                                 ; preds = %3
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load i32, ptr %10, align 8
  %12 = getelementptr inbounds i8, ptr %1, i64 16
  %13 = load ptr, ptr %12, align 8
  %14 = getelementptr inbounds i8, ptr %4, i64 8
  %15 = getelementptr inbounds i8, ptr %1, i64 32
  %16 = load ptr, ptr %15, align 8
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %.preheader
  %.017 = phi i32 [ 0, %.preheader.lr.ph ], [ %35, %.preheader ]
  %.01216 = phi float [ 0.000000e+00, %.preheader.lr.ph ], [ %34, %.preheader ]
  %17 = tail call i32 @rand() #4
  %18 = srem i32 %17, %11
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds ptr, ptr %13, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  store ptr %21, ptr %14, align 8, !tbaa !19
  %22 = getelementptr inbounds ptr, ptr %16, i64 %19
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  store ptr %23, ptr %4, align 8, !tbaa !20
  tail call void @forward_network(ptr noundef nonnull byval(%struct.network) align 8 %0, ptr noundef nonnull byval(%struct.network_state) align 8 %4)
  tail call void @backward_network(ptr noundef nonnull byval(%struct.network) align 8 %0, ptr noundef nonnull byval(%struct.network_state) align 8 %4)
  %24 = tail call float @get_network_cost(ptr noundef nonnull byval(%struct.network) align 8 %0)
  %25 = fadd float %.01216, %24
  %26 = tail call i32 @rand() #4
  %27 = srem i32 %26, %11
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds ptr, ptr %13, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  store ptr %30, ptr %14, align 8, !tbaa !19
  %31 = getelementptr inbounds ptr, ptr %16, i64 %28
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  store ptr %32, ptr %4, align 8, !tbaa !20
  tail call void @forward_network(ptr noundef nonnull byval(%struct.network) align 8 %0, ptr noundef nonnull byval(%struct.network_state) align 8 %4)
  tail call void @backward_network(ptr noundef nonnull byval(%struct.network) align 8 %0, ptr noundef nonnull byval(%struct.network_state) align 8 %4)
  %33 = tail call float @get_network_cost(ptr noundef nonnull byval(%struct.network) align 8 %0)
  %34 = fadd float %25, %33
  tail call void @update_network(ptr noundef nonnull byval(%struct.network) align 8 %0)
  %35 = add nuw nsw i32 %.017, 1
  %exitcond.not = icmp eq i32 %35, %2
  br i1 %exitcond.not, label %._crit_edge, label %.preheader, !llvm.loop !21

._crit_edge:                                      ; preds = %.preheader, %3
  %.012.lcssa = phi float [ 0.000000e+00, %3 ], [ %34, %.preheader ]
  %36 = shl nsw i32 %2, 1
  %37 = sitofp i32 %36 to float
  %38 = fdiv float %.012.lcssa, %37
  call void @llvm.lifetime.end.p0(i64 232, ptr nonnull %4) #4
  ret float %38
}

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #3

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


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