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

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

@.str = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: noreturn nounwind uwtable
declare dso_local void @png_error(ptr noalias noundef, ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: noreturn nounwind uwtable
define dso_local void @png_fixed_error(ptr noalias noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca [220 x i8], align 16
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 220, ptr %6) #3
  %7 = getelementptr inbounds [220 x i8], ptr %6, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %7, ptr align 1 @.str, i64 24, i1 false)
  store i32 0, ptr %5, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %37

10:                                               ; preds = %2
  br label %11

11:                                               ; preds = %24, %10
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = icmp ult i32 %12, 195
  br i1 %13, label %14, label %22

14:                                               ; preds = %11
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds i8, ptr %15, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !11
  %20 = sext i8 %19 to i32
  %21 = icmp ne i32 %20, 0
  br label %22

22:                                               ; preds = %14, %11
  %23 = phi i1 [ false, %11 ], [ %21, %14 ]
  br i1 %23, label %24, label %36

24:                                               ; preds = %22
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %25, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !11
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  %32 = add i64 24, %31
  %33 = getelementptr inbounds [220 x i8], ptr %6, i64 0, i64 %32
  store i8 %29, ptr %33, align 1, !tbaa !11
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = add i32 %34, 1
  store i32 %35, ptr %5, align 4, !tbaa !9
  br label %11, !llvm.loop !12

36:                                               ; preds = %22
  br label %37

37:                                               ; preds = %36, %2
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = zext i32 %38 to i64
  %40 = add i64 24, %39
  %41 = getelementptr inbounds [220 x i8], ptr %6, i64 0, i64 %40
  store i8 0, ptr %41, align 1, !tbaa !11
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds [220 x i8], ptr %6, i64 0, i64 0
  call void @png_error(ptr noundef %42, ptr noundef %43) #4
  unreachable
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

attributes #0 = { noreturn 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: readwrite) }
attributes #3 = { nounwind }
attributes #4 = { noreturn }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@.str = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: noreturn nounwind uwtable
declare dso_local void @png_error(ptr noalias noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: noreturn nounwind uwtable
define dso_local void @png_fixed_error(ptr noalias noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca [220 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 220, ptr nonnull %3) #3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(24) %3, ptr noundef nonnull align 1 dereferenceable(24) @.str, i64 24, i1 false)
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %.critedge, label %.preheader

.preheader:                                       ; preds = %2, %19
  %.0 = phi i32 [ %22, %19 ], [ 0, %2 ]
  %4 = zext nneg i32 %.0 to i64
  %5 = getelementptr inbounds i8, ptr %1, i64 %4
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %.not13 = icmp eq i8 %6, 0
  br i1 %.not13, label %.critedge.loopexit, label %.preheader.1

.preheader.1:                                     ; preds = %.preheader
  %7 = add nuw nsw i64 %4, 24
  %8 = getelementptr inbounds [220 x i8], ptr %3, i64 0, i64 %7
  store i8 %6, ptr %8, align 1, !tbaa !5
  %9 = add nuw nsw i32 %.0, 1
  %10 = zext nneg i32 %9 to i64
  %11 = getelementptr inbounds i8, ptr %1, i64 %10
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %.not13.1 = icmp eq i8 %12, 0
  br i1 %.not13.1, label %.critedge.loopexit, label %.preheader.2

.preheader.2:                                     ; preds = %.preheader.1
  %13 = add nuw nsw i64 %10, 24
  %14 = getelementptr inbounds [220 x i8], ptr %3, i64 0, i64 %13
  store i8 %12, ptr %14, align 1, !tbaa !5
  %15 = add nuw nsw i32 %.0, 2
  %16 = zext nneg i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %1, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %.not13.2 = icmp eq i8 %18, 0
  br i1 %.not13.2, label %.critedge.loopexit, label %19

19:                                               ; preds = %.preheader.2
  %20 = add nuw nsw i64 %16, 24
  %21 = getelementptr inbounds [220 x i8], ptr %3, i64 0, i64 %20
  store i8 %18, ptr %21, align 1, !tbaa !5
  %22 = add nuw nsw i32 %.0, 3
  %exitcond.not.2 = icmp eq i32 %22, 195
  br i1 %exitcond.not.2, label %.critedge.loopexit, label %.preheader

.critedge.loopexit:                               ; preds = %19, %.preheader.2, %.preheader.1, %.preheader
  %.1.ph = phi i32 [ %.0, %.preheader ], [ %9, %.preheader.1 ], [ %15, %.preheader.2 ], [ 195, %19 ]
  %narrow = add nuw i32 %.1.ph, 24
  %23 = zext i32 %narrow to i64
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %2
  %.1 = phi i64 [ 24, %2 ], [ %23, %.critedge.loopexit ]
  %24 = getelementptr inbounds [220 x i8], ptr %3, i64 0, i64 %.1
  store i8 0, ptr %24, align 1, !tbaa !5
  call void @png_error(ptr noundef %0, ptr noundef nonnull %3) #4
  unreachable
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

attributes #0 = { noreturn 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind }
attributes #4 = { noreturn }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass