; LLVM IR from aap/librw :: src/d3d/d3d.ll (ZN2rw3d3d12rasterCreateEPNS_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::Error" = type { i32, i32 }
%"struct.rw::Raster" = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, i32, i32, i32, ptr, i32, i32 }

@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

; 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: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw3d3d12rasterCreateEPNS_6RasterE(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %"struct.rw::Error", align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_ZN2rw3d3dL15rasterSetFormatEPNS_6RasterE(ptr noundef %7)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %8, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %"struct.rw::Raster", ptr %9, i32 0, i32 5
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %18, label %13

13:                                               ; preds = %1
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %"struct.rw::Raster", ptr %14, i32 0, i32 6
  %16 = load i32, ptr %15, align 8, !tbaa !12
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %25

18:                                               ; preds = %13, %1
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.rw::Raster", ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = or i32 %21, 128
  store i32 %22, ptr %20, align 8, !tbaa !13
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %"struct.rw::Raster", ptr %23, i32 0, i32 8
  store i32 0, ptr %24, align 8, !tbaa !14
  br label %51

25:                                               ; preds = %13
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.rw::Raster", ptr %26, i32 0, i32 2
  %28 = load i32, ptr %27, align 8, !tbaa !13
  %29 = and i32 %28, 128
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %25
  br label %51

32:                                               ; preds = %25
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.rw::Raster", ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !15
  switch i32 %35, label %39 [
    i32 0, label %36
    i32 4, label %36
  ]

36:                                               ; preds = %32, %32
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = call noundef ptr @_ZN2rw3d3dL19rasterCreateTextureEPNS_6RasterE(ptr noundef %37)
  store ptr %38, ptr %4, align 8, !tbaa !5
  br label %50

39:                                               ; preds = %32
  br label %40

40:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %41 = getelementptr inbounds %"struct.rw::Error", ptr %5, i32 0, i32 0
  store i32 2816, ptr %41, align 4, !tbaa !16
  %42 = getelementptr inbounds %"struct.rw::Error", ptr %5, i32 0, i32 1
  store i32 -2147483638, ptr %42, align 4, !tbaa !18
  %43 = load ptr, ptr @stderr, align 8, !tbaa !5
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef @.str.3, ptr noundef @.str.4, i32 noundef 556) #5
  %45 = load ptr, ptr @stderr, align 8, !tbaa !5
  %46 = call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483638)
  %47 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str.5, ptr noundef %46) #5
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef %5)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %48

48:                                               ; preds = %40
  br label %49

49:                                               ; preds = %48
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %73

50:                                               ; preds = %36
  br label %51

51:                                               ; preds = %50, %31, %18
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %"struct.rw::Raster", ptr %52, i32 0, i32 5
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %"struct.rw::Raster", ptr %55, i32 0, i32 12
  store i32 %54, ptr %56, align 8, !tbaa !19
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %"struct.rw::Raster", ptr %57, i32 0, i32 6
  %59 = load i32, ptr %58, align 8, !tbaa !12
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %"struct.rw::Raster", ptr %60, i32 0, i32 13
  store i32 %59, ptr %61, align 4, !tbaa !20
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %"struct.rw::Raster", ptr %62, i32 0, i32 8
  %64 = load i32, ptr %63, align 8, !tbaa !14
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %"struct.rw::Raster", ptr %65, i32 0, i32 14
  store i32 %64, ptr %66, align 8, !tbaa !21
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %"struct.rw::Raster", ptr %67, i32 0, i32 9
  %69 = load ptr, ptr %68, align 8, !tbaa !22
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %"struct.rw::Raster", ptr %70, i32 0, i32 11
  store ptr %69, ptr %71, align 8, !tbaa !23
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %72, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %73

73:                                               ; preds = %51, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %74 = load ptr, ptr %2, align 8
  ret ptr %74
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN2rw3d3dL15rasterSetFormatEPNS_6RasterE(ptr noundef) #2

; Function Attrs: mustprogress uwtable
declare hidden noundef ptr @_ZN2rw3d3dL19rasterCreateTextureEPNS_6RasterE(ptr noundef) #1

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

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

declare void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress 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 #3 = { 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 = { "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 }

!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, !11, i64 20}
!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, !11, i64 24}
!13 = !{!10, !11, i64 8}
!14 = !{!10, !11, i64 32}
!15 = !{!10, !11, i64 4}
!16 = !{!17, !11, i64 0}
!17 = !{!"_ZTSN2rw5ErrorE", !11, i64 0, !11, i64 4}
!18 = !{!17, !11, i64 4}
!19 = !{!10, !11, i64 64}
!20 = !{!10, !11, i64 68}
!21 = !{!10, !11, i64 72}
!22 = !{!10, !6, i64 40}
!23 = !{!10, !6, i64 56}


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

; 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: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw3d3d12rasterCreateEPNS_6RasterE(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca %"struct.rw::Error", align 4
  tail call void @_ZN2rw3d3dL15rasterSetFormatEPNS_6RasterE(ptr noundef %0)
  %3 = getelementptr inbounds i8, ptr %0, i64 20
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %10, label %6

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %15

10:                                               ; preds = %6, %1
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load i32, ptr %11, align 8, !tbaa !12
  %13 = or i32 %12, 128
  store i32 %13, ptr %11, align 8, !tbaa !12
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 0, ptr %14, align 8, !tbaa !13
  br label %31

15:                                               ; preds = %6
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load i32, ptr %16, align 8, !tbaa !12
  %18 = and i32 %17, 128
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %19, label %31

19:                                               ; preds = %15
  %20 = getelementptr inbounds i8, ptr %0, i64 4
  %21 = load i32, ptr %20, align 4, !tbaa !14
  switch i32 %21, label %24 [
    i32 0, label %22
    i32 4, label %22
  ]

22:                                               ; preds = %19, %19
  %23 = tail call noundef ptr @_ZN2rw3d3dL19rasterCreateTextureEPNS_6RasterE(ptr noundef nonnull %0)
  %.pre = load i32, ptr %3, align 4, !tbaa !5
  br label %31

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  store i32 2816, ptr %2, align 4, !tbaa !15
  %25 = getelementptr inbounds i8, ptr %2, i64 4
  store i32 -2147483638, ptr %25, align 4, !tbaa !17
  %26 = load ptr, ptr @stderr, align 8, !tbaa !18
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4, i32 noundef 556) #6
  %28 = load ptr, ptr @stderr, align 8, !tbaa !18
  %29 = tail call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483638)
  %30 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str.5, ptr noundef %29) #6
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef nonnull %2)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  br label %43

31:                                               ; preds = %15, %22, %10
  %32 = phi i32 [ %4, %10 ], [ %4, %15 ], [ %.pre, %22 ]
  %.0 = phi ptr [ %0, %10 ], [ %0, %15 ], [ %23, %22 ]
  %33 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 %32, ptr %33, align 8, !tbaa !19
  %34 = getelementptr inbounds i8, ptr %0, i64 24
  %35 = load i32, ptr %34, align 8, !tbaa !11
  %36 = getelementptr inbounds i8, ptr %0, i64 68
  store i32 %35, ptr %36, align 4, !tbaa !20
  %37 = getelementptr inbounds i8, ptr %0, i64 32
  %38 = load i32, ptr %37, align 8, !tbaa !13
  %39 = getelementptr inbounds i8, ptr %0, i64 72
  store i32 %38, ptr %39, align 8, !tbaa !21
  %40 = getelementptr inbounds i8, ptr %0, i64 40
  %41 = load ptr, ptr %40, align 8, !tbaa !22
  %42 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr %41, ptr %42, align 8, !tbaa !23
  br label %43

43:                                               ; preds = %31, %24
  %.019 = phi ptr [ %.0, %31 ], [ null, %24 ]
  ret ptr %.019
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZN2rw3d3dL15rasterSetFormatEPNS_6RasterE(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare hidden noundef ptr @_ZN2rw3d3dL19rasterCreateTextureEPNS_6RasterE(ptr noundef) local_unnamed_addr #1

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

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

declare void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress 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 #3 = { 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 #4 = { "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 = { 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 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 24}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !7, i64 32}
!14 = !{!6, !7, i64 4}
!15 = !{!16, !7, i64 0}
!16 = !{!"_ZTSN2rw5ErrorE", !7, i64 0, !7, i64 4}
!17 = !{!16, !7, i64 4}
!18 = !{!10, !10, i64 0}
!19 = !{!6, !7, i64 64}
!20 = !{!6, !7, i64 68}
!21 = !{!6, !7, i64 72}
!22 = !{!6, !10, i64 40}
!23 = !{!6, !10, i64 56}


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