; LLVM IR from EyalAr/lwip :: src/lib/png (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"

%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.1 = external hidden unnamed_addr constant [31 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @png_set_longjmp_fn(ptr noalias noundef %0, ptr noundef %1, i64 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  br label %77

13:                                               ; preds = %3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.png_struct_def, ptr %14, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %44

18:                                               ; preds = %13
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.png_struct_def, ptr %19, i32 0, i32 3
  store i64 0, ptr %20, align 8, !tbaa !22
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = icmp ule i64 %21, 200
  br i1 %22, label %23, label %28

23:                                               ; preds = %18
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.png_struct_def, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.png_struct_def, ptr %26, i32 0, i32 2
  store ptr %25, ptr %27, align 8, !tbaa !11
  br label %43

28:                                               ; preds = %18
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load i64, ptr %7, align 8, !tbaa !9
  %31 = call noalias ptr @png_malloc_warn(ptr noundef %29, i64 noundef %30)
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.png_struct_def, ptr %32, i32 0, i32 2
  store ptr %31, ptr %33, align 8, !tbaa !11
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.png_struct_def, ptr %34, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %39

38:                                               ; preds = %28
  store ptr null, ptr %4, align 8
  br label %77

39:                                               ; preds = %28
  %40 = load i64, ptr %7, align 8, !tbaa !9
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.png_struct_def, ptr %41, i32 0, i32 3
  store i64 %40, ptr %42, align 8, !tbaa !22
  br label %43

43:                                               ; preds = %39, %23
  br label %70

44:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.png_struct_def, ptr %45, i32 0, i32 3
  %47 = load i64, ptr %46, align 8, !tbaa !22
  store i64 %47, ptr %8, align 8, !tbaa !9
  %48 = load i64, ptr %8, align 8, !tbaa !9
  %49 = icmp eq i64 %48, 0
  br i1 %49, label %50, label %60

50:                                               ; preds = %44
  store i64 200, ptr %8, align 8, !tbaa !9
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.png_struct_def, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.png_struct_def, ptr %54, i32 0, i32 0
  %56 = icmp ne ptr %53, %55
  br i1 %56, label %57, label %59

57:                                               ; preds = %50
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_error(ptr noundef %58, ptr noundef @.str.1) #5
  unreachable

59:                                               ; preds = %50
  br label %60

60:                                               ; preds = %59, %44
  %61 = load i64, ptr %8, align 8, !tbaa !9
  %62 = load i64, ptr %7, align 8, !tbaa !9
  %63 = icmp ne i64 %61, %62
  br i1 %63, label %64, label %66

64:                                               ; preds = %60
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %67

66:                                               ; preds = %60
  store i32 0, ptr %9, align 4
  br label %67

67:                                               ; preds = %66, %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %68 = load i32, ptr %9, align 4
  switch i32 %68, label %79 [
    i32 0, label %69
    i32 1, label %77
  ]

69:                                               ; preds = %67
  br label %70

70:                                               ; preds = %69, %43
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.png_struct_def, ptr %72, i32 0, i32 1
  store ptr %71, ptr %73, align 8, !tbaa !23
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.png_struct_def, ptr %74, i32 0, i32 2
  %76 = load ptr, ptr %75, align 8, !tbaa !11
  store ptr %76, ptr %4, align 8
  br label %77

77:                                               ; preds = %70, %67, %38, %12
  %78 = load ptr, ptr %4, align 8
  ret ptr %78

79:                                               ; preds = %67
  unreachable
}

declare noalias ptr @png_malloc_warn(ptr noundef, i64 noundef) #3

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 = { 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 #3 = { "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 }
attributes #5 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 208}
!12 = !{!"png_struct_def", !7, i64 0, !6, i64 200, !6, i64 208, !10, 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, !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, !10, i64 432, !13, i64 440, !13, i64 444, !13, i64 448, !6, i64 456, !6, i64 464, !10, i64 472, !13, i64 480, !13, i64 484, !6, i64 488, !15, i64 496, !13, i64 500, !15, 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, !15, i64 520, !7, i64 522, !13, i64 524, !16, i64 528, !16, i64 538, !13, i64 548, !13, i64 552, !6, i64 560, !6, i64 568, !6, i64 576, !6, i64 584, !6, i64 592, !6, i64 600, !17, i64 608, !17, i64 613, !6, i64 624, !16, 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, !13, i64 720, !13, i64 724, !10, i64 728, !10, i64 736, !10, i64 744, !10, i64 752, !13, i64 760, !13, i64 764, !6, i64 768, !6, i64 776, !7, i64 784, !7, i64 785, !13, i64 816, !6, i64 824, !6, i64 832, !13, i64 840, !13, i64 844, !6, i64 848, !7, i64 856, !7, i64 857, !15, i64 858, !15, i64 860, !13, 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, !13, i64 932, !13, i64 936, !13, i64 940, !10, i64 944, !18, i64 952, !10, i64 984, !6, i64 992, !10, i64 1000, !13, i64 1008, !13, i64 1012, !6, i64 1016, !7, i64 1024, !19, i64 1056}
!13 = !{!"int", !7, i64 0}
!14 = !{!"z_stream_s", !6, i64 0, !13, i64 8, !10, i64 16, !6, i64 24, !13, i64 32, !10, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !13, i64 88, !10, i64 96, !10, i64 104}
!15 = !{!"short", !7, i64 0}
!16 = !{!"png_color_16_struct", !7, i64 0, !15, i64 2, !15, i64 4, !15, i64 6, !15, i64 8}
!17 = !{!"png_color_8_struct", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4}
!18 = !{!"png_unknown_chunk_t", !7, i64 0, !6, i64 8, !10, i64 16, !7, 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 = !{!12, !10, i64 216}
!23 = !{!12, !6, i64 200}


; 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.1 = external hidden unnamed_addr constant [31 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: nounwind uwtable
define dso_local ptr @png_set_longjmp_fn(ptr noalias noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %26, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 208
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  %9 = getelementptr inbounds i8, ptr %0, i64 216
  br i1 %8, label %10, label %17

10:                                               ; preds = %5
  store i64 0, ptr %9, align 8, !tbaa !20
  %11 = icmp ult i64 %2, 201
  br i1 %11, label %12, label %13

12:                                               ; preds = %10
  store ptr %0, ptr %6, align 8, !tbaa !5
  br label %23

13:                                               ; preds = %10
  %14 = tail call noalias ptr @png_malloc_warn(ptr noundef nonnull %0, i64 noundef %2) #3
  store ptr %14, ptr %6, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %26, label %16

16:                                               ; preds = %13
  store i64 %2, ptr %9, align 8, !tbaa !20
  br label %23

17:                                               ; preds = %5
  %18 = load i64, ptr %9, align 8, !tbaa !20
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %17
  %.not = icmp eq ptr %7, %0
  br i1 %.not, label %22, label %21

21:                                               ; preds = %20
  tail call void @png_error(ptr noundef nonnull %0, ptr noundef nonnull @.str.1) #4
  unreachable

22:                                               ; preds = %20, %17
  %.024 = phi i64 [ 200, %20 ], [ %18, %17 ]
  %.not30.not = icmp eq i64 %.024, %2
  br i1 %.not30.not, label %23, label %26

23:                                               ; preds = %22, %12, %16
  %24 = phi ptr [ %7, %22 ], [ %0, %12 ], [ %14, %16 ]
  %25 = getelementptr inbounds i8, ptr %0, i64 200
  store ptr %1, ptr %25, align 8, !tbaa !21
  br label %26

26:                                               ; preds = %22, %13, %3, %23
  %.1 = phi ptr [ %24, %23 ], [ null, %22 ], [ null, %3 ], [ null, %13 ]
  ret ptr %.1
}

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass