; LLVM IR from aap/librw :: src/gl/gl3raster.ll (ZN2rw3gl321imageFindRasterFormatEPNS_5ImageEiPiS3_S3_S3_)

; 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.rw::Error" = type { i32, i32 }
%"struct.rw::Image" = type { i32, i32, i32, i32, i32, i32, ptr, ptr }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [30 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw3gl321imageFindRasterFormatEPNS_5ImageEiPiS3_S3_S3_ = external hidden unnamed_addr constant [90 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: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

declare noundef ptr @_ZN2rw9dbgsprintEjz(i32 noundef, ...) #2

declare void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef) #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN2rw3gl321imageFindRasterFormatEPNS_5ImageEiPiS3_S3_S3_(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #3 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca %"struct.rw::Error", align 4
  %19 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #5
  %20 = load i32, ptr %9, align 4, !tbaa !9
  %21 = and i32 %20, 15
  %22 = icmp eq i32 %21, 4
  br i1 %22, label %23, label %24

23:                                               ; preds = %6
  br label %26

24:                                               ; preds = %6
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 592, ptr noundef @__PRETTY_FUNCTION__._ZN2rw3gl321imageFindRasterFormatEPNS_5ImageEiPiS3_S3_S3_) #6
  unreachable

25:                                               ; No predecessors!
  br label %26

26:                                               ; preds = %25, %23
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.rw::Image", ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !11
  store i32 %29, ptr %14, align 4, !tbaa !9
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.rw::Image", ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 8, !tbaa !13
  store i32 %32, ptr %15, align 4, !tbaa !9
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.rw::Image", ptr %33, i32 0, i32 3
  %35 = load i32, ptr %34, align 4, !tbaa !14
  store i32 %35, ptr %16, align 4, !tbaa !9
  %36 = load i32, ptr %16, align 4, !tbaa !9
  %37 = icmp sle i32 %36, 8
  br i1 %37, label %38, label %39

38:                                               ; preds = %26
  store i32 32, ptr %16, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %38, %26
  %40 = load i32, ptr %16, align 4, !tbaa !9
  switch i32 %40, label %51 [
    i32 32, label %41
    i32 24, label %48
    i32 16, label %49
    i32 8, label %50
    i32 4, label %50
  ]

41:                                               ; preds = %39
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = call noundef i32 @_ZN2rw5Image8hasAlphaEv(ptr noundef nonnull align 8 dereferenceable(40) %42)
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %41
  store i32 1280, ptr %17, align 4, !tbaa !9
  br label %47

46:                                               ; preds = %41
  store i32 1536, ptr %17, align 4, !tbaa !9
  store i32 24, ptr %16, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %46, %45
  br label %62

48:                                               ; preds = %39
  store i32 1536, ptr %17, align 4, !tbaa !9
  br label %62

49:                                               ; preds = %39
  store i32 256, ptr %17, align 4, !tbaa !9
  br label %62

50:                                               ; preds = %39, %39
  br label %51

51:                                               ; preds = %50, %39
  br label %52

52:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #5
  %53 = getelementptr inbounds %"struct.rw::Error", ptr %18, i32 0, i32 0
  store i32 2816, ptr %53, align 4, !tbaa !15
  %54 = getelementptr inbounds %"struct.rw::Error", ptr %18, i32 0, i32 1
  store i32 -2147483638, ptr %54, align 4, !tbaa !17
  %55 = load ptr, ptr @stderr, align 8, !tbaa !5
  %56 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %55, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 624) #5
  %57 = load ptr, ptr @stderr, align 8, !tbaa !5
  %58 = call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483638)
  %59 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %57, ptr noundef @.str.2, ptr noundef %58) #5
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef %18)
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #5
  br label %60

60:                                               ; preds = %52
  br label %61

61:                                               ; preds = %60
  store i32 0, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %74

62:                                               ; preds = %49, %48, %47
  %63 = load i32, ptr %9, align 4, !tbaa !9
  %64 = load i32, ptr %17, align 4, !tbaa !9
  %65 = or i32 %64, %63
  store i32 %65, ptr %17, align 4, !tbaa !9
  %66 = load i32, ptr %14, align 4, !tbaa !9
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 %66, ptr %67, align 4, !tbaa !9
  %68 = load i32, ptr %15, align 4, !tbaa !9
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 %68, ptr %69, align 4, !tbaa !9
  %70 = load i32, ptr %16, align 4, !tbaa !9
  %71 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 %70, ptr %71, align 4, !tbaa !9
  %72 = load i32, ptr %17, align 4, !tbaa !9
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 %72, ptr %73, align 4, !tbaa !9
  store i32 1, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %74

74:                                               ; preds = %62, %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  %75 = load i32, ptr %7, align 4
  ret i32 %75
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #4

declare noundef i32 @_ZN2rw5Image8hasAlphaEv(ptr noundef nonnull align 8 dereferenceable(40)) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 #4 = { noreturn 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 = { noreturn 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_ZTSN2rw5ImageE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !6, i64 24, !6, i64 32}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !10, i64 12}
!15 = !{!16, !10, i64 0}
!16 = !{!"_ZTSN2rw5ErrorE", !10, i64 0, !10, i64 4}
!17 = !{!16, !10, i64 4}


; 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.rw::Error" = type { i32, i32 }

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [30 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw3gl321imageFindRasterFormatEPNS_5ImageEiPiS3_S3_S3_ = external hidden unnamed_addr constant [90 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: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

declare noundef ptr @_ZN2rw9dbgsprintEjz(i32 noundef, ...) local_unnamed_addr #2

declare void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN2rw3gl321imageFindRasterFormatEPNS_5ImageEiPiS3_S3_S3_(ptr noundef %0, i32 noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef writeonly %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #3 {
  %7 = alloca %"struct.rw::Error", align 4
  %8 = and i32 %1, 15
  %9 = icmp eq i32 %8, 4
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 592, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN2rw3gl321imageFindRasterFormatEPNS_5ImageEiPiS3_S3_S3_) #5
  unreachable

11:                                               ; preds = %6
  %12 = getelementptr inbounds i8, ptr %0, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %0, i64 12
  %17 = load i32, ptr %16, align 4, !tbaa !12
  %18 = icmp slt i32 %17, 9
  %spec.store.select = select i1 %18, i32 32, i32 %17
  switch i32 %spec.store.select, label %22 [
    i32 32, label %19
    i32 24, label %29
    i32 16, label %21
  ]

19:                                               ; preds = %11
  %20 = tail call noundef i32 @_ZN2rw5Image8hasAlphaEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %.not = icmp eq i32 %20, 0
  %. = select i1 %.not, i32 24, i32 32
  %.19 = select i1 %.not, i32 1536, i32 1280
  br label %29

21:                                               ; preds = %11
  br label %29

22:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #6
  store i32 2816, ptr %7, align 4, !tbaa !13
  %23 = getelementptr inbounds i8, ptr %7, i64 4
  store i32 -2147483638, ptr %23, align 4, !tbaa !15
  %24 = load ptr, ptr @stderr, align 8, !tbaa !16
  %25 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 624) #7
  %26 = load ptr, ptr @stderr, align 8, !tbaa !16
  %27 = tail call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483638)
  %28 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef nonnull @.str.2, ptr noundef %27) #7
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef nonnull %7)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #6
  br label %31

29:                                               ; preds = %11, %19, %21
  %.017 = phi i32 [ %spec.store.select, %21 ], [ %., %19 ], [ %spec.store.select, %11 ]
  %.0 = phi i32 [ 256, %21 ], [ %.19, %19 ], [ 1536, %11 ]
  %30 = or i32 %.0, %1
  store i32 %13, ptr %2, align 4, !tbaa !17
  store i32 %15, ptr %3, align 4, !tbaa !17
  store i32 %.017, ptr %4, align 4, !tbaa !17
  store i32 %30, ptr %5, align 4, !tbaa !17
  br label %31

31:                                               ; preds = %29, %22
  %.018 = phi i32 [ 0, %22 ], [ 1, %29 ]
  ret i32 %.018
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #4

declare noundef i32 @_ZN2rw5Image8hasAlphaEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 #4 = { noreturn 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 = { noreturn nounwind }
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, !7, i64 4}
!6 = !{!"_ZTSN2rw5ImageE", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !10, i64 24, !10, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 12}
!13 = !{!14, !7, i64 0}
!14 = !{!"_ZTSN2rw5ErrorE", !7, i64 0, !7, i64 4}
!15 = !{!14, !7, i64 4}
!16 = !{!10, !10, i64 0}
!17 = !{!7, !7, i64 0}


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