; LLVM IR from zchrissirhcz/pixel :: src (px_image_io)

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

@.str.9 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [5 x i8], align 1
@stderr = external global ptr, align 8
@.str.11 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @stbi_failure_reason() #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @stbi_load(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @px_read_image(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call ptr @strstr(ptr noundef %16, ptr noundef @.str.9) #6
  store ptr %17, ptr %4, align 8, !tbaa !5
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = call i32 @strcmp(ptr noundef %18, ptr noundef @.str.10) #6
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %31

21:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  call void @px_read_bmp(ptr noundef %22, ptr noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %8)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = call ptr @px_create_image_header(i32 noundef %23, i32 noundef %24, i32 noundef %25)
  store ptr %26, ptr %9, align 8, !tbaa !5
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.px_image_t, ptr %28, i32 0, i32 0
  store ptr %27, ptr %29, align 8, !tbaa !11
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %30, ptr %2, align 8
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %87

31:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = call ptr @stbi_load(ptr noundef %32, ptr noundef %11, ptr noundef %12, ptr noundef %13, i32 noundef 0)
  store ptr %33, ptr %14, align 8, !tbaa !5
  %34 = load ptr, ptr %14, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %46, label %36

36:                                               ; preds = %31
  br label %37

37:                                               ; preds = %36
  %38 = load ptr, ptr @stderr, align 8, !tbaa !5
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = call ptr @stbi_failure_reason()
  %41 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef @.str.11, ptr noundef %39, ptr noundef %40) #5
  %42 = load ptr, ptr @stderr, align 8, !tbaa !5
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef @.str.12) #5
  br label %44

44:                                               ; preds = %37
  br label %45

45:                                               ; preds = %44
  store ptr null, ptr %2, align 8
  store i32 1, ptr %10, align 4
  br label %86

46:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %47 = load i32, ptr %12, align 4, !tbaa !9
  %48 = load i32, ptr %11, align 4, !tbaa !9
  %49 = load i32, ptr %13, align 4, !tbaa !9
  %50 = call ptr @px_create_image_header(i32 noundef %47, i32 noundef %48, i32 noundef %49)
  store ptr %50, ptr %15, align 8, !tbaa !5
  %51 = load i32, ptr %12, align 4, !tbaa !9
  %52 = load ptr, ptr %15, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.px_image_t, ptr %52, i32 0, i32 2
  store i32 %51, ptr %53, align 4, !tbaa !13
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = load ptr, ptr %15, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.px_image_t, ptr %55, i32 0, i32 1
  store i32 %54, ptr %56, align 8, !tbaa !14
  %57 = load i32, ptr %13, align 4, !tbaa !9
  %58 = load ptr, ptr %15, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.px_image_t, ptr %58, i32 0, i32 3
  store i32 %57, ptr %59, align 8, !tbaa !15
  %60 = load ptr, ptr %14, align 8, !tbaa !5
  %61 = load ptr, ptr %15, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.px_image_t, ptr %61, i32 0, i32 0
  store ptr %60, ptr %62, align 8, !tbaa !11
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = call i32 @strcmp(ptr noundef %63, ptr noundef @.str.13) #6
  %65 = icmp eq i32 %64, 0
  br i1 %65, label %66, label %68

66:                                               ; preds = %46
  %67 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr %67, ptr %2, align 8
  store i32 1, ptr %10, align 4
  br label %85

68:                                               ; preds = %46
  %69 = load ptr, ptr %15, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.px_image_t, ptr %69, i32 0, i32 3
  %71 = load i32, ptr %70, align 8, !tbaa !15
  %72 = icmp eq i32 %71, 3
  br i1 %72, label %73, label %75

73:                                               ; preds = %68
  %74 = load ptr, ptr %15, align 8, !tbaa !5
  call void @px_rgb_to_bgr_inplace(ptr noundef %74)
  br label %83

75:                                               ; preds = %68
  %76 = load ptr, ptr %15, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.px_image_t, ptr %76, i32 0, i32 3
  %78 = load i32, ptr %77, align 8, !tbaa !15
  %79 = icmp eq i32 %78, 4
  br i1 %79, label %80, label %82

80:                                               ; preds = %75
  %81 = load ptr, ptr %15, align 8, !tbaa !5
  call void @px_rgba_to_bgra_inplace(ptr noundef %81)
  br label %82

82:                                               ; preds = %80, %75
  br label %83

83:                                               ; preds = %82, %73
  %84 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr %84, ptr %2, align 8
  store i32 1, ptr %10, align 4
  br label %85

85:                                               ; preds = %83, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  br label %86

86:                                               ; preds = %85, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %87

87:                                               ; preds = %86, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %88 = load ptr, ptr %2, align 8
  ret ptr %88
}

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strstr(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #2

declare void @px_read_bmp(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

declare ptr @px_create_image_header(i32 noundef, i32 noundef, i32 noundef) #3

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #4

declare void @px_rgb_to_bgr_inplace(ptr noundef) #3

declare void @px_rgba_to_bgra_inplace(ptr noundef) #3

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 "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 #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, !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, !6, i64 0}
!12 = !{!"px_image_t", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!13 = !{!12, !10, i64 12}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !10, i64 16}


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

@.str.9 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [5 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.11 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @stbi_failure_reason() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @stbi_load(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @px_read_image(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = tail call ptr @strstr(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) @.str.9) #5
  %10 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %9, ptr noundef nonnull dereferenceable(1) @.str.10) #5
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %18

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #6
  call void @px_read_bmp(ptr noundef %0, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4, ptr noundef nonnull %5) #6
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = call ptr @px_create_image_header(i32 noundef %13, i32 noundef %14, i32 noundef %15) #6
  %17 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %17, ptr %16, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  br label %43

18:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #6
  %19 = call ptr @stbi_load(ptr noundef %0, ptr noundef nonnull %6, ptr noundef nonnull %7, ptr noundef nonnull %8, i32 noundef 0)
  %.not = icmp eq ptr %19, null
  br i1 %.not, label %20, label %26

20:                                               ; preds = %18
  %21 = load ptr, ptr @stderr, align 8, !tbaa !9
  %22 = call ptr @stbi_failure_reason()
  %23 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str.11, ptr noundef %0, ptr noundef %22) #7
  %24 = load ptr, ptr @stderr, align 8, !tbaa !9
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str.12) #7
  br label %42

26:                                               ; preds = %18
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = call ptr @px_create_image_header(i32 noundef %27, i32 noundef %28, i32 noundef %29) #6
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %30, i64 12
  store i32 %31, ptr %32, align 4, !tbaa !13
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %30, i64 8
  store i32 %33, ptr %34, align 8, !tbaa !14
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %30, i64 16
  store i32 %35, ptr %36, align 8, !tbaa !15
  store ptr %19, ptr %30, align 8, !tbaa !11
  %37 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %9, ptr noundef nonnull dereferenceable(1) @.str.13) #5
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %42, label %39

39:                                               ; preds = %26
  switch i32 %35, label %42 [
    i32 3, label %40
    i32 4, label %41
  ]

40:                                               ; preds = %39
  call void @px_rgb_to_bgr_inplace(ptr noundef nonnull %30) #6
  br label %42

41:                                               ; preds = %39
  call void @px_rgba_to_bgra_inplace(ptr noundef nonnull %30) #6
  br label %42

42:                                               ; preds = %26, %39, %41, %40, %20
  %.1 = phi ptr [ null, %20 ], [ %30, %40 ], [ %30, %41 ], [ %30, %39 ], [ %30, %26 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #6
  br label %43

43:                                               ; preds = %42, %12
  %.2 = phi ptr [ %16, %12 ], [ %.1, %42 ]
  ret ptr %.2
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strstr(ptr noundef, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #2

declare void @px_read_bmp(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare ptr @px_create_image_header(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #4

declare void @px_rgb_to_bgr_inplace(ptr noundef) local_unnamed_addr #3

declare void @px_rgba_to_bgra_inplace(ptr noundef) local_unnamed_addr #3

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { nofree nounwind "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 #5 = { nounwind willreturn memory(read) }
attributes #6 = { nounwind }
attributes #7 = { cold 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"px_image_t", !10, i64 0, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20}
!13 = !{!12, !6, i64 12}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !6, i64 16}


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