; LLVM IR from zchrissirhcz/pixel :: src (px_convolution)

; 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_conv_param_t = type { i32, i32, i32, i32, i32, i32 }
%struct.px_size_t = type { i32, i32 }
%struct.px_cube_dim_t = type { i32, i32, i32 }
%struct.px_matrix_t = type { ptr, i32, i32 }

@.str = external hidden unnamed_addr constant [24 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [73 x i8], align 1
@__PRETTY_FUNCTION__.px_forward_convolution_layer_for_cube = external hidden unnamed_addr constant [136 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @px_get_conv_output_matrix_dim(i64, i64, ptr noundef byval(%struct.px_conv_param_t) align 8) #0

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 ptr @px_forward_convolution_layer_for_cube(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef byval(%struct.px_conv_param_t) align 8 %3, ptr noundef %4, i32 noundef %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca %struct.px_size_t, align 4
  %13 = alloca %struct.px_size_t, align 4
  %14 = alloca %struct.px_size_t, align 4
  %15 = alloca %struct.px_cube_dim_t, align 4
  %16 = alloca ptr, align 8
  %17 = alloca { i64, i32 }, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca ptr, align 8
  %22 = alloca ptr, align 8
  %23 = alloca ptr, align 8
  %24 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  store i32 %5, ptr %11, align 4, !tbaa !9
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = icmp eq i32 %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %6
  br label %30

29:                                               ; preds = %6
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 43, ptr noundef @__PRETTY_FUNCTION__.px_forward_convolution_layer_for_cube) #6
  unreachable

30:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #7
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = call i64 @px_get_channel_wise_matrix_dim(ptr noundef %31)
  store i64 %32, ptr %12, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #7
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds ptr, ptr %33, i64 0
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = call i64 @px_get_channel_wise_matrix_dim(ptr noundef %35)
  store i64 %36, ptr %13, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #7
  %37 = load i64, ptr %12, align 4
  %38 = load i64, ptr %13, align 4
  %39 = call i64 @px_get_conv_output_matrix_dim(i64 %37, i64 %38, ptr noundef byval(%struct.px_conv_param_t) align 8 %3)
  store i64 %39, ptr %14, align 4
  call void @llvm.lifetime.start.p0(i64 12, ptr %15) #7
  call void @llvm.memset.p0.i64(ptr align 4 %15, i8 0, i64 12, i1 false)
  %40 = getelementptr inbounds %struct.px_size_t, ptr %14, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !11
  %42 = getelementptr inbounds %struct.px_cube_dim_t, ptr %15, i32 0, i32 1
  store i32 %41, ptr %42, align 4, !tbaa !13
  %43 = getelementptr inbounds %struct.px_size_t, ptr %14, i32 0, i32 0
  %44 = load i32, ptr %43, align 4, !tbaa !15
  %45 = getelementptr inbounds %struct.px_cube_dim_t, ptr %15, i32 0, i32 2
  store i32 %44, ptr %45, align 4, !tbaa !16
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = getelementptr inbounds %struct.px_cube_dim_t, ptr %15, i32 0, i32 0
  store i32 %46, ptr %47, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #7
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %17, ptr align 4 %15, i64 12, i1 false)
  %48 = getelementptr inbounds { i64, i32 }, ptr %17, i32 0, i32 0
  %49 = load i64, ptr %48, align 4
  %50 = getelementptr inbounds { i64, i32 }, ptr %17, i32 0, i32 1
  %51 = load i32, ptr %50, align 4
  %52 = call ptr @px_create_cube(i64 %49, i32 %51)
  store ptr %52, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #7
  %53 = getelementptr inbounds %struct.px_cube_dim_t, ptr %15, i32 0, i32 1
  %54 = load i32, ptr %53, align 4, !tbaa !13
  store i32 %54, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #7
  %55 = getelementptr inbounds %struct.px_cube_dim_t, ptr %15, i32 0, i32 2
  %56 = load i32, ptr %55, align 4, !tbaa !16
  store i32 %56, ptr %19, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #7
  store i32 0, ptr %20, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %92, %30
  %58 = load i32, ptr %20, align 4, !tbaa !9
  %59 = load i32, ptr %9, align 4, !tbaa !9
  %60 = icmp slt i32 %58, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #7
  br label %95

62:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #7
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = load i32, ptr %20, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds ptr, ptr %64, i64 %66
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = load i32, ptr %20, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds float, ptr %69, i64 %71
  %73 = load float, ptr %72, align 4, !tbaa !18
  %74 = call ptr @px_forward_convolution_layer_for_cube_with_one_kernel(ptr noundef %63, ptr noundef %68, ptr noundef byval(%struct.px_conv_param_t) align 8 %3, float noundef %73)
  store ptr %74, ptr %21, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #7
  %75 = load ptr, ptr %16, align 8, !tbaa !5
  %76 = load i32, ptr %20, align 4, !tbaa !9
  %77 = call ptr @px_get_matrix_data_from_cube(ptr noundef %75, i32 noundef %76)
  store ptr %77, ptr %22, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #7
  %78 = load ptr, ptr %21, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.px_matrix_t, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !20
  store ptr %80, ptr %23, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #7
  %81 = load i32, ptr %18, align 4, !tbaa !9
  %82 = load i32, ptr %19, align 4, !tbaa !9
  %83 = mul nsw i32 %81, %82
  %84 = sext i32 %83 to i64
  %85 = mul i64 %84, 4
  %86 = trunc i64 %85 to i32
  store i32 %86, ptr %24, align 4, !tbaa !9
  %87 = load ptr, ptr %22, align 8, !tbaa !5
  %88 = load ptr, ptr %23, align 8, !tbaa !5
  %89 = load i32, ptr %24, align 4, !tbaa !9
  %90 = sext i32 %89 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %87, ptr align 1 %88, i64 %90, i1 false)
  %91 = load ptr, ptr %21, align 8, !tbaa !5
  call void @px_destroy_matrix(ptr noundef %91)
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #7
  br label %92

92:                                               ; preds = %62
  %93 = load i32, ptr %20, align 4, !tbaa !9
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %20, align 4, !tbaa !9
  br label %57, !llvm.loop !22

95:                                               ; preds = %61
  %96 = load ptr, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  ret ptr %96
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

declare i64 @px_get_channel_wise_matrix_dim(ptr noundef) #4

declare ptr @px_create_cube(i64, i32) #4

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @px_forward_convolution_layer_for_cube_with_one_kernel(ptr noundef, ptr noundef, ptr noundef byval(%struct.px_conv_param_t) align 8, float noundef) #0

declare ptr @px_get_matrix_data_from_cube(ptr noundef, i32 noundef) #4

declare void @px_destroy_matrix(ptr noundef) #4

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { noreturn nounwind }
attributes #7 = { 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 = !{!12, !10, i64 4}
!12 = !{!"px_size_t", !10, i64 0, !10, i64 4}
!13 = !{!14, !10, i64 4}
!14 = !{!"px_cube_dim_t", !10, i64 0, !10, i64 4, !10, i64 8}
!15 = !{!12, !10, i64 0}
!16 = !{!14, !10, i64 8}
!17 = !{!14, !10, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"float", !7, i64 0}
!20 = !{!21, !6, i64 0}
!21 = !{!"px_matrix_t", !6, i64 0, !10, i64 8, !10, i64 12}
!22 = distinct !{!22, !23}
!23 = !{!"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.px_conv_param_t = type { i32, i32, i32, i32, i32, i32 }

@.str = external hidden unnamed_addr constant [24 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [73 x i8], align 1
@__PRETTY_FUNCTION__.px_forward_convolution_layer_for_cube = external hidden unnamed_addr constant [136 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @px_get_conv_output_matrix_dim(i64, i64, ptr noundef byval(%struct.px_conv_param_t) align 8) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @px_forward_convolution_layer_for_cube(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr noundef byval(%struct.px_conv_param_t) align 8 %3, ptr nocapture noundef readonly %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = icmp eq i32 %2, %5
  br i1 %7, label %9, label %8

8:                                                ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 43, ptr noundef nonnull @__PRETTY_FUNCTION__.px_forward_convolution_layer_for_cube) #4
  unreachable

9:                                                ; preds = %6
  %10 = tail call i64 @px_get_channel_wise_matrix_dim(ptr noundef %0) #5
  %11 = load ptr, ptr %1, align 8, !tbaa !5
  %12 = tail call i64 @px_get_channel_wise_matrix_dim(ptr noundef %11) #5
  %13 = tail call i64 @px_get_conv_output_matrix_dim(i64 %10, i64 %12, ptr noundef nonnull byval(%struct.px_conv_param_t) align 8 %3)
  %.sroa.017.0.extract.trunc = trunc i64 %13 to i32
  %.sroa.013.sroa.5.0.insert.shift = and i64 %13, -4294967296
  %.sroa.013.sroa.0.0.insert.ext = zext i32 %2 to i64
  %.sroa.013.sroa.0.0.insert.insert = or disjoint i64 %.sroa.013.sroa.5.0.insert.shift, %.sroa.013.sroa.0.0.insert.ext
  %14 = tail call ptr @px_create_cube(i64 %.sroa.013.sroa.0.0.insert.insert, i32 %.sroa.017.0.extract.trunc) #5
  %15 = icmp sgt i32 %2, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %9
  %.sroa.4.0.extract.shift = lshr i64 %13, 32
  %16 = mul i64 %.sroa.4.0.extract.shift, %13
  %.tr = trunc i64 %16 to i32
  %17 = shl i32 %.tr, 2
  %18 = sext i32 %17 to i64
  br label %19

._crit_edge:                                      ; preds = %19, %9
  ret ptr %14

19:                                               ; preds = %.lr.ph, %19
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %19 ]
  %20 = getelementptr inbounds ptr, ptr %1, i64 %indvars.iv
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = getelementptr inbounds float, ptr %4, i64 %indvars.iv
  %23 = load float, ptr %22, align 4, !tbaa !9
  %24 = tail call ptr @px_forward_convolution_layer_for_cube_with_one_kernel(ptr noundef %0, ptr noundef %21, ptr noundef nonnull byval(%struct.px_conv_param_t) align 8 %3, float noundef %23)
  %25 = trunc nuw nsw i64 %indvars.iv to i32
  %26 = tail call ptr @px_get_matrix_data_from_cube(ptr noundef %14, i32 noundef %25) #5
  %27 = load ptr, ptr %24, align 8, !tbaa !11
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %26, ptr align 1 %27, i64 %18, i1 false)
  tail call void @px_destroy_matrix(ptr noundef nonnull %24) #5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %.sroa.013.sroa.0.0.insert.ext
  br i1 %exitcond.not, label %._crit_edge, label %19, !llvm.loop !14
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare i64 @px_get_channel_wise_matrix_dim(ptr noundef) local_unnamed_addr #2

declare ptr @px_create_cube(i64, i32) 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: nounwind uwtable
declare dso_local ptr @px_forward_convolution_layer_for_cube_with_one_kernel(ptr noundef, ptr noundef, ptr noundef byval(%struct.px_conv_param_t) align 8, float noundef) local_unnamed_addr #0

declare ptr @px_get_matrix_data_from_cube(ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @px_destroy_matrix(ptr noundef) 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 = { 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 = { "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 = { noreturn nounwind }
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 = !{!"float", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"px_matrix_t", !6, i64 0, !13, i64 8, !13, i64 12}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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