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

; 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_XYZ = type { i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.png_xy = type { i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.png_colorspace = type { i32, %struct.png_xy, %struct.png_XYZ, i16, i16 }

@png_colorspace_set_sRGB.sRGB_XYZ = external hidden constant %struct.png_XYZ, align 4
@.str.25 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [35 x i8], align 1
@sRGB_xy = external hidden constant %struct.png_xy, align 4
@.str.29 = external hidden unnamed_addr constant [31 x i8], align 1

; 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) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @png_colorspace_check_gamma(ptr noalias noundef, ptr noalias noundef, i32 noundef, i32 noundef) #1

declare void @png_chunk_report(ptr noundef, ptr noundef, i32 noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @png_colorspace_set_sRGB(ptr noalias noundef %0, ptr noalias noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %8 = load ptr, ptr %6, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.png_colorspace, ptr %8, i32 0, i32 4
  %10 = load i16, ptr %9, align 2, !tbaa !11
  %11 = zext i16 %10 to i32
  %12 = and i32 %11, 32768
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  br label %108

15:                                               ; preds = %3
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %21, label %18

18:                                               ; preds = %15
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = icmp sge i32 %19, 4
  br i1 %20, label %21, label %27

21:                                               ; preds = %18, %15
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = call i32 @png_icc_profile_error(ptr noundef %22, ptr noundef %23, ptr noundef @.str.25, i64 noundef %25, ptr noundef @.str.26)
  store i32 %26, ptr %4, align 4
  br label %108

27:                                               ; preds = %18
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.png_colorspace, ptr %28, i32 0, i32 4
  %30 = load i16, ptr %29, align 2, !tbaa !11
  %31 = zext i16 %30 to i32
  %32 = and i32 %31, 4
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %47

34:                                               ; preds = %27
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.png_colorspace, ptr %35, i32 0, i32 3
  %37 = load i16, ptr %36, align 4, !tbaa !16
  %38 = zext i16 %37 to i32
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = icmp ne i32 %38, %39
  br i1 %40, label %41, label %47

41:                                               ; preds = %34
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = call i32 @png_icc_profile_error(ptr noundef %42, ptr noundef %43, ptr noundef @.str.25, i64 noundef %45, ptr noundef @.str.27)
  store i32 %46, ptr %4, align 4
  br label %108

47:                                               ; preds = %34, %27
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.png_colorspace, ptr %48, i32 0, i32 4
  %50 = load i16, ptr %49, align 2, !tbaa !11
  %51 = zext i16 %50 to i32
  %52 = and i32 %51, 32
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %56

54:                                               ; preds = %47
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_benign_error(ptr noundef %55, ptr noundef @.str.28)
  store i32 0, ptr %4, align 4
  br label %108

56:                                               ; preds = %47
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.png_colorspace, ptr %57, i32 0, i32 4
  %59 = load i16, ptr %58, align 2, !tbaa !11
  %60 = zext i16 %59 to i32
  %61 = and i32 %60, 2
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %70

63:                                               ; preds = %56
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.png_colorspace, ptr %64, i32 0, i32 1
  %66 = call i32 @png_colorspace_endpoints_match(ptr noundef @sRGB_xy, ptr noundef %65, i32 noundef 100)
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %70, label %68

68:                                               ; preds = %63
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  call void @png_chunk_report(ptr noundef %69, ptr noundef @.str.29, i32 noundef 2)
  br label %70

70:                                               ; preds = %68, %63, %56
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = call i32 @png_colorspace_check_gamma(ptr noundef %71, ptr noundef %72, i32 noundef 45455, i32 noundef 2)
  %74 = load i32, ptr %7, align 4, !tbaa !9
  %75 = trunc i32 %74 to i16
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.png_colorspace, ptr %76, i32 0, i32 3
  store i16 %75, ptr %77, align 4, !tbaa !16
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.png_colorspace, ptr %78, i32 0, i32 4
  %80 = load i16, ptr %79, align 2, !tbaa !11
  %81 = zext i16 %80 to i32
  %82 = or i32 %81, 4
  %83 = trunc i32 %82 to i16
  store i16 %83, ptr %79, align 2, !tbaa !11
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.png_colorspace, ptr %84, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %85, ptr align 4 @sRGB_xy, i64 32, i1 false), !tbaa.struct !17
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.png_colorspace, ptr %86, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %87, ptr align 4 @png_colorspace_set_sRGB.sRGB_XYZ, i64 36, i1 false), !tbaa.struct !18
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.png_colorspace, ptr %88, i32 0, i32 4
  %90 = load i16, ptr %89, align 2, !tbaa !11
  %91 = zext i16 %90 to i32
  %92 = or i32 %91, 66
  %93 = trunc i32 %92 to i16
  store i16 %93, ptr %89, align 2, !tbaa !11
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.png_colorspace, ptr %94, i32 0, i32 0
  store i32 45455, ptr %95, align 4, !tbaa !19
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.png_colorspace, ptr %96, i32 0, i32 4
  %98 = load i16, ptr %97, align 2, !tbaa !11
  %99 = zext i16 %98 to i32
  %100 = or i32 %99, 1
  %101 = trunc i32 %100 to i16
  store i16 %101, ptr %97, align 2, !tbaa !11
  %102 = load ptr, ptr %6, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.png_colorspace, ptr %102, i32 0, i32 4
  %104 = load i16, ptr %103, align 2, !tbaa !11
  %105 = zext i16 %104 to i32
  %106 = or i32 %105, 160
  %107 = trunc i32 %106 to i16
  store i16 %107, ptr %103, align 2, !tbaa !11
  store i32 1, ptr %4, align 4
  br label %108

108:                                              ; preds = %70, %54, %41, %21, %14
  %109 = load i32, ptr %4, align 4
  ret i32 %109
}

; Function Attrs: nounwind uwtable
declare hidden i32 @png_icc_profile_error(ptr noalias noundef, ptr noalias noundef, ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @png_colorspace_endpoints_match(ptr noundef, ptr noundef, i32 noundef) #1

attributes #0 = { nocallback nofree 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 = { "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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !15, i64 74}
!12 = !{!"png_colorspace", !10, i64 0, !13, i64 4, !14, i64 36, !15, i64 72, !15, i64 74}
!13 = !{!"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}
!14 = !{!"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}
!15 = !{!"short", !7, i64 0}
!16 = !{!12, !15, i64 72}
!17 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9, i64 12, i64 4, !9, i64 16, i64 4, !9, i64 20, i64 4, !9, i64 24, i64 4, !9, i64 28, i64 4, !9}
!18 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9, i64 12, i64 4, !9, i64 16, i64 4, !9, i64 20, i64 4, !9, i64 24, i64 4, !9, i64 28, i64 4, !9, i64 32, i64 4, !9}
!19 = !{!12, !10, 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"

%struct.png_XYZ = type { i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.png_xy = type { i32, i32, i32, i32, i32, i32, i32, i32 }

@png_colorspace_set_sRGB.sRGB_XYZ = external hidden local_unnamed_addr constant %struct.png_XYZ, align 4
@.str.25 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [35 x i8], align 1
@sRGB_xy = external hidden constant %struct.png_xy, align 4
@.str.29 = external hidden unnamed_addr constant [31 x i8], align 1

; 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) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @png_colorspace_check_gamma(ptr noalias noundef, ptr noalias noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @png_chunk_report(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @png_benign_error(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @png_colorspace_set_sRGB(ptr noalias noundef %0, ptr noalias noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %1, i64 74
  %5 = load i16, ptr %4, align 2, !tbaa !5
  %.not = icmp sgt i16 %5, -1
  br i1 %.not, label %6, label %37

6:                                                ; preds = %3
  %or.cond = icmp ugt i32 %2, 3
  br i1 %or.cond, label %7, label %10

7:                                                ; preds = %6
  %8 = sext i32 %2 to i64
  %9 = tail call i32 @png_icc_profile_error(ptr noundef %0, ptr noundef nonnull %1, ptr noundef nonnull @.str.25, i64 noundef %8, ptr noundef nonnull @.str.26)
  br label %37

10:                                               ; preds = %6
  %11 = and i16 %5, 4
  %.not30 = icmp eq i16 %11, 0
  br i1 %.not30, label %19, label %12

12:                                               ; preds = %10
  %13 = getelementptr inbounds i8, ptr %1, i64 72
  %14 = load i16, ptr %13, align 4, !tbaa !13
  %15 = zext i16 %14 to i32
  %.not31 = icmp eq i32 %15, %2
  br i1 %.not31, label %19, label %16

16:                                               ; preds = %12
  %17 = zext nneg i32 %2 to i64
  %18 = tail call i32 @png_icc_profile_error(ptr noundef %0, ptr noundef nonnull %1, ptr noundef nonnull @.str.25, i64 noundef %17, ptr noundef nonnull @.str.27)
  br label %37

19:                                               ; preds = %12, %10
  %20 = zext nneg i16 %5 to i32
  %21 = and i32 %20, 32
  %.not32 = icmp eq i32 %21, 0
  br i1 %.not32, label %23, label %22

22:                                               ; preds = %19
  tail call void @png_benign_error(ptr noundef %0, ptr noundef nonnull @.str.28) #3
  br label %37

23:                                               ; preds = %19
  %24 = and i32 %20, 2
  %.not33 = icmp eq i32 %24, 0
  br i1 %.not33, label %29, label %25

25:                                               ; preds = %23
  %26 = getelementptr inbounds i8, ptr %1, i64 4
  %27 = tail call i32 @png_colorspace_endpoints_match(ptr noundef nonnull @sRGB_xy, ptr noundef nonnull %26, i32 noundef 100)
  %.not34 = icmp eq i32 %27, 0
  br i1 %.not34, label %28, label %29

28:                                               ; preds = %25
  tail call void @png_chunk_report(ptr noundef %0, ptr noundef nonnull @.str.29, i32 noundef 2) #3
  br label %29

29:                                               ; preds = %28, %25, %23
  %30 = tail call i32 @png_colorspace_check_gamma(ptr noundef %0, ptr noundef nonnull %1, i32 noundef 45455, i32 noundef 2)
  %31 = trunc nuw nsw i32 %2 to i16
  %32 = getelementptr inbounds i8, ptr %1, i64 72
  store i16 %31, ptr %32, align 4, !tbaa !13
  %33 = load i16, ptr %4, align 2, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %1, i64 4
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(32) %34, ptr noundef nonnull align 4 dereferenceable(32) @sRGB_xy, i64 32, i1 false), !tbaa.struct !14
  %35 = getelementptr inbounds i8, ptr %1, i64 36
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %35, ptr noundef nonnull align 4 dereferenceable(36) @png_colorspace_set_sRGB.sRGB_XYZ, i64 36, i1 false), !tbaa.struct !16
  store i32 45455, ptr %1, align 4, !tbaa !17
  %36 = or i16 %33, 231
  store i16 %36, ptr %4, align 2, !tbaa !5
  br label %37

37:                                               ; preds = %3, %29, %22, %16, %7
  %.0 = phi i32 [ %9, %7 ], [ %18, %16 ], [ 0, %22 ], [ 1, %29 ], [ 0, %3 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @png_icc_profile_error(ptr noalias noundef, ptr noalias noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @png_colorspace_endpoints_match(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree 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 = { "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 }

!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, !12, i64 74}
!6 = !{!"png_colorspace", !7, i64 0, !10, i64 4, !11, i64 36, !12, i64 72, !12, i64 74}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"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}
!11 = !{!"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}
!12 = !{!"short", !8, i64 0}
!13 = !{!6, !12, i64 72}
!14 = !{i64 0, i64 4, !15, i64 4, i64 4, !15, i64 8, i64 4, !15, i64 12, i64 4, !15, i64 16, i64 4, !15, i64 20, i64 4, !15, i64 24, i64 4, !15, i64 28, i64 4, !15}
!15 = !{!7, !7, i64 0}
!16 = !{i64 0, i64 4, !15, i64 4, i64 4, !15, i64 8, i64 4, !15, i64 12, i64 4, !15, i64 16, i64 4, !15, i64 20, i64 4, !15, i64 24, i64 4, !15, i64 28, i64 4, !15, i64 32, i64 4, !15}
!17 = !{!6, !7, i64 0}


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