; LLVM IR from Try/Tempest :: Engine/thirdparty/libpng (pngtrans)

; 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_swap(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  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 %44

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

24:                                               ; preds = %38, %14
  %25 = load i32, ptr %6, align 4, !tbaa !15
  %26 = load i32, ptr %7, align 4, !tbaa !15
  %27 = icmp ult i32 %25, %26
  br i1 %27, label %28, label %43

28:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #2
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load i8, ptr %29, align 1, !tbaa !16
  store i8 %30, ptr %8, align 1, !tbaa !16
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i64 1
  %33 = load i8, ptr %32, align 1, !tbaa !16
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %33, ptr %34, align 1, !tbaa !16
  %35 = load i8, ptr %8, align 1, !tbaa !16
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 1
  store i8 %35, ptr %37, align 1, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  br label %38

38:                                               ; preds = %28
  %39 = load i32, ptr %6, align 4, !tbaa !15
  %40 = add i32 %39, 1
  store i32 %40, ptr %6, align 4, !tbaa !15
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 2
  store ptr %42, ptr %5, align 8, !tbaa !5
  br label %24, !llvm.loop !17

43:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %44

44:                                               ; preds = %43, %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"}


; 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_swap(ptr nocapture noundef readonly %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 %.loopexit

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 %.loopexit, label %.lr.ph.preheader

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

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

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

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

.lr.ph.epil:                                      ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph.epil
  %.014.epil = phi ptr [ %32, %.lr.ph.epil ], [ %.014.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %29 = load i8, ptr %.014.epil, align 1, !tbaa !13
  %30 = getelementptr inbounds i8, ptr %.014.epil, i64 1
  %31 = load i8, ptr %30, align 1, !tbaa !13
  store i8 %31, ptr %.014.epil, align 1, !tbaa !13
  store i8 %29, ptr %30, align 1, !tbaa !13
  %32 = getelementptr inbounds i8, ptr %.014.epil, i64 2
  %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 %.loopexit, label %.lr.ph.epil, !llvm.loop !16

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph.epil, %6, %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"}


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