; LLVM IR from zchrissirhcz/pixel :: legacy/NaiveCNN/src (naive_cnn)

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

@.str.6 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [17 x i8], align 1
@__PRETTY_FUNCTION__.nc_swap_rgb_and_bgr_inplace = external hidden unnamed_addr constant [47 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 uwtable
define dso_local void @nc_swap_rgb_and_bgr_inplace(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.px_image_t, ptr %9, i32 0, i32 3
  %11 = load i32, ptr %10, align 8, !tbaa !9
  %12 = icmp eq i32 %11, 3
  br i1 %12, label %13, label %14

13:                                               ; preds = %1
  br label %15

14:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str.14, ptr noundef @.str.6, i32 noundef 274, ptr noundef @__PRETTY_FUNCTION__.nc_swap_rgb_and_bgr_inplace) #3
  unreachable

15:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.px_image_t, ptr %16, i32 0, i32 3
  %18 = load i32, ptr %17, align 8, !tbaa !9
  store i32 %18, ptr %3, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !12
  br label %19

19:                                               ; preds = %68, %15
  %20 = load i32, ptr %4, align 4, !tbaa !12
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.px_image_t, ptr %21, i32 0, i32 2
  %23 = load i32, ptr %22, align 4, !tbaa !13
  %24 = icmp slt i32 %20, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %19
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %71

26:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.px_image_t, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = load i32, ptr %4, align 4, !tbaa !12
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.px_image_t, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !15
  %34 = mul nsw i32 %30, %33
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.px_image_t, ptr %35, i32 0, i32 3
  %37 = load i32, ptr %36, align 8, !tbaa !9
  %38 = mul nsw i32 %34, %37
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %29, i64 %39
  store ptr %40, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !12
  br label %41

41:                                               ; preds = %64, %26
  %42 = load i32, ptr %7, align 4, !tbaa !12
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.px_image_t, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 8, !tbaa !15
  %46 = icmp slt i32 %42, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %41
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %67

48:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #4
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i64 0
  %51 = load i8, ptr %50, align 1, !tbaa !16
  store i8 %51, ptr %8, align 1, !tbaa !16
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 2
  %54 = load i8, ptr %53, align 1, !tbaa !16
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %55, i64 0
  store i8 %54, ptr %56, align 1, !tbaa !16
  %57 = load i8, ptr %8, align 1, !tbaa !16
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %58, i64 2
  store i8 %57, ptr %59, align 1, !tbaa !16
  %60 = load i32, ptr %3, align 4, !tbaa !12
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = sext i32 %60 to i64
  %63 = getelementptr inbounds i8, ptr %61, i64 %62
  store ptr %63, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  br label %64

64:                                               ; preds = %48
  %65 = load i32, ptr %7, align 4, !tbaa !12
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %7, align 4, !tbaa !12
  br label %41, !llvm.loop !17

67:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %4, align 4, !tbaa !12
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %4, align 4, !tbaa !12
  br label %19, !llvm.loop !19

71:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr 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 = { noreturn 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 = { noreturn nounwind }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 16}
!10 = !{!"px_image_t", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 12}
!14 = !{!10, !6, i64 0}
!15 = !{!10, !11, i64 8}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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"

@.str.6 = external hidden unnamed_addr constant [84 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [17 x i8], align 1
@__PRETTY_FUNCTION__.nc_swap_rgb_and_bgr_inplace = external hidden unnamed_addr constant [47 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @nc_swap_rgb_and_bgr_inplace(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp eq i32 %3, 3
  br i1 %4, label %.preheader, label %11

.preheader:                                       ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 12
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph24, label %._crit_edge25

.lr.ph24:                                         ; preds = %.preheader
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !12
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph24.split, label %._crit_edge25

11:                                               ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str.14, ptr noundef nonnull @.str.6, i32 noundef 274, ptr noundef nonnull @__PRETTY_FUNCTION__.nc_swap_rgb_and_bgr_inplace) #2
  unreachable

._crit_edge25:                                    ; preds = %._crit_edge, %.lr.ph24, %.preheader
  ret void

.lr.ph24.split:                                   ; preds = %.lr.ph24, %._crit_edge
  %12 = phi i32 [ %21, %._crit_edge ], [ %6, %.lr.ph24 ]
  %13 = phi i32 [ %22, %._crit_edge ], [ %9, %.lr.ph24 ]
  %.023 = phi i32 [ %23, %._crit_edge ], [ 0, %.lr.ph24 ]
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.lr.ph24.split
  %15 = load ptr, ptr %0, align 8, !tbaa !13
  %16 = mul nuw nsw i32 %13, %.023
  %17 = load i32, ptr %2, align 8, !tbaa !5
  %18 = mul nsw i32 %16, %17
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %15, i64 %19
  br label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %5, align 4, !tbaa !11
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph24.split
  %21 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %12, %.lr.ph24.split ]
  %22 = phi i32 [ %30, %._crit_edge.loopexit ], [ %13, %.lr.ph24.split ]
  %23 = add nuw nsw i32 %.023, 1
  %24 = icmp slt i32 %23, %21
  br i1 %24, label %.lr.ph24.split, label %._crit_edge25, !llvm.loop !14

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.01822 = phi i32 [ %29, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.01921 = phi ptr [ %28, %.lr.ph ], [ %20, %.lr.ph.preheader ]
  %25 = load i8, ptr %.01921, align 1, !tbaa !17
  %26 = getelementptr inbounds i8, ptr %.01921, i64 2
  %27 = load i8, ptr %26, align 1, !tbaa !17
  store i8 %27, ptr %.01921, align 1, !tbaa !17
  store i8 %25, ptr %26, align 1, !tbaa !17
  %28 = getelementptr inbounds i8, ptr %.01921, i64 3
  %29 = add nuw nsw i32 %.01822, 1
  %30 = load i32, ptr %8, align 8, !tbaa !12
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !18
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr 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 = { noreturn 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 = { noreturn 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 16}
!6 = !{!"px_image_t", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 12}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !7, i64 0}
!14 = distinct !{!14, !15, !16}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.unswitch.partial.disable"}
!17 = !{!8, !8, i64 0}
!18 = distinct !{!18, !15}


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