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

@png_zTXt = 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

; 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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

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

; Function Attrs: nounwind uwtable
define dso_local void @png_write_zTXt(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, i32 noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca [1 x i8], align 1
  %13 = alloca ptr, align 8
  %14 = alloca %struct.compression_state, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %14) #4
  %16 = getelementptr inbounds %struct.compression_state, ptr %14, i32 0, i32 2
  store i32 0, ptr %16, align 4, !tbaa !13
  %17 = getelementptr inbounds %struct.compression_state, ptr %14, i32 0, i32 3
  store i32 0, ptr %17, align 8, !tbaa !15
  %18 = getelementptr inbounds %struct.compression_state, ptr %14, i32 0, i32 4
  store ptr null, ptr %18, align 8, !tbaa !16
  %19 = getelementptr inbounds %struct.compression_state, ptr %14, i32 0, i32 0
  store ptr null, ptr %19, align 8, !tbaa !17
  %20 = getelementptr inbounds %struct.compression_state, ptr %14, i32 0, i32 1
  store i32 0, ptr %20, align 8, !tbaa !18
  %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 %13)
  store i64 %23, ptr %11, align 8, !tbaa !9
  %24 = icmp eq i64 %23, 0
  br i1 %24, label %25, label %28

25:                                               ; preds = %5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load ptr, ptr %13, align 8, !tbaa !5
  call void @png_free(ptr noundef %26, ptr noundef %27)
  store i32 1, ptr %15, align 4
  br label %72

28:                                               ; preds = %5
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = icmp eq ptr %29, null
  br i1 %30, label %39, label %31

31:                                               ; preds = %28
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = load i8, ptr %32, align 1, !tbaa !19
  %34 = sext i8 %33 to i32
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %39, label %36

36:                                               ; preds = %31
  %37 = load i32, ptr %10, align 4, !tbaa !11
  %38 = icmp eq i32 %37, -1
  br i1 %38, label %39, label %45

39:                                               ; preds = %36, %31, %28
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load ptr, ptr %13, align 8, !tbaa !5
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  call void @png_write_tEXt(ptr noundef %40, ptr noundef %41, ptr noundef %42, i64 noundef 0)
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load ptr, ptr %13, align 8, !tbaa !5
  call void @png_free(ptr noundef %43, ptr noundef %44)
  store i32 1, ptr %15, align 4
  br label %72

45:                                               ; preds = %36
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = call i64 @strlen(ptr noundef %46) #5
  store i64 %47, ptr %9, align 8, !tbaa !9
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load i64, ptr %9, align 8, !tbaa !9
  %51 = load i32, ptr %10, align 4, !tbaa !11
  %52 = call i32 @png_text_compress(ptr noundef %48, ptr noundef %49, i64 noundef %50, i32 noundef %51, ptr noundef %14)
  %53 = sext i32 %52 to i64
  store i64 %53, ptr %9, align 8, !tbaa !9
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load i64, ptr %11, align 8, !tbaa !9
  %56 = load i64, ptr %9, align 8, !tbaa !9
  %57 = add i64 %55, %56
  %58 = add i64 %57, 2
  call void @png_write_chunk_start(ptr noundef %54, ptr noundef @png_zTXt, i64 noundef %58)
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load ptr, ptr %13, align 8, !tbaa !5
  %61 = load i64, ptr %11, align 8, !tbaa !9
  %62 = add i64 %61, 1
  call void @png_write_chunk_data(ptr noundef %59, ptr noundef %60, i64 noundef %62)
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = load ptr, ptr %13, align 8, !tbaa !5
  call void @png_free(ptr noundef %63, ptr noundef %64)
  %65 = load i32, ptr %10, align 4, !tbaa !11
  %66 = trunc i32 %65 to i8
  %67 = getelementptr inbounds [1 x i8], ptr %12, i64 0, i64 0
  store i8 %66, ptr %67, align 1, !tbaa !19
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds [1 x i8], ptr %12, i64 0, i64 0
  call void @png_write_chunk_data(ptr noundef %68, ptr noundef %69, i64 noundef 1)
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  call void @png_write_compressed_data_out(ptr noundef %70, ptr noundef %14)
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  call void @png_write_chunk_end(ptr noundef %71)
  store i32 0, ptr %15, align 4
  br label %72

72:                                               ; preds = %45, %39, %25
  call void @llvm.lifetime.end.p0(i64 32, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  %73 = load i32, ptr %15, align 4
  switch i32 %73, label %75 [
    i32 0, label %74
    i32 1, label %74
  ]

74:                                               ; preds = %72, %72
  ret void

75:                                               ; preds = %72
  unreachable
}

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 willreturn memory(read) "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 = { nounwind willreturn memory(read) }

!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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 12}
!14 = !{!"", !6, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !6, i64 24}
!15 = !{!14, !12, i64 16}
!16 = !{!14, !6, i64 24}
!17 = !{!14, !6, i64 0}
!18 = !{!14, !12, i64 8}
!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 }

@png_zTXt = 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

; 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: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #3

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

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

12:                                               ; preds = %5
  %13 = load ptr, ptr %7, align 8, !tbaa !11
  call void @png_free(ptr noundef %0, ptr noundef %13) #5
  br label %33

14:                                               ; preds = %5
  %15 = icmp eq ptr %2, null
  br i1 %15, label %20, label %16

16:                                               ; preds = %14
  %17 = load i8, ptr %2, align 1, !tbaa !12
  %18 = icmp eq i8 %17, 0
  %19 = icmp eq i32 %4, -1
  %or.cond = or i1 %19, %18
  br i1 %or.cond, label %20, label %23

20:                                               ; preds = %16, %14
  %21 = load ptr, ptr %7, align 8, !tbaa !11
  call void @png_write_tEXt(ptr noundef %0, ptr noundef %21, ptr noundef %2, i64 noundef 0)
  %22 = load ptr, ptr %7, align 8, !tbaa !11
  call void @png_free(ptr noundef %0, ptr noundef %22) #5
  br label %33

23:                                               ; preds = %16
  %24 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #6
  %25 = call i32 @png_text_compress(ptr noundef %0, ptr noundef nonnull %2, i64 noundef %24, i32 noundef %4, ptr noundef nonnull %8)
  %26 = sext i32 %25 to i64
  %27 = add i64 %10, 2
  %28 = add i64 %27, %26
  call void @png_write_chunk_start(ptr noundef %0, ptr noundef nonnull @png_zTXt, i64 noundef %28)
  %29 = load ptr, ptr %7, align 8, !tbaa !11
  %30 = add i64 %10, 1
  call void @png_write_chunk_data(ptr noundef %0, ptr noundef %29, i64 noundef %30)
  %31 = load ptr, ptr %7, align 8, !tbaa !11
  call void @png_free(ptr noundef %0, ptr noundef %31) #5
  %32 = trunc i32 %4 to i8
  store i8 %32, ptr %6, align 1, !tbaa !12
  call void @png_write_chunk_data(ptr noundef %0, ptr noundef nonnull %6, i64 noundef 1)
  call void @png_write_compressed_data_out(ptr noundef %0, ptr noundef nonnull %8)
  call void @png_write_chunk_end(ptr noundef %0)
  br label %33

33:                                               ; preds = %23, %20, %12
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %6) #5
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!7, !7, i64 0}
!12 = !{!8, !8, i64 0}


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