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

; 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.image = type { i32, 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 float @get_pixel(ptr noundef byval(%struct.image) align 8, i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @set_pixel(ptr noundef byval(%struct.image) align 8, i32 noundef, i32 noundef, i32 noundef, float noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @make_image(ptr dead_on_unwind noalias writable sret(%struct.image) align 8, i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @crop_image(ptr dead_on_unwind noalias writable sret(%struct.image) align 8 %0, ptr noundef byval(%struct.image) align 8 %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #1 {
  %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 i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca float, align 4
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  store i32 %4, ptr %9, align 4, !tbaa !5
  store i32 %5, ptr %10, align 4, !tbaa !5
  %17 = load i32, ptr %9, align 4, !tbaa !5
  %18 = load i32, ptr %10, align 4, !tbaa !5
  %19 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 2
  %20 = load i32, ptr %19, align 8, !tbaa !9
  call void @make_image(ptr dead_on_unwind writable sret(%struct.image) align 8 %0, i32 noundef %17, i32 noundef %18, i32 noundef %20)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %86, %6
  %22 = load i32, ptr %13, align 4, !tbaa !5
  %23 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 2
  %24 = load i32, ptr %23, align 8, !tbaa !9
  %25 = icmp slt i32 %22, %24
  br i1 %25, label %26, label %89

26:                                               ; preds = %21
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %82, %26
  %28 = load i32, ptr %12, align 4, !tbaa !5
  %29 = load i32, ptr %10, align 4, !tbaa !5
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %31, label %85

31:                                               ; preds = %27
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %78, %31
  %33 = load i32, ptr %11, align 4, !tbaa !5
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %36, label %81

36:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %37 = load i32, ptr %12, align 4, !tbaa !5
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = add nsw i32 %37, %38
  store i32 %39, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %40 = load i32, ptr %11, align 4, !tbaa !5
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = add nsw i32 %40, %41
  store i32 %42, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  store float 0.000000e+00, ptr %16, align 4, !tbaa !12
  %43 = load i32, ptr %14, align 4, !tbaa !5
  %44 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !14
  %46 = sub nsw i32 %45, 1
  %47 = call i32 @constrain_int(i32 noundef %43, i32 noundef 0, i32 noundef %46)
  store i32 %47, ptr %14, align 4, !tbaa !5
  %48 = load i32, ptr %15, align 4, !tbaa !5
  %49 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !15
  %51 = sub nsw i32 %50, 1
  %52 = call i32 @constrain_int(i32 noundef %48, i32 noundef 0, i32 noundef %51)
  store i32 %52, ptr %15, align 4, !tbaa !5
  %53 = load i32, ptr %14, align 4, !tbaa !5
  %54 = icmp sge i32 %53, 0
  br i1 %54, label %55, label %73

55:                                               ; preds = %36
  %56 = load i32, ptr %14, align 4, !tbaa !5
  %57 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 0
  %58 = load i32, ptr %57, align 8, !tbaa !14
  %59 = icmp slt i32 %56, %58
  br i1 %59, label %60, label %73

60:                                               ; preds = %55
  %61 = load i32, ptr %15, align 4, !tbaa !5
  %62 = icmp sge i32 %61, 0
  br i1 %62, label %63, label %73

63:                                               ; preds = %60
  %64 = load i32, ptr %15, align 4, !tbaa !5
  %65 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 1
  %66 = load i32, ptr %65, align 4, !tbaa !15
  %67 = icmp slt i32 %64, %66
  br i1 %67, label %68, label %73

68:                                               ; preds = %63
  %69 = load i32, ptr %15, align 4, !tbaa !5
  %70 = load i32, ptr %14, align 4, !tbaa !5
  %71 = load i32, ptr %13, align 4, !tbaa !5
  %72 = call float @get_pixel(ptr noundef byval(%struct.image) align 8 %1, i32 noundef %69, i32 noundef %70, i32 noundef %71)
  store float %72, ptr %16, align 4, !tbaa !12
  br label %73

73:                                               ; preds = %68, %63, %60, %55, %36
  %74 = load i32, ptr %11, align 4, !tbaa !5
  %75 = load i32, ptr %12, align 4, !tbaa !5
  %76 = load i32, ptr %13, align 4, !tbaa !5
  %77 = load float, ptr %16, align 4, !tbaa !12
  call void @set_pixel(ptr noundef byval(%struct.image) align 8 %0, i32 noundef %74, i32 noundef %75, i32 noundef %76, float noundef %77)
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %78

78:                                               ; preds = %73
  %79 = load i32, ptr %11, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %11, align 4, !tbaa !5
  br label %32, !llvm.loop !16

81:                                               ; preds = %32
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %12, align 4, !tbaa !5
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %12, align 4, !tbaa !5
  br label %27, !llvm.loop !18

85:                                               ; preds = %27
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %13, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %13, align 4, !tbaa !5
  br label %21, !llvm.loop !19

89:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  ret void
}

declare i32 @constrain_int(i32 noundef, i32 noundef, i32 noundef) #2

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

!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 8}
!10 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !11, i64 16}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !7, i64 0}
!14 = !{!10, !6, i64 0}
!15 = !{!10, !6, i64 4}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = distinct !{!19, !17}


; 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.image = type { i32, i32, i32, ptr }

; Function Attrs: nounwind uwtable
declare dso_local float @get_pixel(ptr noundef byval(%struct.image) align 8, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @set_pixel(ptr noundef byval(%struct.image) align 8, i32 noundef, i32 noundef, i32 noundef, float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @make_image(ptr dead_on_unwind noalias writable sret(%struct.image) align 8, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @crop_image(ptr dead_on_unwind noalias writable sret(%struct.image) align 8 %0, ptr noundef byval(%struct.image) align 8 %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !5
  tail call void @make_image(ptr dead_on_unwind writable sret(%struct.image) align 8 %0, i32 noundef %4, i32 noundef %5, i32 noundef %8)
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.preheader34.lr.ph, label %._crit_edge

.preheader34.lr.ph:                               ; preds = %6
  %10 = icmp sgt i32 %5, 0
  %11 = getelementptr inbounds i8, ptr %1, i64 4
  %12 = icmp sgt i32 %4, 0
  %or.cond = and i1 %10, %12
  br i1 %or.cond, label %.preheader34.us.us, label %._crit_edge

.preheader34.us.us:                               ; preds = %.preheader34.lr.ph, %._crit_edge37.split.us.us.us
  %.02738.us.us = phi i32 [ %34, %._crit_edge37.split.us.us.us ], [ 0, %.preheader34.lr.ph ]
  br label %.preheader.us.us.us

.preheader.us.us.us:                              ; preds = %._crit_edge.us.us.us, %.preheader34.us.us
  %.02836.us.us.us = phi i32 [ 0, %.preheader34.us.us ], [ %33, %._crit_edge.us.us.us ]
  %13 = add nsw i32 %.02836.us.us.us, %3
  br label %14

14:                                               ; preds = %31, %.preheader.us.us.us
  %.02935.us.us.us = phi i32 [ 0, %.preheader.us.us.us ], [ %32, %31 ]
  %15 = add nsw i32 %.02935.us.us.us, %2
  %16 = load i32, ptr %1, align 8, !tbaa !11
  %17 = add nsw i32 %16, -1
  %18 = tail call i32 @constrain_int(i32 noundef %13, i32 noundef 0, i32 noundef %17) #2
  %19 = load i32, ptr %11, align 4, !tbaa !12
  %20 = add nsw i32 %19, -1
  %21 = tail call i32 @constrain_int(i32 noundef %15, i32 noundef 0, i32 noundef %20) #2
  %22 = icmp sgt i32 %18, -1
  br i1 %22, label %23, label %31

23:                                               ; preds = %14
  %24 = load i32, ptr %1, align 8, !tbaa !11
  %25 = icmp slt i32 %18, %24
  %26 = icmp sgt i32 %21, -1
  %or.cond.us.us.us = select i1 %25, i1 %26, i1 false
  %27 = load i32, ptr %11, align 4
  %28 = icmp slt i32 %21, %27
  %or.cond33.us.us.us = select i1 %or.cond.us.us.us, i1 %28, i1 false
  br i1 %or.cond33.us.us.us, label %29, label %31

29:                                               ; preds = %23
  %30 = tail call float @get_pixel(ptr noundef nonnull byval(%struct.image) align 8 %1, i32 noundef %21, i32 noundef %18, i32 noundef %.02738.us.us)
  br label %31

31:                                               ; preds = %29, %23, %14
  %.0.us.us.us = phi float [ %30, %29 ], [ 0.000000e+00, %23 ], [ 0.000000e+00, %14 ]
  tail call void @set_pixel(ptr noundef byval(%struct.image) align 8 %0, i32 noundef %.02935.us.us.us, i32 noundef %.02836.us.us.us, i32 noundef %.02738.us.us, float noundef %.0.us.us.us)
  %32 = add nuw nsw i32 %.02935.us.us.us, 1
  %exitcond.not = icmp eq i32 %32, %4
  br i1 %exitcond.not, label %._crit_edge.us.us.us, label %14, !llvm.loop !13

._crit_edge.us.us.us:                             ; preds = %31
  %33 = add nuw nsw i32 %.02836.us.us.us, 1
  %exitcond46.not = icmp eq i32 %33, %5
  br i1 %exitcond46.not, label %._crit_edge37.split.us.us.us, label %.preheader.us.us.us, !llvm.loop !15

._crit_edge37.split.us.us.us:                     ; preds = %._crit_edge.us.us.us
  %34 = add nuw nsw i32 %.02738.us.us, 1
  %35 = load i32, ptr %7, align 8, !tbaa !5
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %.preheader34.us.us, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %._crit_edge37.split.us.us.us, %.preheader34.lr.ph, %6
  ret void
}

declare i32 @constrain_int(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 }

!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, !7, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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