; LLVM IR from rdguez-mariano/fast_imas_IPOL :: io_png/libs/png (pngwutil)

; 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.compression_state = type { ptr, i32, i32, i32, ptr }

@.str.18 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [50 x i8], align 1
@png_iCCP = external global [5 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_write_chunk_start(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @png_write_chunk_data(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @png_write_chunk_end(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @png_write_iCCP(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca %struct.compression_state, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %14, align 4, !tbaa !9
  %16 = getelementptr inbounds %struct.compression_state, ptr %13, i32 0, i32 2
  store i32 0, ptr %16, align 4, !tbaa !11
  %17 = getelementptr inbounds %struct.compression_state, ptr %13, i32 0, i32 3
  store i32 0, ptr %17, align 8, !tbaa !13
  %18 = getelementptr inbounds %struct.compression_state, ptr %13, i32 0, i32 4
  store ptr null, ptr %18, align 8, !tbaa !14
  %19 = getelementptr inbounds %struct.compression_state, ptr %13, i32 0, i32 0
  store ptr null, ptr %19, align 8, !tbaa !15
  %20 = getelementptr inbounds %struct.compression_state, ptr %13, i32 0, i32 1
  store i32 0, ptr %20, align 8, !tbaa !16
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = call i64 @png_check_keyword(ptr noundef %21, ptr noundef %22, ptr noundef %12)
  store i64 %23, ptr %11, align 8, !tbaa !17
  %24 = icmp eq i64 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %5
  store i32 1, ptr %15, align 4
  br label %107

26:                                               ; preds = %5
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %26
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  call void @png_warning(ptr noundef %30, ptr noundef @.str.18)
  br label %31

31:                                               ; preds = %29, %26
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = icmp eq ptr %32, null
  br i1 %33, label %34, label %35

34:                                               ; preds = %31
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %34, %31
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = icmp sgt i32 %36, 3
  br i1 %37, label %38, label %60

38:                                               ; preds = %35
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = load i8, ptr %39, align 1, !tbaa !19
  %41 = zext i8 %40 to i32
  %42 = shl i32 %41, 24
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i64 1
  %45 = load i8, ptr %44, align 1, !tbaa !19
  %46 = zext i8 %45 to i32
  %47 = shl i32 %46, 16
  %48 = or i32 %42, %47
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i64 2
  %51 = load i8, ptr %50, align 1, !tbaa !19
  %52 = zext i8 %51 to i32
  %53 = shl i32 %52, 8
  %54 = or i32 %48, %53
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %55, i64 3
  %57 = load i8, ptr %56, align 1, !tbaa !19
  %58 = zext i8 %57 to i32
  %59 = or i32 %54, %58
  store i32 %59, ptr %14, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %38, %35
  %61 = load i32, ptr %10, align 4, !tbaa !9
  %62 = load i32, ptr %14, align 4, !tbaa !9
  %63 = icmp slt i32 %61, %62
  br i1 %63, label %64, label %68

64:                                               ; preds = %60
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  call void @png_warning(ptr noundef %65, ptr noundef @.str.19)
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load ptr, ptr %12, align 8, !tbaa !5
  call void @png_free(ptr noundef %66, ptr noundef %67)
  store i32 1, ptr %15, align 4
  br label %107

68:                                               ; preds = %60
  %69 = load i32, ptr %10, align 4, !tbaa !9
  %70 = load i32, ptr %14, align 4, !tbaa !9
  %71 = icmp sgt i32 %69, %70
  br i1 %71, label %72, label %75

72:                                               ; preds = %68
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  call void @png_warning(ptr noundef %73, ptr noundef @.str.20)
  %74 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %74, ptr %10, align 4, !tbaa !9
  br label %75

75:                                               ; preds = %72, %68
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %78, label %84

78:                                               ; preds = %75
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = load i32, ptr %10, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  %83 = call i32 @png_text_compress(ptr noundef %79, ptr noundef %80, i64 noundef %82, i32 noundef 0, ptr noundef %13)
  store i32 %83, ptr %10, align 4, !tbaa !9
  br label %84

84:                                               ; preds = %78, %75
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = load i64, ptr %11, align 8, !tbaa !17
  %87 = load i32, ptr %10, align 4, !tbaa !9
  %88 = sext i32 %87 to i64
  %89 = add i64 %86, %88
  %90 = add i64 %89, 2
  call void @png_write_chunk_start(ptr noundef %85, ptr noundef @png_iCCP, i64 noundef %90)
  %91 = load ptr, ptr %12, align 8, !tbaa !5
  %92 = load i64, ptr %11, align 8, !tbaa !17
  %93 = add i64 %92, 1
  %94 = getelementptr inbounds i8, ptr %91, i64 %93
  store i8 0, ptr %94, align 1, !tbaa !19
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = load ptr, ptr %12, align 8, !tbaa !5
  %97 = load i64, ptr %11, align 8, !tbaa !17
  %98 = add i64 %97, 2
  call void @png_write_chunk_data(ptr noundef %95, ptr noundef %96, i64 noundef %98)
  %99 = load i32, ptr %10, align 4, !tbaa !9
  %100 = icmp ne i32 %99, 0
  br i1 %100, label %101, label %103

101:                                              ; preds = %84
  %102 = load ptr, ptr %6, align 8, !tbaa !5
  call void @png_write_compressed_data_out(ptr noundef %102, ptr noundef %13)
  br label %103

103:                                              ; preds = %101, %84
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  call void @png_write_chunk_end(ptr noundef %104)
  %105 = load ptr, ptr %6, align 8, !tbaa !5
  %106 = load ptr, ptr %12, align 8, !tbaa !5
  call void @png_free(ptr noundef %105, ptr noundef %106)
  store i32 0, ptr %15, align 4
  br label %107

107:                                              ; preds = %103, %64, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %108 = load i32, ptr %15, align 4
  switch i32 %108, label %110 [
    i32 0, label %109
    i32 1, label %109
  ]

109:                                              ; preds = %107, %107
  ret void

110:                                              ; preds = %107
  unreachable
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @png_check_keyword(ptr noundef, ptr noundef, ptr noundef) #1

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

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

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

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 = { "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, !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, !10, i64 12}
!12 = !{!"", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !6, i64 24}
!13 = !{!12, !10, i64 16}
!14 = !{!12, !6, i64 24}
!15 = !{!12, !6, i64 0}
!16 = !{!12, !10, i64 8}
!17 = !{!18, !18, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!7, !7, 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.compression_state = type { ptr, i32, i32, i32, ptr }

@.str.18 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [50 x i8], align 1
@png_iCCP = external global [5 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_write_chunk_start(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @png_write_chunk_data(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @png_write_chunk_end(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @png_write_iCCP(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = alloca ptr, align 8
  %7 = alloca %struct.compression_state, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %7) #4
  %8 = getelementptr inbounds i8, ptr %7, i64 24
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(20) %7, i8 0, i64 20, i1 false)
  %9 = call i64 @png_check_keyword(ptr noundef %0, ptr noundef %1, ptr noundef nonnull %6)
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %54, label %11

11:                                               ; preds = %5
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %13, label %12

12:                                               ; preds = %11
  call void @png_warning(ptr noundef %0, ptr noundef nonnull @.str.18) #4
  br label %13

13:                                               ; preds = %12, %11
  %14 = icmp eq ptr %3, null
  %spec.select = select i1 %14, i32 0, i32 %4
  %15 = icmp sgt i32 %spec.select, 3
  br i1 %15, label %16, label %34

16:                                               ; preds = %13
  %17 = load i8, ptr %3, align 1, !tbaa !11
  %18 = zext i8 %17 to i32
  %19 = shl nuw i32 %18, 24
  %20 = getelementptr inbounds i8, ptr %3, i64 1
  %21 = load i8, ptr %20, align 1, !tbaa !11
  %22 = zext i8 %21 to i32
  %23 = shl nuw nsw i32 %22, 16
  %24 = or disjoint i32 %23, %19
  %25 = getelementptr inbounds i8, ptr %3, i64 2
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = zext i8 %26 to i32
  %28 = shl nuw nsw i32 %27, 8
  %29 = or disjoint i32 %24, %28
  %30 = getelementptr inbounds i8, ptr %3, i64 3
  %31 = load i8, ptr %30, align 1, !tbaa !11
  %32 = zext i8 %31 to i32
  %33 = or disjoint i32 %29, %32
  br label %34

34:                                               ; preds = %16, %13
  %.0 = phi i32 [ %33, %16 ], [ 0, %13 ]
  %35 = icmp slt i32 %spec.select, %.0
  br i1 %35, label %36, label %37

36:                                               ; preds = %34
  call void @png_warning(ptr noundef %0, ptr noundef nonnull @.str.19) #4
  br label %.sink.split

37:                                               ; preds = %34
  %38 = icmp sgt i32 %spec.select, %.0
  br i1 %38, label %39, label %40

39:                                               ; preds = %37
  call void @png_warning(ptr noundef %0, ptr noundef nonnull @.str.20) #4
  br label %40

40:                                               ; preds = %39, %37
  %.1 = phi i32 [ %.0, %39 ], [ %spec.select, %37 ]
  %.not33 = icmp eq i32 %.1, 0
  br i1 %.not33, label %44, label %41

41:                                               ; preds = %40
  %42 = sext i32 %.1 to i64
  %43 = call i32 @png_text_compress(ptr noundef %0, ptr noundef %3, i64 noundef %42, i32 noundef 0, ptr noundef nonnull %7)
  br label %44

44:                                               ; preds = %41, %40
  %.2 = phi i32 [ %43, %41 ], [ 0, %40 ]
  %45 = sext i32 %.2 to i64
  %46 = add i64 %9, 2
  %47 = add i64 %46, %45
  call void @png_write_chunk_start(ptr noundef %0, ptr noundef nonnull @png_iCCP, i64 noundef %47)
  %48 = load ptr, ptr %6, align 8, !tbaa !12
  %49 = getelementptr i8, ptr %48, i64 %9
  %50 = getelementptr i8, ptr %49, i64 1
  store i8 0, ptr %50, align 1, !tbaa !11
  %51 = load ptr, ptr %6, align 8, !tbaa !12
  call void @png_write_chunk_data(ptr noundef %0, ptr noundef %51, i64 noundef %46)
  %.not34 = icmp eq i32 %.2, 0
  br i1 %.not34, label %53, label %52

52:                                               ; preds = %44
  call void @png_write_compressed_data_out(ptr noundef %0, ptr noundef nonnull %7)
  br label %53

53:                                               ; preds = %52, %44
  call void @png_write_chunk_end(ptr noundef %0)
  br label %.sink.split

.sink.split:                                      ; preds = %36, %53
  %.sink = load ptr, ptr %6, align 8, !tbaa !12
  call void @png_free(ptr noundef %0, ptr noundef %.sink) #4
  br label %54

54:                                               ; preds = %.sink.split, %5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @png_check_keyword(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { "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 nounwind willreturn memory(argmem: write) }
attributes #4 = { 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, !7, i64 24}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !7, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = !{!7, !7, i64 0}


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