; 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.32 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [4 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
declare double @pow(double noundef, double noundef) #1

declare i32 @max_index(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local { i64, ptr } @network_predict_data(ptr noundef byval(%struct.network) align 8, ptr noundef byval(%struct.data) align 8) #3

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

26:                                               ; preds = %87, %3
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = getelementptr inbounds %struct.matrix, ptr %4, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !9
  %30 = icmp slt i32 %27, %29
  br i1 %30, label %31, label %90

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %32 = getelementptr inbounds %struct.data, ptr %2, i32 0, i32 3
  %33 = getelementptr inbounds %struct.matrix, ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !12
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds ptr, ptr %34, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  %39 = getelementptr inbounds %struct.data, ptr %2, i32 0, i32 3
  %40 = getelementptr inbounds %struct.matrix, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !15
  %42 = call i32 @max_index(ptr noundef %38, i32 noundef %41)
  store i32 %42, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %43 = getelementptr inbounds %struct.matrix, ptr %4, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !16
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds ptr, ptr %44, i64 %46
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  %49 = getelementptr inbounds %struct.matrix, ptr %4, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !17
  %51 = call i32 @max_index(ptr noundef %48, i32 noundef %50)
  store i32 %51, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %52 = getelementptr inbounds %struct.matrix, ptr %5, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !16
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds ptr, ptr %53, i64 %55
  %57 = load ptr, ptr %56, align 8, !tbaa !14
  %58 = getelementptr inbounds %struct.matrix, ptr %5, i32 0, i32 1
  %59 = load i32, ptr %58, align 4, !tbaa !17
  %60 = call i32 @max_index(ptr noundef %57, i32 noundef %59)
  store i32 %60, ptr %13, align 4, !tbaa !5
  %61 = load i32, ptr %12, align 4, !tbaa !5
  %62 = load i32, ptr %11, align 4, !tbaa !5
  %63 = icmp eq i32 %61, %62
  br i1 %63, label %64, label %75

64:                                               ; preds = %31
  %65 = load i32, ptr %13, align 4, !tbaa !5
  %66 = load i32, ptr %11, align 4, !tbaa !5
  %67 = icmp eq i32 %65, %66
  br i1 %67, label %68, label %71

68:                                               ; preds = %64
  %69 = load i32, ptr %10, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %10, align 4, !tbaa !5
  br label %74

71:                                               ; preds = %64
  %72 = load i32, ptr %9, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %9, align 4, !tbaa !5
  br label %74

74:                                               ; preds = %71, %68
  br label %86

75:                                               ; preds = %31
  %76 = load i32, ptr %13, align 4, !tbaa !5
  %77 = load i32, ptr %11, align 4, !tbaa !5
  %78 = icmp eq i32 %76, %77
  br i1 %78, label %79, label %82

79:                                               ; preds = %75
  %80 = load i32, ptr %8, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %8, align 4, !tbaa !5
  br label %85

82:                                               ; preds = %75
  %83 = load i32, ptr %7, align 4, !tbaa !5
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %7, align 4, !tbaa !5
  br label %85

85:                                               ; preds = %82, %79
  br label %86

86:                                               ; preds = %85, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %87

87:                                               ; preds = %86
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %6, align 4, !tbaa !5
  br label %26, !llvm.loop !18

90:                                               ; preds = %26
  %91 = load i32, ptr %7, align 4, !tbaa !5
  %92 = load i32, ptr %8, align 4, !tbaa !5
  %93 = load i32, ptr %9, align 4, !tbaa !5
  %94 = load i32, ptr %10, align 4, !tbaa !5
  %95 = call i32 (ptr, ...) @printf(ptr noundef @.str.32, i32 noundef %91, i32 noundef %92, i32 noundef %93, i32 noundef %94)
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %96 = load i32, ptr %8, align 4, !tbaa !5
  %97 = load i32, ptr %9, align 4, !tbaa !5
  %98 = sub nsw i32 %96, %97
  %99 = call i32 @llvm.abs.i32(i32 %98, i1 true)
  %100 = sitofp i32 %99 to double
  %101 = fsub double %100, 1.000000e+00
  %102 = call double @pow(double noundef %101, double noundef 2.000000e+00) #5
  %103 = fptrunc double %102 to float
  store float %103, ptr %14, align 4, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %104 = load i32, ptr %8, align 4, !tbaa !5
  %105 = load i32, ptr %9, align 4, !tbaa !5
  %106 = add nsw i32 %104, %105
  %107 = sitofp i32 %106 to float
  store float %107, ptr %15, align 4, !tbaa !20
  %108 = load float, ptr %14, align 4, !tbaa !20
  %109 = load float, ptr %15, align 4, !tbaa !20
  %110 = fdiv float %108, %109
  %111 = fpext float %110 to double
  %112 = call i32 (ptr, ...) @printf(ptr noundef @.str.33, double noundef %111)
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  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 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #5
  ret void
}

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #4

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 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"matrix", !6, i64 0, !6, i64 4, !11, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !11, i64 32}
!13 = !{!"", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 24, !6, i64 40, !11, i64 48, !11, i64 56}
!14 = !{!11, !11, i64 0}
!15 = !{!13, !6, i64 28}
!16 = !{!10, !11, i64 8}
!17 = !{!10, !6, i64 4}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!21, !21, i64 0}
!21 = !{!"float", !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.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.32 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [4 x i8], align 1

declare i32 @max_index(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local { i64, ptr } @network_predict_data(ptr noundef byval(%struct.network) align 8, ptr noundef byval(%struct.data) align 8) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @compare_networks(ptr noundef byval(%struct.network) align 8 %0, ptr noundef byval(%struct.network) align 8 %1, ptr noundef byval(%struct.data) align 8 %2) local_unnamed_addr #1 {
  %4 = tail call { i64, ptr } @network_predict_data(ptr noundef nonnull byval(%struct.network) align 8 %0, ptr noundef nonnull byval(%struct.data) align 8 %2)
  %5 = extractvalue { i64, ptr } %4, 0
  %6 = extractvalue { i64, ptr } %4, 1
  %7 = tail call { i64, ptr } @network_predict_data(ptr noundef nonnull byval(%struct.network) align 8 %1, ptr noundef nonnull byval(%struct.data) align 8 %2)
  %8 = extractvalue { i64, ptr } %7, 1
  %.sroa.024.0.extract.trunc = trunc i64 %5 to i32
  %9 = icmp sgt i32 %.sroa.024.0.extract.trunc, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %10 = extractvalue { i64, ptr } %7, 0
  %11 = getelementptr inbounds i8, ptr %2, i64 32
  %12 = getelementptr inbounds i8, ptr %2, i64 28
  %.sroa.024.4.extract.shift = lshr i64 %5, 32
  %.sroa.024.4.extract.trunc = trunc nuw i64 %.sroa.024.4.extract.shift to i32
  %.sroa.0.4.extract.shift = lshr i64 %10, 32
  %.sroa.0.4.extract.trunc = trunc nuw i64 %.sroa.0.4.extract.shift to i32
  %wide.trip.count = and i64 %5, 2147483647
  br label %13

13:                                               ; preds = %.lr.ph, %37
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %37 ]
  %.02537 = phi i32 [ 0, %.lr.ph ], [ %.1, %37 ]
  %.02636 = phi i32 [ 0, %.lr.ph ], [ %.127, %37 ]
  %.02835 = phi i32 [ 0, %.lr.ph ], [ %.129, %37 ]
  %.03034 = phi i32 [ 0, %.lr.ph ], [ %.131, %37 ]
  %14 = load ptr, ptr %11, align 8, !tbaa !5
  %15 = getelementptr inbounds ptr, ptr %14, i64 %indvars.iv
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = load i32, ptr %12, align 4, !tbaa !13
  %18 = tail call i32 @max_index(ptr noundef %16, i32 noundef %17) #4
  %19 = getelementptr inbounds ptr, ptr %6, i64 %indvars.iv
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = tail call i32 @max_index(ptr noundef %20, i32 noundef %.sroa.024.4.extract.trunc) #4
  %22 = getelementptr inbounds ptr, ptr %8, i64 %indvars.iv
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  %24 = tail call i32 @max_index(ptr noundef %23, i32 noundef %.sroa.0.4.extract.trunc) #4
  %25 = icmp eq i32 %21, %18
  %26 = icmp eq i32 %24, %18
  br i1 %25, label %27, label %32

27:                                               ; preds = %13
  br i1 %26, label %28, label %30

28:                                               ; preds = %27
  %29 = add nsw i32 %.03034, 1
  br label %37

30:                                               ; preds = %27
  %31 = add nsw i32 %.02835, 1
  br label %37

32:                                               ; preds = %13
  br i1 %26, label %33, label %35

33:                                               ; preds = %32
  %34 = add nsw i32 %.02636, 1
  br label %37

35:                                               ; preds = %32
  %36 = add nsw i32 %.02537, 1
  br label %37

37:                                               ; preds = %33, %35, %28, %30
  %.131 = phi i32 [ %29, %28 ], [ %.03034, %30 ], [ %.03034, %33 ], [ %.03034, %35 ]
  %.129 = phi i32 [ %.02835, %28 ], [ %31, %30 ], [ %.02835, %33 ], [ %.02835, %35 ]
  %.127 = phi i32 [ %.02636, %28 ], [ %.02636, %30 ], [ %34, %33 ], [ %.02636, %35 ]
  %.1 = phi i32 [ %.02537, %28 ], [ %.02537, %30 ], [ %.02537, %33 ], [ %36, %35 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %13, !llvm.loop !14

._crit_edge:                                      ; preds = %37, %3
  %.030.lcssa = phi i32 [ 0, %3 ], [ %.131, %37 ]
  %.028.lcssa = phi i32 [ 0, %3 ], [ %.129, %37 ]
  %.026.lcssa = phi i32 [ 0, %3 ], [ %.127, %37 ]
  %.025.lcssa = phi i32 [ 0, %3 ], [ %.1, %37 ]
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.32, i32 noundef %.025.lcssa, i32 noundef %.026.lcssa, i32 noundef %.028.lcssa, i32 noundef %.030.lcssa)
  %39 = sub nsw i32 %.026.lcssa, %.028.lcssa
  %40 = tail call i32 @llvm.abs.i32(i32 %39, i1 true)
  %41 = add nsw i32 %40, -1
  %42 = sitofp i32 %41 to double
  %square = fmul double %42, %42
  %43 = fptrunc double %square to float
  %44 = add nsw i32 %.026.lcssa, %.028.lcssa
  %45 = sitofp i32 %44 to float
  %46 = fdiv float %43, %45
  %47 = fpext float %46 to double
  %48 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.33, double noundef %47)
  ret void
}

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

attributes #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 #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 = { 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 #3 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !11, i64 32}
!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 = !{!11, !11, i64 0}
!13 = !{!6, !7, i64 28}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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