; LLVM IR from leonmavr/gfx-v4 :: src (algos)

; 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.vec3u8_t = type { i8, i8, i8 }
%struct.node_t = type { %struct.vec2i_t, %struct.vec3u8_t, ptr }
%struct.vec2i_t = type { i32, i32 }
%struct.queue_t = type { ptr, ptr }

; Function Attrs: nounwind uwtable
declare dso_local void @algos_line_bres(ptr noundef, ptr noundef, ptr noundef) #0

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

declare void @gfx_point(i32 noundef, i32 noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @algos_line_bres_col(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca %struct.vec3u8_t, align 1
  %9 = alloca %struct.vec3u8_t, align 1
  %10 = alloca %struct.vec3u8_t, align 1
  %11 = alloca %struct.vec3u8_t, align 1
  %12 = alloca %struct.vec3u8_t, align 1
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.node_t, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.node_t, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  call void @algos_line_bres(ptr noundef %16, ptr noundef %18, ptr noundef %19)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = call i32 @queue_length(ptr noundef %20)
  store i32 %21, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 3, ptr %8) #5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.node_t, ptr %22, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %8, ptr align 8 %23, i64 3, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.start.p0(i64 3, ptr %9) #5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.node_t, ptr %24, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %9, ptr align 8 %25, i64 3, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.start.p0(i64 3, ptr %10) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %10, ptr align 1 %8, i64 3, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.start.p0(i64 3, ptr %11) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %11, ptr align 1 %9, i64 3, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.start.p0(i64 3, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.queue_t, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  store ptr %28, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %84, %3
  %30 = load i32, ptr %14, align 4, !tbaa !9
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  br label %87

34:                                               ; preds = %29
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = load i32, ptr %14, align 4, !tbaa !9
  %37 = sub nsw i32 %35, %36
  %38 = sub nsw i32 %37, 1
  %39 = sitofp i32 %38 to float
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = sitofp i32 %40 to float
  %42 = fdiv float %39, %41
  call void @vec3u_mul_float(ptr noundef %10, ptr noundef %8, float noundef %42)
  %43 = load i32, ptr %14, align 4, !tbaa !9
  %44 = sub nsw i32 %43, 1
  %45 = sitofp i32 %44 to float
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = sitofp i32 %46 to float
  %48 = fdiv float %45, %47
  call void @vec3u_mul_float(ptr noundef %11, ptr noundef %9, float noundef %48)
  call void @vec3u_add(ptr noundef %12, ptr noundef %10, ptr noundef %11)
  %49 = getelementptr inbounds %struct.vec3u8_t, ptr %12, i32 0, i32 0
  %50 = load i8, ptr %49, align 1, !tbaa !15
  %51 = zext i8 %50 to i32
  %52 = getelementptr inbounds %struct.vec3u8_t, ptr %12, i32 0, i32 1
  %53 = load i8, ptr %52, align 1, !tbaa !17
  %54 = zext i8 %53 to i32
  %55 = getelementptr inbounds %struct.vec3u8_t, ptr %12, i32 0, i32 2
  %56 = load i8, ptr %55, align 1, !tbaa !18
  %57 = zext i8 %56 to i32
  call void @gfx_color(i32 noundef %51, i32 noundef %54, i32 noundef %57)
  %58 = getelementptr inbounds %struct.vec3u8_t, ptr %12, i32 0, i32 0
  %59 = load i8, ptr %58, align 1, !tbaa !15
  %60 = load ptr, ptr %13, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.node_t, ptr %60, i32 0, i32 1
  %62 = getelementptr inbounds %struct.vec3u8_t, ptr %61, i32 0, i32 0
  store i8 %59, ptr %62, align 8, !tbaa !19
  %63 = getelementptr inbounds %struct.vec3u8_t, ptr %12, i32 0, i32 1
  %64 = load i8, ptr %63, align 1, !tbaa !17
  %65 = load ptr, ptr %13, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.node_t, ptr %65, i32 0, i32 1
  %67 = getelementptr inbounds %struct.vec3u8_t, ptr %66, i32 0, i32 1
  store i8 %64, ptr %67, align 1, !tbaa !22
  %68 = getelementptr inbounds %struct.vec3u8_t, ptr %12, i32 0, i32 2
  %69 = load i8, ptr %68, align 1, !tbaa !18
  %70 = load ptr, ptr %13, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.node_t, ptr %70, i32 0, i32 1
  %72 = getelementptr inbounds %struct.vec3u8_t, ptr %71, i32 0, i32 2
  store i8 %69, ptr %72, align 2, !tbaa !23
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.node_t, ptr %73, i32 0, i32 0
  %75 = getelementptr inbounds %struct.vec2i_t, ptr %74, i32 0, i32 0
  %76 = load i32, ptr %75, align 8, !tbaa !24
  %77 = load ptr, ptr %13, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.node_t, ptr %77, i32 0, i32 0
  %79 = getelementptr inbounds %struct.vec2i_t, ptr %78, i32 0, i32 1
  %80 = load i32, ptr %79, align 4, !tbaa !25
  call void @gfx_point(i32 noundef %76, i32 noundef %80)
  call void (...) @gfx_flush()
  %81 = load ptr, ptr %13, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.node_t, ptr %81, i32 0, i32 2
  %83 = load ptr, ptr %82, align 8, !tbaa !26
  store ptr %83, ptr %13, align 8, !tbaa !5
  br label %84

84:                                               ; preds = %34
  %85 = load i32, ptr %14, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %14, align 4, !tbaa !9
  br label %29, !llvm.loop !27

87:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 3, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 3, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 3, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 3, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 3, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret void
}

declare i32 @queue_length(ptr noundef) #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @vec3u_mul_float(ptr noundef, ptr noundef, float noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @vec3u_add(ptr noundef, ptr noundef, ptr noundef) #4

declare void @gfx_color(i32 noundef, i32 noundef, i32 noundef) #2

declare void @gfx_flush(...) #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint 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 #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 = !{!"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 = !{i64 0, i64 1, !12, i64 1, i64 1, !12, i64 2, i64 1, !12}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"queue_t", !6, i64 0, !6, i64 8}
!15 = !{!16, !7, i64 0}
!16 = !{!"vec3u8_t", !7, i64 0, !7, i64 1, !7, i64 2}
!17 = !{!16, !7, i64 1}
!18 = !{!16, !7, i64 2}
!19 = !{!20, !7, i64 8}
!20 = !{!"node_t", !21, i64 0, !16, i64 8, !6, i64 16}
!21 = !{!"vec2i_t", !10, i64 0, !10, i64 4}
!22 = !{!20, !7, i64 9}
!23 = !{!20, !7, i64 10}
!24 = !{!20, !10, i64 0}
!25 = !{!20, !10, i64 4}
!26 = !{!20, !6, i64 16}
!27 = distinct !{!27, !28}
!28 = !{!"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.vec3u8_t = type { i8, i8, i8 }

; Function Attrs: nounwind uwtable
declare dso_local void @algos_line_bres(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

declare void @gfx_point(i32 noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local void @algos_line_bres_col(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.vec3u8_t, align 1
  %5 = alloca %struct.vec3u8_t, align 1
  %6 = alloca %struct.vec3u8_t, align 1
  %7 = alloca %struct.vec3u8_t, align 1
  %8 = alloca %struct.vec3u8_t, align 1
  tail call void @algos_line_bres(ptr noundef %0, ptr noundef %1, ptr noundef %2)
  %9 = tail call i32 @queue_length(ptr noundef %2) #5
  call void @llvm.lifetime.start.p0(i64 3, ptr nonnull %4) #5
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(3) %4, ptr noundef nonnull align 8 dereferenceable(3) %10, i64 3, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.start.p0(i64 3, ptr nonnull %5) #5
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(3) %5, ptr noundef nonnull align 8 dereferenceable(3) %11, i64 3, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.start.p0(i64 3, ptr nonnull %6) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(3) %6, ptr noundef nonnull align 8 dereferenceable(3) %10, i64 3, i1 false)
  call void @llvm.lifetime.start.p0(i64 3, ptr nonnull %7) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(3) %7, ptr noundef nonnull align 8 dereferenceable(3) %11, i64 3, i1 false)
  call void @llvm.lifetime.start.p0(i64 3, ptr nonnull %8) #5
  %12 = icmp sgt i32 %9, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %13 = uitofp nneg i32 %9 to float
  %14 = getelementptr inbounds i8, ptr %8, i64 1
  %15 = getelementptr inbounds i8, ptr %8, i64 2
  br label %16

._crit_edge:                                      ; preds = %16, %3
  call void @llvm.lifetime.end.p0(i64 3, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 3, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 3, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 3, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 3, ptr nonnull %4) #5
  ret void

16:                                               ; preds = %.lr.ph, %16
  %.023 = phi i32 [ 0, %.lr.ph ], [ %40, %16 ]
  %.020.in22 = phi ptr [ %2, %.lr.ph ], [ %39, %16 ]
  %.020 = load ptr, ptr %.020.in22, align 8, !tbaa !9
  %17 = xor i32 %.023, -1
  %18 = add nsw i32 %9, %17
  %19 = sitofp i32 %18 to float
  %20 = fdiv float %19, %13
  call void @vec3u_mul_float(ptr noundef nonnull %6, ptr noundef nonnull %4, float noundef %20)
  %21 = add nsw i32 %.023, -1
  %22 = sitofp i32 %21 to float
  %23 = fdiv float %22, %13
  call void @vec3u_mul_float(ptr noundef nonnull %7, ptr noundef nonnull %5, float noundef %23)
  call void @vec3u_add(ptr noundef nonnull %8, ptr noundef nonnull %6, ptr noundef nonnull %7)
  %24 = load i8, ptr %8, align 1, !tbaa !11
  %25 = zext i8 %24 to i32
  %26 = load i8, ptr %14, align 1, !tbaa !13
  %27 = zext i8 %26 to i32
  %28 = load i8, ptr %15, align 1, !tbaa !14
  %29 = zext i8 %28 to i32
  call void @gfx_color(i32 noundef %25, i32 noundef %27, i32 noundef %29) #5
  %30 = load i8, ptr %8, align 1, !tbaa !11
  %31 = getelementptr inbounds i8, ptr %.020, i64 8
  store i8 %30, ptr %31, align 8, !tbaa !15
  %32 = load i8, ptr %14, align 1, !tbaa !13
  %33 = getelementptr inbounds i8, ptr %.020, i64 9
  store i8 %32, ptr %33, align 1, !tbaa !19
  %34 = load i8, ptr %15, align 1, !tbaa !14
  %35 = getelementptr inbounds i8, ptr %.020, i64 10
  store i8 %34, ptr %35, align 2, !tbaa !20
  %36 = load i32, ptr %.020, align 8, !tbaa !21
  %37 = getelementptr inbounds i8, ptr %.020, i64 4
  %38 = load i32, ptr %37, align 4, !tbaa !22
  call void @gfx_point(i32 noundef %36, i32 noundef %38) #5
  call void (...) @gfx_flush() #5
  %39 = getelementptr inbounds i8, ptr %.020, i64 16
  %40 = add nuw nsw i32 %.023, 1
  %exitcond.not = icmp eq i32 %40, %9
  br i1 %exitcond.not, label %._crit_edge, label %16, !llvm.loop !23
}

declare i32 @queue_length(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @vec3u_mul_float(ptr noundef, ptr noundef, float noundef) local_unnamed_addr #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @vec3u_add(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

declare void @gfx_color(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

declare void @gfx_flush(...) local_unnamed_addr #2

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass