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

; 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_info_def = type { i32, i32, i32, i64, ptr, i16, i16, i8, i8, i8, i8, i8, i8, i8, i8, [8 x i8], %struct.png_colorspace, ptr, ptr, i32, i32, i32, ptr, %struct.png_time_struct, %struct.png_color_8_struct, ptr, %struct.png_color_16_struct, %struct.png_color_16_struct, i32, i32, i8, i32, i32, i8, ptr, ptr, i32, i32, ptr, ptr, i8, i8, i32, ptr, i32, ptr, i32, i8, ptr, ptr, ptr }
%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 }
%struct.png_time_struct = type { i16, i8, i8, i8, i8, i8 }
%struct.png_color_8_struct = type { i8, i8, i8, i8, i8 }
%struct.png_color_16_struct = type { i8, i16, i16, i16, i16 }

; Function Attrs: nounwind uwtable
define dso_local i32 @png_get_iCCP(ptr noalias noundef %0, ptr noalias noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #0 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %77

16:                                               ; preds = %6
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %77

19:                                               ; preds = %16
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.png_info_def, ptr %20, i32 0, i32 2
  %22 = load i32, ptr %21, align 8, !tbaa !9
  %23 = and i32 %22, 4096
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %77

25:                                               ; preds = %19
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %77

28:                                               ; preds = %25
  %29 = load ptr, ptr %11, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %77

31:                                               ; preds = %28
  %32 = load ptr, ptr %12, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %77

34:                                               ; preds = %31
  %35 = load ptr, ptr %13, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %77

37:                                               ; preds = %34
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.png_info_def, ptr %38, i32 0, i32 17
  %40 = load ptr, ptr %39, align 8, !tbaa !20
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %40, ptr %41, align 8, !tbaa !5
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.png_info_def, ptr %42, i32 0, i32 18
  %44 = load ptr, ptr %43, align 8, !tbaa !21
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %44, ptr %45, align 8, !tbaa !5
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.png_info_def, ptr %46, i32 0, i32 18
  %48 = load ptr, ptr %47, align 8, !tbaa !21
  %49 = load i8, ptr %48, align 1, !tbaa !22
  %50 = zext i8 %49 to i32
  %51 = shl i32 %50, 24
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.png_info_def, ptr %52, i32 0, i32 18
  %54 = load ptr, ptr %53, align 8, !tbaa !21
  %55 = getelementptr inbounds i8, ptr %54, i64 1
  %56 = load i8, ptr %55, align 1, !tbaa !22
  %57 = zext i8 %56 to i32
  %58 = shl i32 %57, 16
  %59 = add i32 %51, %58
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.png_info_def, ptr %60, i32 0, i32 18
  %62 = load ptr, ptr %61, align 8, !tbaa !21
  %63 = getelementptr inbounds i8, ptr %62, i64 2
  %64 = load i8, ptr %63, align 1, !tbaa !22
  %65 = zext i8 %64 to i32
  %66 = shl i32 %65, 8
  %67 = add i32 %59, %66
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.png_info_def, ptr %68, i32 0, i32 18
  %70 = load ptr, ptr %69, align 8, !tbaa !21
  %71 = getelementptr inbounds i8, ptr %70, i64 3
  %72 = load i8, ptr %71, align 1, !tbaa !22
  %73 = zext i8 %72 to i32
  %74 = add i32 %67, %73
  %75 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 %74, ptr %75, align 4, !tbaa !23
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 0, ptr %76, align 4, !tbaa !23
  store i32 4096, ptr %7, align 4
  br label %78

77:                                               ; preds = %34, %31, %28, %25, %19, %16, %6
  store i32 0, ptr %7, align 4
  br label %78

78:                                               ; preds = %77, %37
  %79 = load i32, ptr %7, align 4
  ret i32 %79
}

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

!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, !11, i64 8}
!10 = !{!"png_info_def", !11, i64 0, !11, i64 4, !11, i64 8, !12, i64 16, !6, i64 24, !13, i64 32, !13, i64 34, !7, i64 36, !7, i64 37, !7, i64 38, !7, i64 39, !7, i64 40, !7, i64 41, !7, i64 42, !7, i64 43, !7, i64 44, !14, i64 52, !6, i64 128, !6, i64 136, !11, i64 144, !11, i64 148, !11, i64 152, !6, i64 160, !17, i64 168, !18, i64 176, !6, i64 184, !19, i64 192, !19, i64 202, !11, i64 212, !11, i64 216, !7, i64 220, !11, i64 224, !11, i64 228, !7, i64 232, !6, i64 240, !6, i64 248, !11, i64 256, !11, i64 260, !6, i64 264, !6, i64 272, !7, i64 280, !7, i64 281, !11, i64 284, !6, i64 288, !11, i64 296, !6, i64 304, !11, i64 312, !7, i64 316, !6, i64 320, !6, i64 328, !6, i64 336}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!"png_colorspace", !11, i64 0, !15, i64 4, !16, i64 36, !13, i64 72, !13, i64 74}
!15 = !{!"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}
!16 = !{!"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}
!17 = !{!"png_time_struct", !13, i64 0, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6}
!18 = !{!"png_color_8_struct", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4}
!19 = !{!"png_color_16_struct", !7, i64 0, !13, i64 2, !13, i64 4, !13, i64 6, !13, i64 8}
!20 = !{!10, !6, i64 128}
!21 = !{!10, !6, i64 136}
!22 = !{!7, !7, i64 0}
!23 = !{!11, !11, i64 0}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 4097) i32 @png_get_iCCP(ptr noalias noundef readnone %0, ptr noalias noundef readonly %1, ptr noundef writeonly %2, ptr noundef writeonly %3, ptr noundef writeonly %4, ptr noundef writeonly %5) local_unnamed_addr #0 {
  %7 = icmp ne ptr %0, null
  %8 = icmp ne ptr %1, null
  %or.cond = and i1 %7, %8
  br i1 %or.cond, label %9, label %43

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !5
  %12 = and i32 %11, 4096
  %13 = icmp ne i32 %12, 0
  %14 = insertelement <4 x ptr> poison, ptr %2, i64 0
  %15 = insertelement <4 x ptr> %14, ptr %3, i64 1
  %16 = insertelement <4 x ptr> %15, ptr %4, i64 2
  %17 = insertelement <4 x ptr> %16, ptr %5, i64 3
  %18 = icmp eq <4 x ptr> %17, zeroinitializer
  %19 = bitcast <4 x i1> %18 to i4
  %20 = icmp eq i4 %19, 0
  %op.rdx = and i1 %20, %13
  br i1 %op.rdx, label %21, label %43

21:                                               ; preds = %9
  %22 = getelementptr inbounds i8, ptr %1, i64 128
  %23 = load ptr, ptr %22, align 8, !tbaa !19
  store ptr %23, ptr %2, align 8, !tbaa !20
  %24 = getelementptr inbounds i8, ptr %1, i64 136
  %25 = load ptr, ptr %24, align 8, !tbaa !21
  store ptr %25, ptr %4, align 8, !tbaa !20
  %26 = load i8, ptr %25, align 1, !tbaa !22
  %27 = zext i8 %26 to i32
  %28 = shl nuw i32 %27, 24
  %29 = getelementptr inbounds i8, ptr %25, i64 1
  %30 = load i8, ptr %29, align 1, !tbaa !22
  %31 = zext i8 %30 to i32
  %32 = shl nuw nsw i32 %31, 16
  %33 = or disjoint i32 %32, %28
  %34 = getelementptr inbounds i8, ptr %25, i64 2
  %35 = load i8, ptr %34, align 1, !tbaa !22
  %36 = zext i8 %35 to i32
  %37 = shl nuw nsw i32 %36, 8
  %38 = or disjoint i32 %33, %37
  %39 = getelementptr inbounds i8, ptr %25, i64 3
  %40 = load i8, ptr %39, align 1, !tbaa !22
  %41 = zext i8 %40 to i32
  %42 = or disjoint i32 %38, %41
  store i32 %42, ptr %5, align 4, !tbaa !23
  store i32 0, ptr %3, align 4, !tbaa !23
  br label %43

43:                                               ; preds = %6, %9, %21
  %.0 = phi i32 [ 4096, %21 ], [ 0, %9 ], [ 0, %6 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: 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, !7, i64 8}
!6 = !{!"png_info_def", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !11, i64 24, !12, i64 32, !12, i64 34, !8, i64 36, !8, i64 37, !8, i64 38, !8, i64 39, !8, i64 40, !8, i64 41, !8, i64 42, !8, i64 43, !8, i64 44, !13, i64 52, !11, i64 128, !11, i64 136, !7, i64 144, !7, i64 148, !7, i64 152, !11, i64 160, !16, i64 168, !17, i64 176, !11, i64 184, !18, i64 192, !18, i64 202, !7, i64 212, !7, i64 216, !8, i64 220, !7, i64 224, !7, i64 228, !8, i64 232, !11, i64 240, !11, i64 248, !7, i64 256, !7, i64 260, !11, i64 264, !11, i64 272, !8, i64 280, !8, i64 281, !7, i64 284, !11, i64 288, !7, i64 296, !11, i64 304, !7, i64 312, !8, i64 316, !11, i64 320, !11, i64 328, !11, i64 336}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!"png_colorspace", !7, i64 0, !14, i64 4, !15, i64 36, !12, i64 72, !12, i64 74}
!14 = !{!"png_xy", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28}
!15 = !{!"png_XYZ", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32}
!16 = !{!"png_time_struct", !12, i64 0, !8, i64 2, !8, i64 3, !8, i64 4, !8, i64 5, !8, i64 6}
!17 = !{!"png_color_8_struct", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4}
!18 = !{!"png_color_16_struct", !8, i64 0, !12, i64 2, !12, i64 4, !12, i64 6, !12, i64 8}
!19 = !{!6, !11, i64 128}
!20 = !{!11, !11, i64 0}
!21 = !{!6, !11, i64 136}
!22 = !{!8, !8, i64 0}
!23 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass