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

; 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.NcLayerBottomTop = type { i32, ptr, ptr }
%struct.NcBlob = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr }
%struct.NcPoolingParam = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, %struct.px_size_t, ptr, ptr }
%struct.px_size_t = type { i32, i32 }

@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [33 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
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

declare void @nc_blob_data_realloc3d(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @nc_infer_pooling(ptr noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  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
  br label %10

10:                                               ; preds = %3
  %11 = load ptr, ptr @stderr, align 8, !tbaa !5
  %12 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef @.str.3) #4
  %13 = load ptr, ptr @stderr, align 8, !tbaa !5
  %14 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef @.str.1) #4
  br label %15

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %16, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.NcLayerBottomTop, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds ptr, ptr %19, i64 0
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  store ptr %21, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.NcLayerBottomTop, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = getelementptr inbounds ptr, ptr %24, i64 0
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  store ptr %26, ptr %9, align 8, !tbaa !5
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.NcBlob, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !12
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.NcPoolingParam, ptr %30, i32 0, i32 2
  store i32 %29, ptr %31, align 8, !tbaa !14
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.NcBlob, ptr %32, i32 0, i32 2
  %34 = load i32, ptr %33, align 8, !tbaa !17
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.NcPoolingParam, ptr %35, i32 0, i32 3
  store i32 %34, ptr %36, align 4, !tbaa !18
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.NcPoolingParam, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 8, !tbaa !14
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.NcPoolingParam, ptr %40, i32 0, i32 4
  %42 = load i32, ptr %41, align 8, !tbaa !19
  %43 = sub nsw i32 %39, %42
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.NcPoolingParam, ptr %44, i32 0, i32 11
  %46 = getelementptr inbounds %struct.px_size_t, ptr %45, i32 0, i32 1
  %47 = load i32, ptr %46, align 4, !tbaa !20
  %48 = sdiv i32 %43, %47
  %49 = add nsw i32 %48, 1
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.NcPoolingParam, ptr %50, i32 0, i32 7
  store i32 %49, ptr %51, align 4, !tbaa !21
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.NcPoolingParam, ptr %52, i32 0, i32 3
  %54 = load i32, ptr %53, align 4, !tbaa !18
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.NcPoolingParam, ptr %55, i32 0, i32 4
  %57 = load i32, ptr %56, align 8, !tbaa !19
  %58 = sub nsw i32 %54, %57
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.NcPoolingParam, ptr %59, i32 0, i32 11
  %61 = getelementptr inbounds %struct.px_size_t, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 4, !tbaa !22
  %63 = sdiv i32 %58, %62
  %64 = add nsw i32 %63, 1
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.NcPoolingParam, ptr %65, i32 0, i32 8
  store i32 %64, ptr %66, align 8, !tbaa !23
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.NcPoolingParam, ptr %68, i32 0, i32 7
  %70 = load i32, ptr %69, align 4, !tbaa !21
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.NcPoolingParam, ptr %71, i32 0, i32 8
  %73 = load i32, ptr %72, align 8, !tbaa !23
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.NcPoolingParam, ptr %74, i32 0, i32 6
  %76 = load i32, ptr %75, align 8, !tbaa !24
  call void @nc_blob_data_realloc3d(ptr noundef %67, i32 noundef %70, i32 noundef %73, i32 noundef %76)
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.NcBlob, ptr %77, i32 0, i32 8
  %79 = load i32, ptr %78, align 8, !tbaa !25
  %80 = icmp eq i32 %79, 1
  br i1 %80, label %81, label %85

81:                                               ; preds = %15
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  call void @nc_pooling_forward_nhwc(ptr noundef %82, ptr noundef %83, ptr noundef %84)
  br label %95

85:                                               ; preds = %15
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.NcBlob, ptr %86, i32 0, i32 8
  %88 = load i32, ptr %87, align 8, !tbaa !25
  %89 = icmp eq i32 %88, 0
  br i1 %89, label %90, label %94

90:                                               ; preds = %85
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = load ptr, ptr %9, align 8, !tbaa !5
  call void @nc_pooling_forward_nchw(ptr noundef %91, ptr noundef %92, ptr noundef %93)
  br label %94

94:                                               ; preds = %90, %85
  br label %95

95:                                               ; preds = %94, %81
  %96 = load ptr, ptr %8, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.NcBlob, ptr %96, i32 0, i32 7
  %98 = load i32, ptr %97, align 4, !tbaa !26
  %99 = add nsw i32 %98, -1
  store i32 %99, ptr %97, align 4, !tbaa !26
  %100 = load ptr, ptr %8, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.NcBlob, ptr %100, i32 0, i32 7
  %102 = load i32, ptr %101, align 4, !tbaa !26
  %103 = icmp eq i32 %102, 0
  br i1 %103, label %104, label %110

104:                                              ; preds = %95
  %105 = load ptr, ptr %8, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.NcBlob, ptr %105, i32 0, i32 9
  %107 = load ptr, ptr %106, align 8, !tbaa !27
  call void @free(ptr noundef %107) #4
  %108 = load ptr, ptr %8, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.NcBlob, ptr %108, i32 0, i32 9
  store ptr null, ptr %109, align 8, !tbaa !27
  br label %110

110:                                              ; preds = %104, %95
  br label %111

111:                                              ; preds = %110
  %112 = load ptr, ptr @stderr, align 8, !tbaa !5
  %113 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %112, ptr noundef @.str.4) #4
  %114 = load ptr, ptr @stderr, align 8, !tbaa !5
  %115 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %114, ptr noundef @.str.1) #4
  br label %116

116:                                              ; preds = %111
  br label %117

117:                                              ; preds = %116
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret void
}

declare void @nc_pooling_forward_nhwc(ptr noundef, ptr noundef, ptr noundef) #2

declare void @nc_pooling_forward_nchw(ptr noundef, ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 #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, !6, i64 8}
!10 = !{!"NcLayerBottomTop", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 4}
!13 = !{!"NcBlob", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !6, i64 40}
!14 = !{!15, !11, i64 8}
!15 = !{!"NcPoolingParam", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !16, i64 44, !6, i64 56, !6, i64 64}
!16 = !{!"px_size_t", !11, i64 0, !11, i64 4}
!17 = !{!13, !11, i64 8}
!18 = !{!15, !11, i64 12}
!19 = !{!15, !11, i64 16}
!20 = !{!15, !11, i64 48}
!21 = !{!15, !11, i64 28}
!22 = !{!15, !11, i64 44}
!23 = !{!15, !11, i64 32}
!24 = !{!15, !11, i64 24}
!25 = !{!13, !11, i64 32}
!26 = !{!13, !11, i64 28}
!27 = !{!13, !6, i64 40}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [33 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

declare void @nc_blob_data_realloc3d(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @nc_infer_pooling(ptr noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #3 {
  %4 = load ptr, ptr @stderr, align 8, !tbaa !5
  %5 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %4, ptr noundef nonnull @.str.3) #4
  %6 = load ptr, ptr @stderr, align 8, !tbaa !5
  %7 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %6, ptr noundef nonnull @.str.1) #4
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %2, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %10, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %15, ptr %16, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %10, i64 8
  %18 = load i32, ptr %17, align 8, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %18, ptr %19, align 4, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  %21 = load i32, ptr %20, align 8, !tbaa !19
  %22 = sub nsw i32 %15, %21
  %23 = getelementptr inbounds i8, ptr %0, i64 44
  %24 = getelementptr inbounds i8, ptr %0, i64 48
  %25 = load i32, ptr %24, align 4, !tbaa !20
  %26 = sdiv i32 %22, %25
  %27 = add nsw i32 %26, 1
  %28 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 %27, ptr %28, align 4, !tbaa !21
  %29 = sub nsw i32 %18, %21
  %30 = load i32, ptr %23, align 4, !tbaa !22
  %31 = sdiv i32 %29, %30
  %32 = add nsw i32 %31, 1
  %33 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 %32, ptr %33, align 8, !tbaa !23
  %34 = getelementptr inbounds i8, ptr %0, i64 24
  %35 = load i32, ptr %34, align 8, !tbaa !24
  tail call void @nc_blob_data_realloc3d(ptr noundef %13, i32 noundef %27, i32 noundef %32, i32 noundef %35) #5
  %36 = getelementptr inbounds i8, ptr %10, i64 32
  %37 = load i32, ptr %36, align 8, !tbaa !25
  switch i32 %37, label %40 [
    i32 1, label %38
    i32 0, label %39
  ]

38:                                               ; preds = %3
  tail call void @nc_pooling_forward_nhwc(ptr noundef nonnull %0, ptr noundef nonnull %10, ptr noundef %13) #5
  br label %40

39:                                               ; preds = %3
  tail call void @nc_pooling_forward_nchw(ptr noundef nonnull %0, ptr noundef nonnull %10, ptr noundef %13) #5
  br label %40

40:                                               ; preds = %3, %39, %38
  %41 = getelementptr inbounds i8, ptr %10, i64 28
  %42 = load i32, ptr %41, align 4, !tbaa !26
  %43 = add nsw i32 %42, -1
  store i32 %43, ptr %41, align 4, !tbaa !26
  %44 = icmp eq i32 %43, 0
  br i1 %44, label %45, label %48

45:                                               ; preds = %40
  %46 = getelementptr inbounds i8, ptr %10, i64 40
  %47 = load ptr, ptr %46, align 8, !tbaa !27
  tail call void @free(ptr noundef %47) #5
  store ptr null, ptr %46, align 8, !tbaa !27
  br label %48

48:                                               ; preds = %40, %45
  %49 = load ptr, ptr @stderr, align 8, !tbaa !5
  %50 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %49, ptr noundef nonnull @.str.4) #4
  %51 = load ptr, ptr @stderr, align 8, !tbaa !5
  %52 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %51, ptr noundef nonnull @.str.1) #4
  ret void
}

declare void @nc_pooling_forward_nhwc(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @nc_pooling_forward_nchw(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { nofree 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 #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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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 #4 = { cold 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, !6, i64 8}
!10 = !{!"NcLayerBottomTop", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 4}
!13 = !{!"NcBlob", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !6, i64 40}
!14 = !{!15, !11, i64 8}
!15 = !{!"NcPoolingParam", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !16, i64 44, !6, i64 56, !6, i64 64}
!16 = !{!"px_size_t", !11, i64 0, !11, i64 4}
!17 = !{!13, !11, i64 8}
!18 = !{!15, !11, i64 12}
!19 = !{!15, !11, i64 16}
!20 = !{!15, !11, i64 48}
!21 = !{!15, !11, i64 28}
!22 = !{!15, !11, i64 44}
!23 = !{!15, !11, i64 32}
!24 = !{!15, !11, i64 24}
!25 = !{!13, !11, i64 32}
!26 = !{!13, !11, i64 28}
!27 = !{!13, !6, i64 40}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass