; LLVM IR from aap/librw :: src/image.ll (ZN2rw5Image8allocateEv)

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

@.str.4 = external hidden unnamed_addr constant [72 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [72 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw5Image8allocateEv(ptr noundef nonnull align 8 dereferenceable(40) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  %4 = getelementptr inbounds %"struct.rw::Image", ptr %3, i32 0, i32 6
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %26

7:                                                ; preds = %1
  %8 = getelementptr inbounds %"struct.rw::Image", ptr %3, i32 0, i32 1
  %9 = load i32, ptr %8, align 4, !tbaa !12
  %10 = getelementptr inbounds %"struct.rw::Image", ptr %3, i32 0, i32 4
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = mul nsw i32 %9, %11
  %13 = getelementptr inbounds %"struct.rw::Image", ptr %3, i32 0, i32 5
  store i32 %12, ptr %13, align 4, !tbaa !14
  %14 = getelementptr inbounds %"struct.rw::Image", ptr %3, i32 0, i32 5
  %15 = load i32, ptr %14, align 4, !tbaa !14
  %16 = getelementptr inbounds %"struct.rw::Image", ptr %3, i32 0, i32 2
  %17 = load i32, ptr %16, align 8, !tbaa !15
  %18 = mul nsw i32 %15, %17
  %19 = sext i32 %18 to i64
  %20 = mul i64 %19, 1
  %21 = call noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef %20, i32 noundef 196632, ptr noundef @.str.4)
  %22 = getelementptr inbounds %"struct.rw::Image", ptr %3, i32 0, i32 6
  store ptr %21, ptr %22, align 8, !tbaa !9
  %23 = getelementptr inbounds %"struct.rw::Image", ptr %3, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !16
  %25 = or i32 %24, 1
  store i32 %25, ptr %23, align 8, !tbaa !16
  br label %26

26:                                               ; preds = %7, %1
  %27 = getelementptr inbounds %"struct.rw::Image", ptr %3, i32 0, i32 7
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = icmp eq ptr %28, null
  br i1 %29, label %30, label %51

30:                                               ; preds = %26
  %31 = getelementptr inbounds %"struct.rw::Image", ptr %3, i32 0, i32 3
  %32 = load i32, ptr %31, align 4, !tbaa !18
  %33 = icmp eq i32 %32, 4
  br i1 %33, label %38, label %34

34:                                               ; preds = %30
  %35 = getelementptr inbounds %"struct.rw::Image", ptr %3, i32 0, i32 3
  %36 = load i32, ptr %35, align 4, !tbaa !18
  %37 = icmp eq i32 %36, 8
  br i1 %37, label %38, label %47

38:                                               ; preds = %34, %30
  %39 = getelementptr inbounds %"struct.rw::Image", ptr %3, i32 0, i32 3
  %40 = load i32, ptr %39, align 4, !tbaa !18
  %41 = shl i32 1, %40
  %42 = mul nsw i32 %41, 4
  %43 = sext i32 %42 to i64
  %44 = mul i64 %43, 1
  %45 = call noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef %44, i32 noundef 196632, ptr noundef @.str.5)
  %46 = getelementptr inbounds %"struct.rw::Image", ptr %3, i32 0, i32 7
  store ptr %45, ptr %46, align 8, !tbaa !17
  br label %47

47:                                               ; preds = %38, %34
  %48 = getelementptr inbounds %"struct.rw::Image", ptr %3, i32 0, i32 0
  %49 = load i32, ptr %48, align 8, !tbaa !16
  %50 = or i32 %49, 2
  store i32 %50, ptr %48, align 8, !tbaa !16
  br label %51

51:                                               ; preds = %47, %26
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef, i32 noundef, ptr noundef) #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 = { inlinehint 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 24}
!10 = !{!"_ZTSN2rw5ImageE", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !6, i64 24, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !11, i64 16}
!14 = !{!10, !11, i64 20}
!15 = !{!10, !11, i64 8}
!16 = !{!10, !11, i64 0}
!17 = !{!10, !6, i64 32}
!18 = !{!10, !11, i64 12}


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

@.str.4 = external hidden unnamed_addr constant [72 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [72 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw5Image8allocateEv(ptr nocapture noundef nonnull align 8 dereferenceable(40) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %19

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load i32, ptr %8, align 8, !tbaa !12
  %10 = mul nsw i32 %9, %7
  %11 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %10, ptr %11, align 4, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load i32, ptr %12, align 8, !tbaa !14
  %14 = mul nsw i32 %13, %10
  %15 = sext i32 %14 to i64
  %16 = tail call noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef %15, i32 noundef 196632, ptr noundef nonnull @.str.4)
  store ptr %16, ptr %2, align 8, !tbaa !5
  %17 = load i32, ptr %0, align 8, !tbaa !15
  %18 = or i32 %17, 1
  store i32 %18, ptr %0, align 8, !tbaa !15
  br label %19

19:                                               ; preds = %5, %1
  %20 = getelementptr inbounds i8, ptr %0, i64 32
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %33

23:                                               ; preds = %19
  %24 = getelementptr inbounds i8, ptr %0, i64 12
  %25 = load i32, ptr %24, align 4, !tbaa !17
  switch i32 %25, label %30 [
    i32 4, label %26
    i32 8, label %26
  ]

26:                                               ; preds = %23, %23
  %27 = shl nuw nsw i32 4, %25
  %28 = zext nneg i32 %27 to i64
  %29 = tail call noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef %28, i32 noundef 196632, ptr noundef nonnull @.str.5)
  store ptr %29, ptr %20, align 8, !tbaa !16
  br label %30

30:                                               ; preds = %23, %26
  %31 = load i32, ptr %0, align 8, !tbaa !15
  %32 = or i32 %31, 2
  store i32 %32, ptr %0, align 8, !tbaa !15
  br label %33

33:                                               ; preds = %30, %19
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #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 = { inlinehint 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, !10, i64 24}
!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 4}
!12 = !{!6, !7, i64 16}
!13 = !{!6, !7, i64 20}
!14 = !{!6, !7, i64 8}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !10, i64 32}
!17 = !{!6, !7, i64 12}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass