; LLVM IR from niessner/Matterport :: code/gaps/pkgs/png (png)

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

; 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 @png_64bit_product(i64 noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  store i64 %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #2
  %17 = load i64, ptr %5, align 8, !tbaa !5
  %18 = ashr i64 %17, 16
  %19 = and i64 %18, 65535
  %20 = trunc i64 %19 to i32
  store i32 %20, ptr %9, align 4, !tbaa !11
  %21 = load i64, ptr %5, align 8, !tbaa !5
  %22 = and i64 %21, 65535
  %23 = trunc i64 %22 to i32
  store i32 %23, ptr %10, align 4, !tbaa !11
  %24 = load i64, ptr %6, align 8, !tbaa !5
  %25 = ashr i64 %24, 16
  %26 = and i64 %25, 65535
  %27 = trunc i64 %26 to i32
  store i32 %27, ptr %11, align 4, !tbaa !11
  %28 = load i64, ptr %6, align 8, !tbaa !5
  %29 = and i64 %28, 65535
  %30 = trunc i64 %29 to i32
  store i32 %30, ptr %12, align 4, !tbaa !11
  %31 = load i32, ptr %10, align 4, !tbaa !11
  %32 = load i32, ptr %12, align 4, !tbaa !11
  %33 = mul nsw i32 %31, %32
  %34 = sext i32 %33 to i64
  store i64 %34, ptr %13, align 8, !tbaa !5
  %35 = load i32, ptr %9, align 4, !tbaa !11
  %36 = load i32, ptr %12, align 4, !tbaa !11
  %37 = mul nsw i32 %35, %36
  %38 = load i32, ptr %11, align 4, !tbaa !11
  %39 = load i32, ptr %10, align 4, !tbaa !11
  %40 = mul nsw i32 %38, %39
  %41 = add nsw i32 %37, %40
  %42 = sext i32 %41 to i64
  store i64 %42, ptr %15, align 8, !tbaa !5
  %43 = load i64, ptr %13, align 8, !tbaa !5
  %44 = ashr i64 %43, 16
  %45 = and i64 %44, 65535
  %46 = load i64, ptr %15, align 8, !tbaa !5
  %47 = add nsw i64 %45, %46
  store i64 %47, ptr %16, align 8, !tbaa !5
  %48 = load i64, ptr %13, align 8, !tbaa !5
  %49 = and i64 %48, 65535
  %50 = load i64, ptr %16, align 8, !tbaa !5
  %51 = and i64 %50, 65535
  %52 = shl i64 %51, 16
  %53 = or i64 %49, %52
  store i64 %53, ptr %13, align 8, !tbaa !5
  %54 = load i64, ptr %16, align 8, !tbaa !5
  %55 = ashr i64 %54, 16
  %56 = and i64 %55, 65535
  store i64 %56, ptr %14, align 8, !tbaa !5
  %57 = load i32, ptr %9, align 4, !tbaa !11
  %58 = load i32, ptr %11, align 4, !tbaa !11
  %59 = mul nsw i32 %57, %58
  %60 = sext i32 %59 to i64
  %61 = load i64, ptr %14, align 8, !tbaa !5
  %62 = add nsw i64 %61, %60
  store i64 %62, ptr %14, align 8, !tbaa !5
  %63 = load i64, ptr %14, align 8, !tbaa !5
  %64 = load ptr, ptr %7, align 8, !tbaa !9
  store i64 %63, ptr %64, align 8, !tbaa !5
  %65 = load i64, ptr %13, align 8, !tbaa !5
  %66 = load ptr, ptr %8, align 8, !tbaa !9
  store i64 %65, ptr %66, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret void
}

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 = { 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 = !{!"long", !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, !12, i64 0}
!12 = !{!"int", !7, i64 0}


; 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(argmem: write) uwtable
define dso_local void @png_64bit_product(i64 noundef %0, i64 noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = trunc i64 %0 to i32
  %6 = lshr i32 %5, 16
  %7 = and i32 %5, 65535
  %8 = trunc i64 %1 to i32
  %9 = lshr i32 %8, 16
  %10 = and i32 %8, 65535
  %11 = mul nuw nsw i32 %10, %7
  %12 = zext nneg i32 %11 to i64
  %13 = mul nuw nsw i32 %10, %6
  %14 = mul nuw nsw i32 %9, %7
  %15 = add nuw nsw i32 %13, %14
  %16 = zext nneg i32 %15 to i64
  %17 = lshr i64 %12, 16
  %18 = add nuw nsw i64 %17, %16
  %19 = and i64 %12, 65535
  %20 = shl nuw nsw i64 %18, 16
  %21 = and i64 %20, 4294901760
  %22 = or disjoint i64 %21, %19
  %23 = lshr i64 %18, 16
  %24 = mul nuw nsw i32 %9, %6
  %25 = zext nneg i32 %24 to i64
  %26 = add nuw nsw i64 %23, %25
  store i64 %26, ptr %2, align 8, !tbaa !5
  store i64 %22, ptr %3, align 8, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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