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

; 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_size_t = type { i32, i32 }
%struct.px_pooling_param_t = type { i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local i64 @px_get_pooling_output_matrix_dim(i64 %0, i64 %1, i64 %2) #0 {
  %4 = alloca %struct.px_size_t, align 4
  %5 = alloca %struct.px_size_t, align 4
  %6 = alloca %struct.px_pooling_param_t, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i64 %0, ptr %5, align 4
  %15 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 0
  store i64 %1, ptr %15, align 4
  %16 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 1
  store i64 %2, ptr %16, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %17 = getelementptr inbounds %struct.px_size_t, ptr %5, i32 0, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !5
  store i32 %18, ptr %7, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %19 = getelementptr inbounds %struct.px_size_t, ptr %5, i32 0, i32 0
  %20 = load i32, ptr %19, align 4, !tbaa !11
  store i32 %20, ptr %8, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %21 = getelementptr inbounds %struct.px_pooling_param_t, ptr %6, i32 0, i32 0
  %22 = load i32, ptr %21, align 4, !tbaa !12
  store i32 %22, ptr %9, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %23 = getelementptr inbounds %struct.px_pooling_param_t, ptr %6, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !14
  store i32 %24, ptr %10, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %25 = getelementptr inbounds %struct.px_pooling_param_t, ptr %6, i32 0, i32 2
  %26 = load i32, ptr %25, align 4, !tbaa !15
  store i32 %26, ptr %11, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %27 = getelementptr inbounds %struct.px_pooling_param_t, ptr %6, i32 0, i32 3
  %28 = load i32, ptr %27, align 4, !tbaa !16
  store i32 %28, ptr %12, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %29 = load i32, ptr %7, align 4, !tbaa !10
  %30 = load i32, ptr %9, align 4, !tbaa !10
  %31 = sub nsw i32 %29, %30
  %32 = load i32, ptr %11, align 4, !tbaa !10
  %33 = sdiv i32 %31, %32
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %13, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %35 = load i32, ptr %8, align 4, !tbaa !10
  %36 = load i32, ptr %10, align 4, !tbaa !10
  %37 = sub nsw i32 %35, %36
  %38 = load i32, ptr %12, align 4, !tbaa !10
  %39 = sdiv i32 %37, %38
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %14, align 4, !tbaa !10
  call void @llvm.memset.p0.i64(ptr align 4 %4, i8 0, i64 8, i1 false)
  %41 = load i32, ptr %13, align 4, !tbaa !10
  %42 = getelementptr inbounds %struct.px_size_t, ptr %4, i32 0, i32 1
  store i32 %41, ptr %42, align 4, !tbaa !5
  %43 = load i32, ptr %14, align 4, !tbaa !10
  %44 = getelementptr inbounds %struct.px_size_t, ptr %4, i32 0, i32 0
  store i32 %43, ptr %44, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %45 = load i64, ptr %4, align 4
  ret i64 %45
}

; 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

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 = { 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, !7, i64 4}
!6 = !{!"px_size_t", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!13, !7, i64 0}
!13 = !{!"px_pooling_param_t", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!14 = !{!13, !7, i64 4}
!15 = !{!13, !7, i64 8}
!16 = !{!13, !7, i64 12}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local i64 @px_get_pooling_output_matrix_dim(i64 %0, i64 %1, i64 %2) local_unnamed_addr #0 {
  %.sroa.08.0.extract.trunc = trunc i64 %0 to i32
  %.sroa.29.0.extract.shift = lshr i64 %0, 32
  %.sroa.29.0.extract.trunc = trunc nuw i64 %.sroa.29.0.extract.shift to i32
  %.sroa.0.0.extract.trunc = trunc i64 %1 to i32
  %.sroa.2.0.extract.shift = lshr i64 %1, 32
  %.sroa.2.0.extract.trunc = trunc nuw i64 %.sroa.2.0.extract.shift to i32
  %.sroa.3.8.extract.trunc = trunc i64 %2 to i32
  %.sroa.5.8.extract.shift = lshr i64 %2, 32
  %.sroa.5.8.extract.trunc = trunc nuw i64 %.sroa.5.8.extract.shift to i32
  %4 = sub nsw i32 %.sroa.29.0.extract.trunc, %.sroa.0.0.extract.trunc
  %5 = sdiv i32 %4, %.sroa.3.8.extract.trunc
  %6 = add nsw i32 %5, 1
  %7 = sub nsw i32 %.sroa.08.0.extract.trunc, %.sroa.2.0.extract.trunc
  %8 = sdiv i32 %7, %.sroa.5.8.extract.trunc
  %9 = add nsw i32 %8, 1
  %.sroa.311.0.insert.ext = zext i32 %6 to i64
  %.sroa.311.0.insert.shift = shl nuw i64 %.sroa.311.0.insert.ext, 32
  %.sroa.010.0.insert.ext = zext i32 %9 to i64
  %.sroa.010.0.insert.insert = or disjoint i64 %.sroa.311.0.insert.shift, %.sroa.010.0.insert.ext
  ret i64 %.sroa.010.0.insert.insert
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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" }

!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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass