; LLVM IR from aap/librw :: src/d3d/d3d.ll (ZN2rw3d3d21imageFindRasterFormatEPNS_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 }

@_ZN2rw3d3d13isP8supportedE = external dso_local global i32, align 4
@stderr = external global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [59 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [30 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw3d3d21imageFindRasterFormatEPNS_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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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: mustprogress uwtable
define dso_local noundef i32 @_ZN2rw3d3d21imageFindRasterFormatEPNS_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.6, ptr noundef @.str.4, i32 noundef 676, ptr noundef @__PRETTY_FUNCTION__._ZN2rw3d3d21imageFindRasterFormatEPNS_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 %42

38:                                               ; preds = %26
  %39 = load i32, ptr @_ZN2rw3d3d13isP8supportedE, align 4, !tbaa !9
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %42, label %41

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

42:                                               ; preds = %41, %38, %26
  %43 = load i32, ptr %16, align 4, !tbaa !9
  switch i32 %43, label %55 [
    i32 32, label %44
    i32 24, label %51
    i32 16, label %52
    i32 8, label %53
    i32 4, label %54
  ]

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

48:                                               ; preds = %44
  store i32 1280, ptr %17, align 4, !tbaa !9
  br label %50

49:                                               ; preds = %44
  store i32 1536, ptr %17, align 4, !tbaa !9
  store i32 24, ptr %16, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %49, %48
  br label %66

51:                                               ; preds = %42
  store i32 1536, ptr %17, align 4, !tbaa !9
  br label %66

52:                                               ; preds = %42
  store i32 256, ptr %17, align 4, !tbaa !9
  br label %66

53:                                               ; preds = %42
  store i32 9472, ptr %17, align 4, !tbaa !9
  br label %66

54:                                               ; preds = %42
  store i32 17664, ptr %17, align 4, !tbaa !9
  br label %66

55:                                               ; preds = %42
  br label %56

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

64:                                               ; preds = %56
  br label %65

65:                                               ; preds = %64
  store i32 0, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %78

66:                                               ; preds = %54, %53, %52, %51, %50
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = load i32, ptr %17, align 4, !tbaa !9
  %69 = or i32 %68, %67
  store i32 %69, ptr %17, align 4, !tbaa !9
  %70 = load i32, ptr %14, align 4, !tbaa !9
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 %70, ptr %71, align 4, !tbaa !9
  %72 = load i32, ptr %15, align 4, !tbaa !9
  %73 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 %72, ptr %73, align 4, !tbaa !9
  %74 = load i32, ptr %16, align 4, !tbaa !9
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 %74, ptr %75, align 4, !tbaa !9
  %76 = load i32, ptr %17, align 4, !tbaa !9
  %77 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 %76, ptr %77, align 4, !tbaa !9
  store i32 1, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %78

78:                                               ; preds = %66, %65
  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
  %79 = load i32, ptr %7, align 4
  ret i32 %79
}

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

@_ZN2rw3d3d13isP8supportedE = external dso_local local_unnamed_addr global i32, align 4
@stderr = external local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [59 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [30 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw3d3d21imageFindRasterFormatEPNS_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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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 uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN2rw3d3d21imageFindRasterFormatEPNS_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.6, ptr noundef nonnull @.str.4, i32 noundef 676, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN2rw3d3d21imageFindRasterFormatEPNS_5ImageEiPiS3_S3_S3_) #6
  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 sgt i32 %17, 8
  %19 = load i32, ptr @_ZN2rw3d3d13isP8supportedE, align 4
  %20 = icmp ne i32 %19, 0
  %or.cond = select i1 %18, i1 true, i1 %20
  %spec.store.select = select i1 %or.cond, i32 %17, i32 32
  %21 = add i32 %spec.store.select, -4
  %22 = tail call i32 @llvm.fshl.i32(i32 %21, i32 %21, i32 30)
  switch i32 %22, label %28 [
    i32 7, label %23
    i32 5, label %35
    i32 3, label %25
    i32 1, label %26
    i32 0, label %27
  ]

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

25:                                               ; preds = %11
  br label %35

26:                                               ; preds = %11
  br label %35

27:                                               ; preds = %11
  br label %35

28:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #7
  store i32 2816, ptr %7, align 4, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %7, i64 4
  store i32 -2147483638, ptr %29, align 4, !tbaa !15
  %30 = load ptr, ptr @stderr, align 8, !tbaa !16
  %31 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4, i32 noundef 711) #8
  %32 = load ptr, ptr @stderr, align 8, !tbaa !16
  %33 = tail call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483638)
  %34 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef nonnull @.str.5, ptr noundef %33) #8
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef nonnull %7)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #7
  br label %37

35:                                               ; preds = %11, %23, %27, %26, %25
  %.018 = phi i32 [ %spec.store.select, %27 ], [ %spec.store.select, %26 ], [ %spec.store.select, %25 ], [ %.spec.store.select, %23 ], [ %spec.store.select, %11 ]
  %.0 = phi i32 [ 17664, %27 ], [ 9472, %26 ], [ 256, %25 ], [ %., %23 ], [ 1536, %11 ]
  %36 = or i32 %.0, %1
  store i32 %13, ptr %2, align 4, !tbaa !17
  store i32 %15, ptr %3, align 4, !tbaa !17
  store i32 %.018, ptr %4, align 4, !tbaa !17
  store i32 %36, ptr %5, align 4, !tbaa !17
  br label %37

37:                                               ; preds = %35, %28
  %.019 = phi i32 [ 0, %28 ], [ 1, %35 ]
  ret i32 %.019
}

; 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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.fshl.i32(i32, i32, i32) #5

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { noreturn nounwind }
attributes #7 = { nounwind }
attributes #8 = { 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