; LLVM IR from Try/Tempest :: Engine/thirdparty/libpng (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.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }
%struct.png_image = type { ptr, i32, i32, i32, i32, i32, i32, i32, [64 x i8] }
%struct.png_control = type { ptr, ptr, ptr, ptr, i64, i8 }

; 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 returns_twice
declare i32 @_setjmp(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @png_safe_execute(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca [1 x %struct.__jmp_buf_tag], align 16
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  store volatile ptr %11, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 200, ptr %10) #4
  %12 = load volatile ptr, ptr %7, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.png_image, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.png_control, ptr %14, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  store volatile ptr %16, ptr %9, align 8, !tbaa !5
  %17 = getelementptr inbounds [1 x %struct.__jmp_buf_tag], ptr %10, i64 0, i64 0
  %18 = call i32 @_setjmp(ptr noundef %17) #5
  %19 = icmp eq i32 %18, 0
  %20 = zext i1 %19 to i32
  store volatile i32 %20, ptr %8, align 4, !tbaa !15
  %21 = load volatile i32, ptr %8, align 4, !tbaa !15
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %32

23:                                               ; preds = %3
  %24 = getelementptr inbounds [1 x %struct.__jmp_buf_tag], ptr %10, i64 0, i64 0
  %25 = load volatile ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.png_image, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.png_control, ptr %27, i32 0, i32 2
  store ptr %24, ptr %28, align 8, !tbaa !12
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call i32 %29(ptr noundef %30)
  store volatile i32 %31, ptr %8, align 4, !tbaa !15
  br label %32

32:                                               ; preds = %23, %3
  %33 = load volatile ptr, ptr %9, align 8, !tbaa !5
  %34 = load volatile ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.png_image, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.png_control, ptr %36, i32 0, i32 2
  store ptr %33, ptr %37, align 8, !tbaa !12
  %38 = load volatile i32, ptr %8, align 4, !tbaa !15
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %42

40:                                               ; preds = %32
  %41 = load volatile ptr, ptr %7, align 8, !tbaa !5
  call void @png_image_free(ptr noundef %41)
  br label %42

42:                                               ; preds = %40, %32
  %43 = load volatile i32, ptr %8, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 200, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret i32 %43
}

declare void @png_image_free(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind returns_twice "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 = { 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 = { nounwind returns_twice }

!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, !6, i64 0}
!10 = !{!"", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !7, i64 36}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 16}
!13 = !{!"png_control", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !14, i64 32, !11, i64 40, !11, i64 40}
!14 = !{!"long", !7, i64 0}
!15 = !{!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"

%struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }
%struct.__sigset_t = type { [16 x i64] }

; 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 returns_twice
declare i32 @_setjmp(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @png_safe_execute(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca [1 x %struct.__jmp_buf_tag], align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4)
  store volatile ptr %0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6)
  call void @llvm.lifetime.start.p0(i64 200, ptr nonnull %7) #4
  %.0..0..0..0.4 = load volatile ptr, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %.0..0..0..0.4, align 8, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  store volatile ptr %10, ptr %6, align 8, !tbaa !5
  %11 = call i32 @_setjmp(ptr noundef nonnull %7) #5
  %12 = icmp eq i32 %11, 0
  %13 = zext i1 %12 to i32
  store volatile i32 %13, ptr %5, align 4, !tbaa !15
  %.0..0..0..0.1 = load volatile i32, ptr %5, align 4, !tbaa !15
  %.not = icmp eq i32 %.0..0..0..0.1, 0
  br i1 %.not, label %18, label %14

14:                                               ; preds = %3
  %.0..0..0..0.5 = load volatile ptr, ptr %4, align 8, !tbaa !5
  %15 = load ptr, ptr %.0..0..0..0.5, align 8, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  store ptr %7, ptr %16, align 8, !tbaa !12
  %17 = call i32 %1(ptr noundef %2) #4
  store volatile i32 %17, ptr %5, align 4, !tbaa !15
  br label %18

18:                                               ; preds = %14, %3
  %.0..0..0..0. = load volatile ptr, ptr %6, align 8, !tbaa !5
  %.0..0..0..0.6 = load volatile ptr, ptr %4, align 8, !tbaa !5
  %19 = load ptr, ptr %.0..0..0..0.6, align 8, !tbaa !9
  %20 = getelementptr inbounds i8, ptr %19, i64 16
  store ptr %.0..0..0..0., ptr %20, align 8, !tbaa !12
  %.0..0..0..0.2 = load volatile i32, ptr %5, align 4, !tbaa !15
  %21 = icmp eq i32 %.0..0..0..0.2, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %18
  %.0..0..0..0.7 = load volatile ptr, ptr %4, align 8, !tbaa !5
  call void @png_image_free(ptr noundef %.0..0..0..0.7) #4
  br label %23

23:                                               ; preds = %22, %18
  %.0..0..0..0.3 = load volatile i32, ptr %5, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 200, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4)
  ret i32 %.0..0..0..0.3
}

declare void @png_image_free(ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind returns_twice "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 = { 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 = { nounwind returns_twice }

!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, !6, i64 0}
!10 = !{!"", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !7, i64 36}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 16}
!13 = !{!"png_control", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !14, i64 32, !11, i64 40, !11, i64 40}
!14 = !{!"long", !7, i64 0}
!15 = !{!11, !11, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass