; LLVM IR from aap/librw :: src/ps2/ps2raster.ll (ZN2rw3ps221imageFindRasterFormatEPNS_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.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [65 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [30 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw3ps221imageFindRasterFormatEPNS_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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN2rw3ps221imageFindRasterFormatEPNS_5ImageEiPiS3_S3_S3_(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #4 {
  %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.2, i32 noundef 1577, ptr noundef @__PRETTY_FUNCTION__._ZN2rw3ps221imageFindRasterFormatEPNS_5ImageEiPiS3_S3_S3_) #6
  unreachable

25:                                               ; No predecessors!
  br label %26

26:                                               ; preds = %25, %23
  store i32 1, ptr %14, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %34, %26
  %28 = load i32, ptr %14, align 4, !tbaa !9
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.rw::Image", ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !11
  %32 = icmp slt i32 %28, %31
  br i1 %32, label %33, label %37

33:                                               ; preds = %27
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %14, align 4, !tbaa !9
  %36 = shl i32 %35, 1
  store i32 %36, ptr %14, align 4, !tbaa !9
  br label %27, !llvm.loop !13

37:                                               ; preds = %27
  store i32 1, ptr %15, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %45, %37
  %39 = load i32, ptr %15, align 4, !tbaa !9
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %"struct.rw::Image", ptr %40, i32 0, i32 2
  %42 = load i32, ptr %41, align 8, !tbaa !15
  %43 = icmp slt i32 %39, %42
  br i1 %43, label %44, label %48

44:                                               ; preds = %38
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %15, align 4, !tbaa !9
  %47 = shl i32 %46, 1
  store i32 %47, ptr %15, align 4, !tbaa !9
  br label %38, !llvm.loop !16

48:                                               ; preds = %38
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %"struct.rw::Image", ptr %49, i32 0, i32 3
  %51 = load i32, ptr %50, align 4, !tbaa !17
  store i32 %51, ptr %16, align 4, !tbaa !9
  %52 = load i32, ptr %16, align 4, !tbaa !9
  switch i32 %52, label %57 [
    i32 32, label %53
    i32 24, label %53
    i32 16, label %54
    i32 8, label %55
    i32 4, label %56
  ]

53:                                               ; preds = %48, %48
  store i32 1280, ptr %17, align 4, !tbaa !9
  store i32 32, ptr %16, align 4, !tbaa !9
  br label %68

54:                                               ; preds = %48
  store i32 256, ptr %17, align 4, !tbaa !9
  br label %68

55:                                               ; preds = %48
  store i32 9472, ptr %17, align 4, !tbaa !9
  br label %68

56:                                               ; preds = %48
  store i32 17664, ptr %17, align 4, !tbaa !9
  br label %68

57:                                               ; preds = %48
  br label %58

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

66:                                               ; preds = %58
  br label %67

67:                                               ; preds = %66
  store i32 0, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %80

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

80:                                               ; preds = %68, %67
  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
  %81 = load i32, ptr %7, align 4
  ret i32 %81
}

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 = { 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 #4 = { 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 #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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !10, i64 8}
!16 = distinct !{!16, !14}
!17 = !{!12, !10, i64 12}
!18 = !{!19, !10, i64 0}
!19 = !{!"_ZTSN2rw5ErrorE", !10, i64 0, !10, i64 4}
!20 = !{!19, !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.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [65 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [30 x i8], align 1
@__PRETTY_FUNCTION__._ZN2rw3ps221imageFindRasterFormatEPNS_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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN2rw3ps221imageFindRasterFormatEPNS_5ImageEiPiS3_S3_S3_(ptr nocapture noundef readonly %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 #4 {
  %7 = alloca %"struct.rw::Error", align 4
  %8 = and i32 %1, 15
  %9 = icmp eq i32 %8, 4
  br i1 %9, label %.preheader23, label %12

.preheader23:                                     ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !5
  br label %13

12:                                               ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.2, i32 noundef 1577, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN2rw3ps221imageFindRasterFormatEPNS_5ImageEiPiS3_S3_S3_) #6
  unreachable

13:                                               ; preds = %13, %.preheader23
  %.021 = phi i32 [ %15, %13 ], [ 1, %.preheader23 ]
  %14 = icmp slt i32 %.021, %11
  %15 = shl i32 %.021, 1
  br i1 %14, label %13, label %.preheader, !llvm.loop !11

.preheader:                                       ; preds = %13
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load i32, ptr %16, align 8, !tbaa !13
  br label %18

18:                                               ; preds = %18, %.preheader
  %.020 = phi i32 [ %20, %18 ], [ 1, %.preheader ]
  %19 = icmp slt i32 %.020, %17
  %20 = shl i32 %.020, 1
  br i1 %19, label %18, label %21, !llvm.loop !14

21:                                               ; preds = %18
  %22 = getelementptr inbounds i8, ptr %0, i64 12
  %23 = load i32, ptr %22, align 4, !tbaa !15
  %24 = add i32 %23, -4
  %25 = tail call i32 @llvm.fshl.i32(i32 %24, i32 %24, i32 30)
  switch i32 %25, label %29 [
    i32 7, label %36
    i32 5, label %36
    i32 3, label %26
    i32 1, label %27
    i32 0, label %28
  ]

26:                                               ; preds = %21
  br label %36

27:                                               ; preds = %21
  br label %36

28:                                               ; preds = %21
  br label %36

29:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #7
  store i32 2816, ptr %7, align 4, !tbaa !16
  %30 = getelementptr inbounds i8, ptr %7, i64 4
  store i32 -2147483638, ptr %30, align 4, !tbaa !18
  %31 = load ptr, ptr @stderr, align 8, !tbaa !19
  %32 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 1601) #8
  %33 = load ptr, ptr @stderr, align 8, !tbaa !19
  %34 = tail call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483638)
  %35 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef nonnull @.str.3, ptr noundef %34) #8
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef nonnull %7)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #7
  br label %38

36:                                               ; preds = %21, %21, %28, %27, %26
  %.019 = phi i32 [ %23, %28 ], [ %23, %27 ], [ %23, %26 ], [ 32, %21 ], [ 32, %21 ]
  %.0 = phi i32 [ 17664, %28 ], [ 9472, %27 ], [ 256, %26 ], [ 1280, %21 ], [ 1280, %21 ]
  %37 = or i32 %.0, %1
  store i32 %.021, ptr %2, align 4, !tbaa !20
  store i32 %.020, ptr %3, align 4, !tbaa !20
  store i32 %.019, ptr %4, align 4, !tbaa !20
  store i32 %37, ptr %5, align 4, !tbaa !20
  br label %38

38:                                               ; preds = %36, %29
  %.022 = phi i32 [ 0, %29 ], [ 1, %36 ]
  ret i32 %.022
}

; 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 = { 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 #4 = { 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 #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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!6, !7, i64 8}
!14 = distinct !{!14, !12}
!15 = !{!6, !7, i64 12}
!16 = !{!17, !7, i64 0}
!17 = !{!"_ZTSN2rw5ErrorE", !7, i64 0, !7, i64 4}
!18 = !{!17, !7, i64 4}
!19 = !{!10, !10, i64 0}
!20 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass