; LLVM IR from EyalAr/lwip :: src/lib/png (pngrutil)

; 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_struct_def = type { [1 x %struct.__jmp_buf_tag], ptr, ptr, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i8, i8, i32, i32, i32, i32, %struct.z_stream_s, i32, i32, i32, i32, i64, i32, i32, i32, ptr, ptr, i64, i32, i32, ptr, i16, i32, i16, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i16, i8, i32, %struct.png_color_16_struct, %struct.png_color_16_struct, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, %struct.png_color_8_struct, %struct.png_color_8_struct, ptr, %struct.png_color_16_struct, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i64, i64, i64, i64, i32, i32, ptr, ptr, i8, [29 x i8], i32, ptr, ptr, i32, i32, ptr, i8, i8, i16, i16, i32, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i8, i32, i32, i32, i64, %struct.png_unknown_chunk_t, i64, ptr, i64, i32, i32, ptr, [4 x ptr], %struct.png_colorspace }
%struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }
%struct.z_stream_s = type { ptr, i32, i64, ptr, i32, i64, ptr, ptr, ptr, ptr, ptr, i32, i64, i64 }
%struct.png_color_8_struct = type { i8, i8, i8, i8, i8 }
%struct.png_color_16_struct = type { i8, i16, i16, i16, i16 }
%struct.png_unknown_chunk_t = type { [5 x i8], ptr, i64, i8 }
%struct.png_colorspace = type { i32, %struct.png_xy, %struct.png_XYZ, i16, i16 }
%struct.png_xy = type { i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.png_XYZ = type { i32, i32, i32, i32, i32, i32, i32, i32, i32 }

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

; 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
declare dso_local void @png_crc_read(ptr noalias noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @png_crc_finish(ptr noalias noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca [1024 x i8], align 16
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %17, %2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp ugt i32 %9, 0
  br i1 %10, label %11, label %24

11:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 1024, ptr %7) #3
  store i32 1024, ptr %6, align 4, !tbaa !9
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp ugt i32 %12, %13
  br i1 %14, label %15, label %17

15:                                               ; preds = %11
  %16 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %16, ptr %6, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %15, %11
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = sub i32 %19, %18
  store i32 %20, ptr %5, align 4, !tbaa !9
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds [1024 x i8], ptr %7, i64 0, i64 0
  %23 = load i32, ptr %6, align 4, !tbaa !9
  call void @png_crc_read(ptr noundef %21, ptr noundef %22, i32 noundef %23)
  call void @llvm.lifetime.end.p0(i64 1024, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %8, !llvm.loop !11

24:                                               ; preds = %8
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = call i32 @png_crc_error(ptr noundef %25)
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %52

28:                                               ; preds = %24
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.png_struct_def, ptr %29, i32 0, i32 25
  %31 = load i32, ptr %30, align 8, !tbaa !13
  %32 = lshr i32 %31, 29
  %33 = and i32 1, %32
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %41

35:                                               ; preds = %28
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.png_struct_def, ptr %36, i32 0, i32 14
  %38 = load i32, ptr %37, align 8, !tbaa !24
  %39 = and i32 %38, 512
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %47, label %49

41:                                               ; preds = %28
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.png_struct_def, ptr %42, i32 0, i32 14
  %44 = load i32, ptr %43, align 8, !tbaa !24
  %45 = and i32 %44, 1024
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %49

47:                                               ; preds = %41, %35
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  br label %51

49:                                               ; preds = %41, %35
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  call void @png_chunk_error(ptr noundef %50, ptr noundef @.str.3) #4
  unreachable

51:                                               ; preds = %47
  store i32 1, ptr %3, align 4
  br label %53

52:                                               ; preds = %24
  store i32 0, ptr %3, align 4
  br label %53

53:                                               ; preds = %52, %51
  %54 = load i32, ptr %3, align 4
  ret i32 %54
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @png_crc_error(ptr noalias noundef) #1

; Function Attrs: noreturn
declare void @png_chunk_error(ptr noundef, ptr noundef) #2

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 = { noreturn "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 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 448}
!14 = !{!"png_struct_def", !7, i64 0, !6, i64 200, !6, i64 208, !15, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !7, i64 280, !7, i64 281, !10, i64 284, !10, i64 288, !10, i64 292, !10, i64 296, !16, i64 304, !10, i64 416, !10, i64 420, !10, i64 424, !10, i64 428, !15, i64 432, !10, i64 440, !10, i64 444, !10, i64 448, !6, i64 456, !6, i64 464, !15, i64 472, !10, i64 480, !10, i64 484, !6, i64 488, !17, i64 496, !10, i64 500, !17, i64 504, !7, i64 506, !7, i64 507, !7, i64 508, !7, i64 509, !7, i64 510, !7, i64 511, !7, i64 512, !7, i64 513, !7, i64 514, !7, i64 515, !7, i64 516, !7, i64 517, !7, i64 518, !17, i64 520, !7, i64 522, !10, i64 524, !18, i64 528, !18, i64 538, !10, i64 548, !10, i64 552, !6, i64 560, !6, i64 568, !6, i64 576, !6, i64 584, !6, i64 592, !6, i64 600, !19, i64 608, !19, i64 613, !6, i64 624, !18, i64 632, !6, i64 648, !6, i64 656, !6, i64 664, !6, i64 672, !6, i64 680, !6, i64 688, !6, i64 696, !6, i64 704, !6, i64 712, !10, i64 720, !10, i64 724, !15, i64 728, !15, i64 736, !15, i64 744, !15, i64 752, !10, i64 760, !10, i64 764, !6, i64 768, !6, i64 776, !7, i64 784, !7, i64 785, !10, i64 816, !6, i64 824, !6, i64 832, !10, i64 840, !10, i64 844, !6, i64 848, !7, i64 856, !7, i64 857, !17, i64 858, !17, i64 860, !10, i64 864, !7, i64 868, !6, i64 872, !6, i64 880, !6, i64 888, !6, i64 896, !6, i64 904, !6, i64 912, !6, i64 920, !7, i64 928, !10, i64 932, !10, i64 936, !10, i64 940, !15, i64 944, !20, i64 952, !15, i64 984, !6, i64 992, !15, i64 1000, !10, i64 1008, !10, i64 1012, !6, i64 1016, !7, i64 1024, !21, i64 1056}
!15 = !{!"long", !7, i64 0}
!16 = !{!"z_stream_s", !6, i64 0, !10, i64 8, !15, i64 16, !6, i64 24, !10, i64 32, !15, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !10, i64 88, !15, i64 96, !15, i64 104}
!17 = !{!"short", !7, i64 0}
!18 = !{!"png_color_16_struct", !7, i64 0, !17, i64 2, !17, i64 4, !17, i64 6, !17, i64 8}
!19 = !{!"png_color_8_struct", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4}
!20 = !{!"png_unknown_chunk_t", !7, i64 0, !6, i64 8, !15, i64 16, !7, i64 24}
!21 = !{!"png_colorspace", !10, i64 0, !22, i64 4, !23, i64 36, !17, i64 72, !17, i64 74}
!22 = !{!"png_xy", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!23 = !{!"png_XYZ", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32}
!24 = !{!14, !10, i64 288}


; 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.3 = external hidden unnamed_addr constant [10 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @png_crc_read(ptr noalias noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @png_crc_finish(ptr noalias noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = alloca [1024 x i8], align 16
  %.not19 = icmp eq i32 %1, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.01420 = phi i32 [ %4, %.lr.ph ], [ %1, %2 ]
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %3) #4
  %spec.select = call i32 @llvm.umin.i32(i32 %.01420, i32 1024)
  %4 = sub i32 %.01420, %spec.select
  call void @png_crc_read(ptr noundef %0, ptr noundef nonnull %3, i32 noundef %spec.select)
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %3) #4
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %2
  %5 = call i32 @png_crc_error(ptr noundef %0)
  %.not16 = icmp eq i32 %5, 0
  br i1 %.not16, label %18, label %6

6:                                                ; preds = %._crit_edge
  %7 = getelementptr inbounds i8, ptr %0, i64 448
  %8 = load i32, ptr %7, align 8, !tbaa !7
  %9 = and i32 %8, 536870912
  %.not17 = icmp eq i32 %9, 0
  %10 = getelementptr inbounds i8, ptr %0, i64 288
  %11 = load i32, ptr %10, align 8, !tbaa !22
  br i1 %.not17, label %15, label %12

12:                                               ; preds = %6
  %13 = and i32 %11, 512
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %18, label %17

15:                                               ; preds = %6
  %16 = and i32 %11, 1024
  %.not18 = icmp eq i32 %16, 0
  br i1 %.not18, label %17, label %18

17:                                               ; preds = %15, %12
  call void @png_chunk_error(ptr noundef nonnull %0, ptr noundef nonnull @.str.3) #5
  unreachable

18:                                               ; preds = %._crit_edge, %12, %15
  %.015 = phi i32 [ 1, %15 ], [ 1, %12 ], [ 0, %._crit_edge ]
  ret i32 %.015
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @png_crc_error(ptr noalias noundef) local_unnamed_addr #1

; Function Attrs: noreturn
declare void @png_chunk_error(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #3

attributes #0 = { mustprogress 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 = { noreturn "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind }
attributes #5 = { noreturn 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !13, i64 448}
!8 = !{!"png_struct_def", !9, i64 0, !11, i64 200, !11, i64 208, !12, i64 216, !11, i64 224, !11, i64 232, !11, i64 240, !11, i64 248, !11, i64 256, !11, i64 264, !11, i64 272, !9, i64 280, !9, i64 281, !13, i64 284, !13, i64 288, !13, i64 292, !13, i64 296, !14, i64 304, !13, i64 416, !13, i64 420, !13, i64 424, !13, i64 428, !12, i64 432, !13, i64 440, !13, i64 444, !13, i64 448, !11, i64 456, !11, i64 464, !12, i64 472, !13, i64 480, !13, i64 484, !11, i64 488, !15, i64 496, !13, i64 500, !15, i64 504, !9, i64 506, !9, i64 507, !9, i64 508, !9, i64 509, !9, i64 510, !9, i64 511, !9, i64 512, !9, i64 513, !9, i64 514, !9, i64 515, !9, i64 516, !9, i64 517, !9, i64 518, !15, i64 520, !9, i64 522, !13, i64 524, !16, i64 528, !16, i64 538, !13, i64 548, !13, i64 552, !11, i64 560, !11, i64 568, !11, i64 576, !11, i64 584, !11, i64 592, !11, i64 600, !17, i64 608, !17, i64 613, !11, i64 624, !16, i64 632, !11, i64 648, !11, i64 656, !11, i64 664, !11, i64 672, !11, i64 680, !11, i64 688, !11, i64 696, !11, i64 704, !11, i64 712, !13, i64 720, !13, i64 724, !12, i64 728, !12, i64 736, !12, i64 744, !12, i64 752, !13, i64 760, !13, i64 764, !11, i64 768, !11, i64 776, !9, i64 784, !9, i64 785, !13, i64 816, !11, i64 824, !11, i64 832, !13, i64 840, !13, i64 844, !11, i64 848, !9, i64 856, !9, i64 857, !15, i64 858, !15, i64 860, !13, i64 864, !9, i64 868, !11, i64 872, !11, i64 880, !11, i64 888, !11, i64 896, !11, i64 904, !11, i64 912, !11, i64 920, !9, i64 928, !13, i64 932, !13, i64 936, !13, i64 940, !12, i64 944, !18, i64 952, !12, i64 984, !11, i64 992, !12, i64 1000, !13, i64 1008, !13, i64 1012, !11, i64 1016, !9, i64 1024, !19, i64 1056}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"long", !9, i64 0}
!13 = !{!"int", !9, i64 0}
!14 = !{!"z_stream_s", !11, i64 0, !13, i64 8, !12, i64 16, !11, i64 24, !13, i64 32, !12, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !13, i64 88, !12, i64 96, !12, i64 104}
!15 = !{!"short", !9, i64 0}
!16 = !{!"png_color_16_struct", !9, i64 0, !15, i64 2, !15, i64 4, !15, i64 6, !15, i64 8}
!17 = !{!"png_color_8_struct", !9, i64 0, !9, i64 1, !9, i64 2, !9, i64 3, !9, i64 4}
!18 = !{!"png_unknown_chunk_t", !9, i64 0, !11, i64 8, !12, i64 16, !9, i64 24}
!19 = !{!"png_colorspace", !13, i64 0, !20, i64 4, !21, i64 36, !15, i64 72, !15, i64 74}
!20 = !{!"png_xy", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28}
!21 = !{!"png_XYZ", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32}
!22 = !{!8, !13, i64 288}


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