; LLVM IR from aap/librw :: src/ps2/ps2raster.ll (ZN2rw3ps212rasterCreateEPNS_6RasterE)

; 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::Raster" = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, i32, i32, i32, ptr, i32, i32 }

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN2rw3ps215getRasterFormatEPNS_6RasterE(ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw3ps212rasterCreateEPNS_6RasterE(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = call noundef i32 @_ZN2rw3ps215getRasterFormatEPNS_6RasterE(ptr noundef %4)
  %6 = icmp ne i32 %5, 0
  br i1 %6, label %8, label %7

7:                                                ; preds = %1
  store ptr null, ptr %2, align 8
  br label %62

8:                                                ; preds = %1
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %"struct.rw::Raster", ptr %9, i32 0, i32 9
  store ptr null, ptr %10, align 8, !tbaa !9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %"struct.rw::Raster", ptr %11, i32 0, i32 10
  store ptr null, ptr %12, align 8, !tbaa !12
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %"struct.rw::Raster", ptr %13, i32 0, i32 5
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %"struct.rw::Raster", ptr %16, i32 0, i32 12
  store i32 %15, ptr %17, align 8, !tbaa !14
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.rw::Raster", ptr %18, i32 0, i32 6
  %20 = load i32, ptr %19, align 8, !tbaa !15
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.rw::Raster", ptr %21, i32 0, i32 13
  store i32 %20, ptr %22, align 4, !tbaa !16
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %"struct.rw::Raster", ptr %23, i32 0, i32 9
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.rw::Raster", ptr %26, i32 0, i32 11
  store ptr %25, ptr %27, align 8, !tbaa !17
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.rw::Raster", ptr %28, i32 0, i32 5
  %30 = load i32, ptr %29, align 4, !tbaa !13
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %37, label %32

32:                                               ; preds = %8
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.rw::Raster", ptr %33, i32 0, i32 6
  %35 = load i32, ptr %34, align 8, !tbaa !15
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %45

37:                                               ; preds = %32, %8
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %"struct.rw::Raster", ptr %38, i32 0, i32 2
  store i32 128, ptr %39, align 8, !tbaa !18
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %"struct.rw::Raster", ptr %40, i32 0, i32 8
  store i32 0, ptr %41, align 8, !tbaa !19
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.rw::Raster", ptr %42, i32 0, i32 14
  store i32 0, ptr %43, align 8, !tbaa !20
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %44, ptr %2, align 8
  br label %62

45:                                               ; preds = %32
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.rw::Raster", ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !21
  switch i32 %48, label %61 [
    i32 0, label %49
    i32 4, label %49
    i32 1, label %52
    i32 2, label %56
    i32 5, label %60
  ]

49:                                               ; preds = %45, %45
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = call noundef ptr @_ZN2rw3ps2L19rasterCreateTextureEPNS_6RasterE(ptr noundef %50)
  store ptr %51, ptr %2, align 8
  br label %62

52:                                               ; preds = %45
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %"struct.rw::Raster", ptr %53, i32 0, i32 2
  store i32 128, ptr %54, align 8, !tbaa !18
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %55, ptr %2, align 8
  br label %62

56:                                               ; preds = %45
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %"struct.rw::Raster", ptr %57, i32 0, i32 2
  store i32 128, ptr %58, align 8, !tbaa !18
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %59, ptr %2, align 8
  br label %62

60:                                               ; preds = %45
  store ptr null, ptr %2, align 8
  br label %62

61:                                               ; preds = %45
  store ptr null, ptr %2, align 8
  br label %62

62:                                               ; preds = %61, %60, %56, %52, %49, %37, %7
  %63 = load ptr, ptr %2, align 8
  ret ptr %63
}

; Function Attrs: mustprogress uwtable
declare hidden noundef ptr @_ZN2rw3ps2L19rasterCreateTextureEPNS_6RasterE(ptr noundef) #0

attributes #0 = { 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" }

!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, !6, i64 40}
!10 = !{!"_ZTSN2rw6RasterE", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !11, i64 64, !11, i64 68, !11, i64 72, !6, i64 80, !11, i64 88, !11, i64 92}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 48}
!13 = !{!10, !11, i64 20}
!14 = !{!10, !11, i64 64}
!15 = !{!10, !11, i64 24}
!16 = !{!10, !11, i64 68}
!17 = !{!10, !6, i64 56}
!18 = !{!10, !11, i64 8}
!19 = !{!10, !11, i64 32}
!20 = !{!10, !11, i64 72}
!21 = !{!10, !11, 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"

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN2rw3ps215getRasterFormatEPNS_6RasterE(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw3ps212rasterCreateEPNS_6RasterE(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call noundef i32 @_ZN2rw3ps215getRasterFormatEPNS_6RasterE(ptr noundef %0)
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %27, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  %5 = getelementptr inbounds i8, ptr %0, i64 20
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %4, i8 0, i64 16, i1 false)
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 %6, ptr %7, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load i32, ptr %8, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %0, i64 68
  store i32 %9, ptr %10, align 4, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr null, ptr %11, align 8, !tbaa !14
  %12 = icmp eq i32 %6, 0
  %13 = icmp eq i32 %9, 0
  %or.cond = select i1 %12, i1 true, i1 %13
  br i1 %or.cond, label %14, label %18

14:                                               ; preds = %3
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 128, ptr %15, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 0, ptr %16, align 8, !tbaa !16
  %17 = getelementptr inbounds i8, ptr %0, i64 72
  store i32 0, ptr %17, align 8, !tbaa !17
  br label %27

18:                                               ; preds = %3
  %19 = getelementptr inbounds i8, ptr %0, i64 4
  %20 = load i32, ptr %19, align 4, !tbaa !18
  switch i32 %20, label %27 [
    i32 0, label %21
    i32 4, label %21
    i32 1, label %23
    i32 2, label %25
  ]

21:                                               ; preds = %18, %18
  %22 = tail call noundef ptr @_ZN2rw3ps2L19rasterCreateTextureEPNS_6RasterE(ptr noundef nonnull %0)
  br label %27

23:                                               ; preds = %18
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 128, ptr %24, align 8, !tbaa !15
  br label %27

25:                                               ; preds = %18
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 128, ptr %26, align 8, !tbaa !15
  br label %27

27:                                               ; preds = %18, %1, %25, %23, %21, %14
  %.0 = phi ptr [ %0, %14 ], [ %0, %25 ], [ %0, %23 ], [ %22, %21 ], [ null, %1 ], [ null, %18 ]
  ret ptr %.0
}

; Function Attrs: mustprogress uwtable
declare hidden noundef ptr @_ZN2rw3ps2L19rasterCreateTextureEPNS_6RasterE(ptr noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

!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 20}
!6 = !{!"_ZTSN2rw6RasterE", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !7, i64 64, !7, i64 68, !7, i64 72, !10, i64 80, !7, i64 88, !7, i64 92}
!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 64}
!12 = !{!6, !7, i64 24}
!13 = !{!6, !7, i64 68}
!14 = !{!6, !10, i64 56}
!15 = !{!6, !7, i64 8}
!16 = !{!6, !7, i64 32}
!17 = !{!6, !7, i64 72}
!18 = !{!6, !7, i64 4}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass