; LLVM IR from aap/librw :: src/gl/gl3raster.ll (ZN2rw3gl312rasterCreateEPNS_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::gl3::Gl3Raster" = type { i32, i32, i32, i32, i32, i8, i8, i8, i8, i8, i8, i8, i32, i32, ptr, ptr }
%"struct.rw::Raster" = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, i32, i32, i32, ptr, i32, i32 }

@_ZN2rw3gl318nativeRasterOffsetE = external dso_local global i32, align 4
@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

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

23:                                               ; preds = %1
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.rw::Raster", ptr %24, i32 0, i32 6
  %26 = load i32, ptr %25, align 8, !tbaa !18
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %35

28:                                               ; preds = %23, %1
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.rw::Raster", ptr %29, i32 0, i32 2
  %31 = load i32, ptr %30, align 8, !tbaa !19
  %32 = or i32 %31, 128
  store i32 %32, ptr %30, align 8, !tbaa !19
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.rw::Raster", ptr %33, i32 0, i32 8
  store i32 0, ptr %34, align 8, !tbaa !20
  br label %57

35:                                               ; preds = %23
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %"struct.rw::Raster", ptr %36, i32 0, i32 2
  %38 = load i32, ptr %37, align 8, !tbaa !19
  %39 = and i32 %38, 128
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %35
  br label %57

42:                                               ; preds = %35
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %"struct.rw::Raster", ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !21
  switch i32 %45, label %46 [
  ]

46:                                               ; preds = %42
  br label %47

47:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %48 = getelementptr inbounds %"struct.rw::Error", ptr %6, i32 0, i32 0
  store i32 2816, ptr %48, align 4, !tbaa !22
  %49 = getelementptr inbounds %"struct.rw::Error", ptr %6, i32 0, i32 1
  store i32 -2147483638, ptr %49, align 4, !tbaa !24
  %50 = load ptr, ptr @stderr, align 8, !tbaa !5
  %51 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %50, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 425) #4
  %52 = load ptr, ptr @stderr, align 8, !tbaa !5
  %53 = call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483638)
  %54 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %52, ptr noundef @.str.2, ptr noundef %53) #4
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef %6)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %55

55:                                               ; preds = %47
  br label %56

56:                                               ; preds = %55
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %79

57:                                               ; preds = %41, %28
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %"struct.rw::Raster", ptr %58, i32 0, i32 5
  %60 = load i32, ptr %59, align 4, !tbaa !16
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %"struct.rw::Raster", ptr %61, i32 0, i32 12
  store i32 %60, ptr %62, align 8, !tbaa !25
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %"struct.rw::Raster", ptr %63, i32 0, i32 6
  %65 = load i32, ptr %64, align 8, !tbaa !18
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %"struct.rw::Raster", ptr %66, i32 0, i32 13
  store i32 %65, ptr %67, align 4, !tbaa !26
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %"struct.rw::Raster", ptr %68, i32 0, i32 8
  %70 = load i32, ptr %69, align 8, !tbaa !20
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %"struct.rw::Raster", ptr %71, i32 0, i32 14
  store i32 %70, ptr %72, align 8, !tbaa !27
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %"struct.rw::Raster", ptr %73, i32 0, i32 9
  %75 = load ptr, ptr %74, align 8, !tbaa !28
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = getelementptr inbounds %"struct.rw::Raster", ptr %76, i32 0, i32 11
  store ptr %75, ptr %77, align 8, !tbaa !29
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %78, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %79

79:                                               ; preds = %57, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %80 = load ptr, ptr %2, align 8
  ret ptr %80
}

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

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

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

declare void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 = { 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, !13, i64 20}
!12 = !{!"_ZTSN2rw3gl39Gl3RasterE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !13, i64 20, !13, i64 21, !13, i64 22, !7, i64 23, !7, i64 24, !7, i64 25, !7, i64 26, !10, i64 28, !10, i64 32, !6, i64 40, !6, i64 48}
!13 = !{!"bool", !7, i64 0}
!14 = !{!12, !13, i64 21}
!15 = !{!12, !7, i64 23}
!16 = !{!17, !10, i64 20}
!17 = !{!"_ZTSN2rw6RasterE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !6, i64 80, !10, i64 88, !10, i64 92}
!18 = !{!17, !10, i64 24}
!19 = !{!17, !10, i64 8}
!20 = !{!17, !10, i64 32}
!21 = !{!17, !10, i64 4}
!22 = !{!23, !10, i64 0}
!23 = !{!"_ZTSN2rw5ErrorE", !10, i64 0, !10, i64 4}
!24 = !{!23, !10, i64 4}
!25 = !{!17, !10, i64 64}
!26 = !{!17, !10, i64 68}
!27 = !{!17, !10, i64 72}
!28 = !{!17, !6, i64 40}
!29 = !{!17, !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 }

@_ZN2rw3gl318nativeRasterOffsetE = external dso_local local_unnamed_addr global i32, align 4
@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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw3gl312rasterCreateEPNS_6RasterE(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca %"struct.rw::Error", align 4
  %3 = load i32, ptr @_ZN2rw3gl318nativeRasterOffsetE, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds i8, ptr %0, i64 %4
  %6 = getelementptr inbounds i8, ptr %5, i64 20
  store i8 0, ptr %6, align 4, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %5, i64 21
  store i8 0, ptr %7, align 1, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %5, i64 23
  store i8 1, ptr %8, align 1, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %0, i64 20
  %10 = load i32, ptr %9, align 4, !tbaa !15
  %11 = icmp eq i32 %10, 0
  %.phi.trans.insert.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 24
  %.pre.pre = load i32, ptr %.phi.trans.insert.phi.trans.insert, align 8, !tbaa !17
  br i1 %11, label %._crit_edge22, label %12

12:                                               ; preds = %1
  %13 = icmp eq i32 %.pre.pre, 0
  br i1 %13, label %._crit_edge22, label %18

._crit_edge22:                                    ; preds = %1, %12
  %.pre = phi i32 [ 0, %12 ], [ %.pre.pre, %1 ]
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load i32, ptr %14, align 8, !tbaa !18
  %16 = or i32 %15, 128
  store i32 %16, ptr %14, align 8, !tbaa !18
  %17 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 0, ptr %17, align 8, !tbaa !19
  br label %29

18:                                               ; preds = %12
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  %20 = load i32, ptr %19, align 8, !tbaa !18
  %21 = and i32 %20, 128
  %.not = icmp eq i32 %21, 0
  br i1 %.not, label %22, label %._crit_edge

._crit_edge:                                      ; preds = %18
  %.phi.trans.insert20 = getelementptr inbounds i8, ptr %0, i64 32
  %.pre21 = load i32, ptr %.phi.trans.insert20, align 8, !tbaa !19
  br label %29

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  store i32 2816, ptr %2, align 4, !tbaa !20
  %23 = getelementptr inbounds i8, ptr %2, i64 4
  store i32 -2147483638, ptr %23, align 4, !tbaa !22
  %24 = load ptr, ptr @stderr, align 8, !tbaa !23
  %25 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 425) #5
  %26 = load ptr, ptr @stderr, align 8, !tbaa !23
  %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) #5
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef nonnull %2)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  br label %38

29:                                               ; preds = %._crit_edge, %._crit_edge22
  %30 = phi i32 [ %.pre21, %._crit_edge ], [ 0, %._crit_edge22 ]
  %31 = phi i32 [ %.pre.pre, %._crit_edge ], [ %.pre, %._crit_edge22 ]
  %32 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 %10, ptr %32, align 8, !tbaa !24
  %33 = getelementptr inbounds i8, ptr %0, i64 68
  store i32 %31, ptr %33, align 4, !tbaa !25
  %34 = getelementptr inbounds i8, ptr %0, i64 72
  store i32 %30, ptr %34, align 8, !tbaa !26
  %35 = getelementptr inbounds i8, ptr %0, i64 40
  %36 = load ptr, ptr %35, align 8, !tbaa !27
  %37 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr %36, ptr %37, align 8, !tbaa !28
  br label %38

38:                                               ; preds = %29, %22
  %.0 = phi ptr [ %0, %29 ], [ null, %22 ]
  ret ptr %.0
}

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

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

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

declare void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 = { nounwind }
attributes #5 = { 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 20}
!10 = !{!"_ZTSN2rw3gl39Gl3RasterE", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !11, i64 20, !11, i64 21, !11, i64 22, !7, i64 23, !7, i64 24, !7, i64 25, !7, i64 26, !6, i64 28, !6, i64 32, !12, i64 40, !12, i64 48}
!11 = !{!"bool", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !11, i64 21}
!14 = !{!10, !7, i64 23}
!15 = !{!16, !6, i64 20}
!16 = !{!"_ZTSN2rw6RasterE", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !6, i64 64, !6, i64 68, !6, i64 72, !12, i64 80, !6, i64 88, !6, i64 92}
!17 = !{!16, !6, i64 24}
!18 = !{!16, !6, i64 8}
!19 = !{!16, !6, i64 32}
!20 = !{!21, !6, i64 0}
!21 = !{!"_ZTSN2rw5ErrorE", !6, i64 0, !6, i64 4}
!22 = !{!21, !6, i64 4}
!23 = !{!12, !12, i64 0}
!24 = !{!16, !6, i64 64}
!25 = !{!16, !6, i64 68}
!26 = !{!16, !6, i64 72}
!27 = !{!16, !12, i64 40}
!28 = !{!16, !12, i64 56}


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