; 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: 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) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @get_label(ptr dead_on_unwind noalias writable sret(%struct.image) align 8 %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca %struct.image, align 8
  %9 = alloca %struct.image, align 8
  %10 = alloca %struct.image, align 8
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  store i32 %3, ptr %7, align 4, !tbaa !9
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = icmp sgt i32 %11, 7
  br i1 %12, label %13, label %14

13:                                               ; preds = %4
  store i32 7, ptr %7, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %13, %4
  call void @llvm.lifetime.start.p0(i64 24, ptr %8) #3
  call void @make_empty_image(ptr dead_on_unwind writable sret(%struct.image) align 8 %8, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  br label %15

15:                                               ; preds = %19, %14
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = icmp ne i8 %17, 0
  br i1 %18, label %19, label %39

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds ptr, ptr %20, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = sext i8 %26 to i32
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds %struct.image, ptr %24, i64 %28
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %29, i64 24, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #3
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = sub nsw i32 0, %30
  %32 = sub nsw i32 %31, 1
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  %35 = sdiv i32 %34, 2
  %36 = add nsw i32 %32, %35
  call void @tile_images(ptr dead_on_unwind writable sret(%struct.image) align 8 %10, ptr noundef byval(%struct.image) align 8 %8, ptr noundef byval(%struct.image) align 8 %9, i32 noundef %36)
  call void @free_image(ptr noundef byval(%struct.image) align 8 %8)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %10, i64 24, i1 false), !tbaa.struct !12
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i32 1
  store ptr %38, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #3
  br label %15, !llvm.loop !13

39:                                               ; preds = %15
  %40 = getelementptr inbounds %struct.image, ptr %8, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !15
  %42 = sitofp i32 %41 to double
  %43 = fmul double %42, 2.500000e-01
  %44 = fptosi double %43 to i32
  call void @border_image(ptr dead_on_unwind writable sret(%struct.image) align 8 %0, ptr noundef byval(%struct.image) align 8 %8, i32 noundef %44)
  call void @free_image(ptr noundef byval(%struct.image) align 8 %8)
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #3
  ret void
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @free_image(ptr noundef byval(%struct.image) align 8) #2

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

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


; 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: 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: 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) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @get_label(ptr dead_on_unwind noalias writable sret(%struct.image) align 8 %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, i32 noundef %3) local_unnamed_addr #2 {
  %5 = alloca %struct.image, align 8
  %6 = alloca %struct.image, align 8
  %7 = alloca %struct.image, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #4
  call void @make_empty_image(ptr dead_on_unwind nonnull writable sret(%struct.image) align 8 %5, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %8 = load i8, ptr %2, align 1, !tbaa !5
  %.not7 = icmp eq i8 %8, 0
  br i1 %.not7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %spec.store.select = tail call i32 @llvm.smin.i32(i32 %3, i32 7)
  %9 = sext i32 %spec.store.select to i64
  %10 = getelementptr inbounds ptr, ptr %1, i64 %9
  %11 = xor i32 %spec.store.select, -1
  %12 = add nsw i32 %spec.store.select, 1
  %13 = sdiv i32 %12, 2
  %14 = add nsw i32 %13, %11
  br label %15

15:                                               ; preds = %.lr.ph, %15
  %16 = phi i8 [ %8, %.lr.ph ], [ %21, %15 ]
  %.08 = phi ptr [ %2, %.lr.ph ], [ %20, %15 ]
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #4
  %17 = load ptr, ptr %10, align 8, !tbaa !8
  %18 = sext i8 %16 to i64
  %19 = getelementptr inbounds %struct.image, ptr %17, i64 %18
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %6, ptr noundef nonnull align 8 dereferenceable(24) %19, i64 24, i1 false), !tbaa.struct !10
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %7) #4
  call void @tile_images(ptr dead_on_unwind nonnull writable sret(%struct.image) align 8 %7, ptr noundef nonnull byval(%struct.image) align 8 %5, ptr noundef nonnull byval(%struct.image) align 8 %6, i32 noundef %14)
  call void @free_image(ptr noundef nonnull byval(%struct.image) align 8 %5)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %5, ptr noundef nonnull align 8 dereferenceable(24) %7, i64 24, i1 false), !tbaa.struct !10
  %20 = getelementptr inbounds i8, ptr %.08, i64 1
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #4
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %.not = icmp eq i8 %21, 0
  br i1 %.not, label %._crit_edge, label %15, !llvm.loop !13

._crit_edge:                                      ; preds = %15, %4
  %22 = load i32, ptr %5, align 8, !tbaa !15
  %23 = sitofp i32 %22 to double
  %24 = fmul double %23, 2.500000e-01
  %25 = fptosi double %24 to i32
  call void @border_image(ptr dead_on_unwind writable sret(%struct.image) align 8 %0, ptr noundef nonnull byval(%struct.image) align 8 %5, i32 noundef %25)
  call void @free_image(ptr noundef nonnull byval(%struct.image) align 8 %5)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #4
  ret void
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @free_image(ptr noundef byval(%struct.image) align 8) local_unnamed_addr #2

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{i64 0, i64 4, !11, i64 4, i64 4, !11, i64 8, i64 4, !11, i64 16, i64 8, !8}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !6, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !12, i64 0}
!16 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !9, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass