; LLVM IR from zchrissirhcz/pixel :: legacy (px_png_libpng)

; 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 [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [75 x i8], align 1
@__PRETTY_FUNCTION__.px_read_png = external hidden unnamed_addr constant [69 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @px_read_png(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call noalias ptr @fopen(ptr noundef %13, ptr noundef @.str)
  store ptr %14, ptr %9, align 8, !tbaa !5
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %4
  br label %19

18:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 12, ptr noundef @__PRETTY_FUNCTION__.px_read_png) #6
  unreachable

19:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %20 = call noalias ptr @png_create_read_struct(ptr noundef @.str.3, ptr noundef null, ptr noundef null, ptr noundef null)
  store ptr %20, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = call noalias ptr @png_create_info_struct(ptr noundef %21)
  store ptr %22, ptr %11, align 8, !tbaa !5
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  call void @png_init_io(ptr noundef %23, ptr noundef %24)
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  call void @png_read_info(ptr noundef %25, ptr noundef %26)
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  %29 = call i32 @png_get_image_width(ptr noundef %27, ptr noundef %28)
  %30 = zext i32 %29 to i64
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %30, ptr %31, align 8, !tbaa !9
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = call i32 @png_get_image_height(ptr noundef %32, ptr noundef %33)
  %35 = zext i32 %34 to i64
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %35, ptr %36, align 8, !tbaa !9
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = call i64 @png_get_rowbytes(ptr noundef %39, ptr noundef %40)
  %42 = mul i64 %38, %41
  %43 = add i64 %42, 128
  %44 = call noalias ptr @malloc(i64 noundef %43) #7
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %44, ptr %45, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %46

46:                                               ; preds = %64, %19
  %47 = load i32, ptr %12, align 4, !tbaa !11
  %48 = zext i32 %47 to i64
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load i64, ptr %49, align 8, !tbaa !9
  %51 = icmp ult i64 %48, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %67

53:                                               ; preds = %46
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = load i32, ptr %12, align 4, !tbaa !11
  %58 = zext i32 %57 to i64
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = call i64 @png_get_rowbytes(ptr noundef %59, ptr noundef %60)
  %62 = mul i64 %58, %61
  %63 = getelementptr inbounds i8, ptr %56, i64 %62
  call void @png_read_row(ptr noundef %54, ptr noundef %63, ptr noundef null)
  br label %64

64:                                               ; preds = %53
  %65 = load i32, ptr %12, align 4, !tbaa !11
  %66 = add i32 %65, 1
  store i32 %66, ptr %12, align 4, !tbaa !11
  br label %46, !llvm.loop !13

67:                                               ; preds = %52
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  call void @png_read_end(ptr noundef %68, ptr noundef %69)
  call void @png_destroy_read_struct(ptr noundef %10, ptr noundef %11, ptr noundef null)
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = call i32 @fclose(ptr noundef %70)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  ret void
}

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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

declare noalias ptr @png_create_read_struct(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare noalias ptr @png_create_info_struct(ptr noundef) #2

declare void @png_init_io(ptr noundef, ptr noundef) #2

declare void @png_read_info(ptr noundef, ptr noundef) #2

declare i32 @png_get_image_width(ptr noundef, ptr noundef) #2

declare i32 @png_get_image_height(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

declare i64 @png_get_rowbytes(ptr noundef, ptr noundef) #2

declare void @png_read_row(ptr noundef, ptr noundef, ptr noundef) #2

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

declare void @png_read_end(ptr noundef, ptr noundef) #2

declare void @png_destroy_read_struct(ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @fclose(ptr noundef) #2

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 = { "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 #3 = { noreturn nounwind "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 #4 = { nounwind allocsize(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 #5 = { nounwind }
attributes #6 = { noreturn nounwind }
attributes #7 = { nounwind allocsize(0) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [75 x i8], align 1
@__PRETTY_FUNCTION__.px_read_png = external hidden unnamed_addr constant [69 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @px_read_png(ptr nocapture noundef readonly %0, ptr nocapture noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = tail call noalias ptr @fopen(ptr noundef %0, ptr noundef nonnull @.str)
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %8, label %9

8:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 12, ptr noundef nonnull @__PRETTY_FUNCTION__.px_read_png) #6
  unreachable

9:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #7
  %10 = tail call noalias ptr @png_create_read_struct(ptr noundef nonnull @.str.3, ptr noundef null, ptr noundef null, ptr noundef null) #7
  store ptr %10, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #7
  %11 = tail call noalias ptr @png_create_info_struct(ptr noundef %10) #7
  store ptr %11, ptr %6, align 8, !tbaa !5
  tail call void @png_init_io(ptr noundef %10, ptr noundef nonnull %7) #7
  tail call void @png_read_info(ptr noundef %10, ptr noundef %11) #7
  %12 = tail call i32 @png_get_image_width(ptr noundef %10, ptr noundef %11) #7
  %13 = zext i32 %12 to i64
  store i64 %13, ptr %2, align 8, !tbaa !9
  %14 = tail call i32 @png_get_image_height(ptr noundef %10, ptr noundef %11) #7
  %15 = zext i32 %14 to i64
  store i64 %15, ptr %3, align 8, !tbaa !9
  %16 = tail call i64 @png_get_rowbytes(ptr noundef %10, ptr noundef %11) #7
  %17 = mul i64 %16, %15
  %18 = add i64 %17, 128
  %19 = tail call noalias ptr @malloc(i64 noundef %18) #8
  store ptr %19, ptr %1, align 8, !tbaa !5
  %20 = load i64, ptr %3, align 8, !tbaa !9
  %.not15 = icmp eq i64 %20, 0
  br i1 %.not15, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %9
  tail call void @png_read_end(ptr noundef %10, ptr noundef %11) #7
  call void @png_destroy_read_struct(ptr noundef nonnull %5, ptr noundef nonnull %6, ptr noundef null) #7
  %21 = call i32 @fclose(ptr noundef nonnull %7)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #7
  ret void

.lr.ph:                                           ; preds = %9, %.lr.ph
  %22 = phi i64 [ %28, %.lr.ph ], [ 0, %9 ]
  %.014 = phi i32 [ %27, %.lr.ph ], [ 0, %9 ]
  %23 = load ptr, ptr %1, align 8, !tbaa !5
  %24 = tail call i64 @png_get_rowbytes(ptr noundef %10, ptr noundef %11) #7
  %25 = mul i64 %24, %22
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  tail call void @png_read_row(ptr noundef %10, ptr noundef %26, ptr noundef null) #7
  %27 = add i32 %.014, 1
  %28 = zext i32 %27 to i64
  %29 = load i64, ptr %3, align 8, !tbaa !9
  %30 = icmp ugt i64 %29, %28
  br i1 %30, label %.lr.ph, label %._crit_edge, !llvm.loop !11
}

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

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

declare noalias ptr @png_create_read_struct(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

declare noalias ptr @png_create_info_struct(ptr noundef) local_unnamed_addr #4

declare void @png_init_io(ptr noundef, ptr noundef) local_unnamed_addr #4

declare void @png_read_info(ptr noundef, ptr noundef) local_unnamed_addr #4

declare i32 @png_get_image_width(ptr noundef, ptr noundef) local_unnamed_addr #4

declare i32 @png_get_image_height(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #5

declare i64 @png_get_rowbytes(ptr noundef, ptr noundef) local_unnamed_addr #4

declare void @png_read_row(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

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

declare void @png_read_end(ptr noundef, ptr noundef) local_unnamed_addr #4

declare void @png_destroy_read_struct(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #2

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind "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 #3 = { noreturn nounwind "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 #4 = { "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 #5 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #6 = { noreturn nounwind }
attributes #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }

!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 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass