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

; 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.png_row_info_struct = type { i32, i64, i8, i8, i8, i8 }

; 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_do_chop(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.png_row_info_struct, ptr %9, i32 0, i32 3
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = zext i8 %11 to i32
  %13 = icmp eq i32 %12, 16
  br i1 %13, label %14, label %62

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %15, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %16, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.png_row_info_struct, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !13
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.png_row_info_struct, ptr %20, i32 0, i32 4
  %22 = load i8, ptr %21, align 2, !tbaa !14
  %23 = zext i8 %22 to i32
  %24 = mul i32 %19, %23
  store i32 %24, ptr %8, align 4, !tbaa !15
  store i32 0, ptr %7, align 4, !tbaa !15
  br label %25

25:                                               ; preds = %33, %14
  %26 = load i32, ptr %7, align 4, !tbaa !15
  %27 = load i32, ptr %8, align 4, !tbaa !15
  %28 = icmp ult i32 %26, %27
  br i1 %28, label %29, label %40

29:                                               ; preds = %25
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i8, ptr %30, align 1, !tbaa !16
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  store i8 %31, ptr %32, align 1, !tbaa !16
  br label %33

33:                                               ; preds = %29
  %34 = load i32, ptr %7, align 4, !tbaa !15
  %35 = add i32 %34, 1
  store i32 %35, ptr %7, align 4, !tbaa !15
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 2
  store ptr %37, ptr %5, align 8, !tbaa !5
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i32 1
  store ptr %39, ptr %6, align 8, !tbaa !5
  br label %25, !llvm.loop !17

40:                                               ; preds = %25
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.png_row_info_struct, ptr %41, i32 0, i32 3
  store i8 8, ptr %42, align 1, !tbaa !9
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.png_row_info_struct, ptr %43, i32 0, i32 4
  %45 = load i8, ptr %44, align 2, !tbaa !14
  %46 = zext i8 %45 to i32
  %47 = mul nsw i32 8, %46
  %48 = trunc i32 %47 to i8
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.png_row_info_struct, ptr %49, i32 0, i32 5
  store i8 %48, ptr %50, align 1, !tbaa !19
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.png_row_info_struct, ptr %51, i32 0, i32 0
  %53 = load i32, ptr %52, align 8, !tbaa !13
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.png_row_info_struct, ptr %54, i32 0, i32 4
  %56 = load i8, ptr %55, align 2, !tbaa !14
  %57 = zext i8 %56 to i32
  %58 = mul i32 %53, %57
  %59 = zext i32 %58 to i64
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.png_row_info_struct, ptr %60, i32 0, i32 1
  store i64 %59, ptr %61, align 8, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %62

62:                                               ; preds = %40, %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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 17}
!10 = !{!"png_row_info_struct", !11, i64 0, !12, i64 8, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 19}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !11, i64 0}
!14 = !{!10, !7, i64 18}
!15 = !{!11, !11, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!10, !7, i64 19}
!20 = !{!10, !12, i64 8}


; 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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @png_do_chop(ptr nocapture noundef %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 17
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %5 = icmp eq i8 %4, 16
  br i1 %5, label %6, label %45

6:                                                ; preds = %2
  %7 = load i32, ptr %0, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 18
  %9 = load i8, ptr %8, align 2, !tbaa !12
  %10 = zext i8 %9 to i32
  %11 = mul i32 %7, %10
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %6
  %xtraiter = and i32 %11, 7
  %12 = icmp ult i32 %11, 8
  br i1 %12, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %11, -8
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.021 = phi ptr [ %1, %.lr.ph.preheader.new ], [ %35, %.lr.ph ]
  %.01819 = phi ptr [ %1, %.lr.ph.preheader.new ], [ %36, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %13 = load i8, ptr %.021, align 1, !tbaa !13
  store i8 %13, ptr %.01819, align 1, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %.021, i64 2
  %15 = getelementptr inbounds i8, ptr %.01819, i64 1
  %16 = load i8, ptr %14, align 1, !tbaa !13
  store i8 %16, ptr %15, align 1, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %.021, i64 4
  %18 = getelementptr inbounds i8, ptr %.01819, i64 2
  %19 = load i8, ptr %17, align 1, !tbaa !13
  store i8 %19, ptr %18, align 1, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %.021, i64 6
  %21 = getelementptr inbounds i8, ptr %.01819, i64 3
  %22 = load i8, ptr %20, align 1, !tbaa !13
  store i8 %22, ptr %21, align 1, !tbaa !13
  %23 = getelementptr inbounds i8, ptr %.021, i64 8
  %24 = getelementptr inbounds i8, ptr %.01819, i64 4
  %25 = load i8, ptr %23, align 1, !tbaa !13
  store i8 %25, ptr %24, align 1, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %.021, i64 10
  %27 = getelementptr inbounds i8, ptr %.01819, i64 5
  %28 = load i8, ptr %26, align 1, !tbaa !13
  store i8 %28, ptr %27, align 1, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %.021, i64 12
  %30 = getelementptr inbounds i8, ptr %.01819, i64 6
  %31 = load i8, ptr %29, align 1, !tbaa !13
  store i8 %31, ptr %30, align 1, !tbaa !13
  %32 = getelementptr inbounds i8, ptr %.021, i64 14
  %33 = getelementptr inbounds i8, ptr %.01819, i64 7
  %34 = load i8, ptr %32, align 1, !tbaa !13
  store i8 %34, ptr %33, align 1, !tbaa !13
  %35 = getelementptr inbounds i8, ptr %.021, i64 16
  %36 = getelementptr inbounds i8, ptr %.01819, i64 8
  %niter.next.7 = add i32 %niter, 8
  %niter.ncmp.7 = icmp eq i32 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !14

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.021.unr = phi ptr [ %1, %.lr.ph.preheader ], [ %35, %.lr.ph ]
  %.01819.unr = phi ptr [ %1, %.lr.ph.preheader ], [ %36, %.lr.ph ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.021.epil = phi ptr [ %38, %.lr.ph.epil ], [ %.021.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.01819.epil = phi ptr [ %39, %.lr.ph.epil ], [ %.01819.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %37 = load i8, ptr %.021.epil, align 1, !tbaa !13
  store i8 %37, ptr %.01819.epil, align 1, !tbaa !13
  %38 = getelementptr inbounds i8, ptr %.021.epil, i64 2
  %39 = getelementptr inbounds i8, ptr %.01819.epil, i64 1
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.loopexit, label %.lr.ph.epil, !llvm.loop !16

._crit_edge.loopexit:                             ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa
  %.pre = load i8, ptr %8, align 2, !tbaa !12
  %.pre22 = load i32, ptr %0, align 8, !tbaa !11
  %.pre23 = zext i8 %.pre to i32
  %.pre24 = mul i32 %.pre22, %.pre23
  %40 = zext i32 %.pre24 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %6
  %.pre-phi25 = phi i64 [ %40, %._crit_edge.loopexit ], [ 0, %6 ]
  %41 = phi i8 [ %.pre, %._crit_edge.loopexit ], [ %9, %6 ]
  store i8 8, ptr %3, align 1, !tbaa !5
  %42 = shl i8 %41, 3
  %43 = getelementptr inbounds i8, ptr %0, i64 19
  store i8 %42, ptr %43, align 1, !tbaa !18
  %44 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %.pre-phi25, ptr %44, align 8, !tbaa !19
  br label %45

45:                                               ; preds = %._crit_edge, %2
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: 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)"}
!5 = !{!6, !8, i64 17}
!6 = !{!"png_row_info_struct", !7, i64 0, !10, i64 8, !8, i64 16, !8, i64 17, !8, i64 18, !8, i64 19}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !8, i64 18}
!13 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.unroll.disable"}
!18 = !{!6, !8, i64 19}
!19 = !{!6, !10, i64 8}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass