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

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

@_ZN2rw5Image12numAllocatedE = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [72 x i8], align 1
@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 [57 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw5Image6createEiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca %"struct.rw::Error", align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %11 = call noundef ptr @_ZN2rw10malloc_LOCEmjPKc(i64 noundef 40, i32 noundef 196632, ptr noundef @.str)
  store ptr %11, ptr %8, align 8, !tbaa !9
  %12 = load ptr, ptr %8, align 8, !tbaa !9
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %25

14:                                               ; preds = %3
  br label %15

15:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %16 = getelementptr inbounds %"struct.rw::Error", ptr %9, i32 0, i32 0
  store i32 24, ptr %16, align 4, !tbaa !11
  %17 = getelementptr inbounds %"struct.rw::Error", ptr %9, i32 0, i32 1
  store i32 -2147483646, ptr %17, align 4, !tbaa !13
  %18 = load ptr, ptr @stderr, align 8, !tbaa !9
  %19 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 55) #5
  %20 = load ptr, ptr @stderr, align 8, !tbaa !9
  %21 = call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483646, i64 noundef 40)
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef @.str.3, ptr noundef %21) #5
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef %9)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %23

23:                                               ; preds = %15
  br label %24

24:                                               ; preds = %23
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %56

25:                                               ; preds = %3
  %26 = load i32, ptr @_ZN2rw5Image12numAllocatedE, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr @_ZN2rw5Image12numAllocatedE, align 4, !tbaa !5
  %28 = load ptr, ptr %8, align 8, !tbaa !9
  %29 = getelementptr inbounds %"struct.rw::Image", ptr %28, i32 0, i32 0
  store i32 0, ptr %29, align 8, !tbaa !14
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !9
  %32 = getelementptr inbounds %"struct.rw::Image", ptr %31, i32 0, i32 1
  store i32 %30, ptr %32, align 4, !tbaa !16
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !9
  %35 = getelementptr inbounds %"struct.rw::Image", ptr %34, i32 0, i32 2
  store i32 %33, ptr %35, align 8, !tbaa !17
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = load ptr, ptr %8, align 8, !tbaa !9
  %38 = getelementptr inbounds %"struct.rw::Image", ptr %37, i32 0, i32 3
  store i32 %36, ptr %38, align 4, !tbaa !18
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = icmp slt i32 %39, 8
  br i1 %40, label %41, label %42

41:                                               ; preds = %25
  br label %45

42:                                               ; preds = %25
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = sdiv i32 %43, 8
  br label %45

45:                                               ; preds = %42, %41
  %46 = phi i32 [ 1, %41 ], [ %44, %42 ]
  %47 = load ptr, ptr %8, align 8, !tbaa !9
  %48 = getelementptr inbounds %"struct.rw::Image", ptr %47, i32 0, i32 4
  store i32 %46, ptr %48, align 8, !tbaa !19
  %49 = load ptr, ptr %8, align 8, !tbaa !9
  %50 = getelementptr inbounds %"struct.rw::Image", ptr %49, i32 0, i32 5
  store i32 0, ptr %50, align 4, !tbaa !20
  %51 = load ptr, ptr %8, align 8, !tbaa !9
  %52 = getelementptr inbounds %"struct.rw::Image", ptr %51, i32 0, i32 6
  store ptr null, ptr %52, align 8, !tbaa !21
  %53 = load ptr, ptr %8, align 8, !tbaa !9
  %54 = getelementptr inbounds %"struct.rw::Image", ptr %53, i32 0, i32 7
  store ptr null, ptr %54, align 8, !tbaa !22
  %55 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %55, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %56

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw10malloc_LOCEmjPKc(i64 noundef, i32 noundef, ptr noundef) #2

; 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

; 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 = { 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" }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTSN2rw5ErrorE", !6, i64 0, !6, i64 4}
!13 = !{!12, !6, i64 4}
!14 = !{!15, !6, i64 0}
!15 = !{!"_ZTSN2rw5ImageE", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !10, i64 24, !10, i64 32}
!16 = !{!15, !6, i64 4}
!17 = !{!15, !6, i64 8}
!18 = !{!15, !6, i64 12}
!19 = !{!15, !6, i64 16}
!20 = !{!15, !6, i64 20}
!21 = !{!15, !10, i64 24}
!22 = !{!15, !10, i64 32}


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

@_ZN2rw5Image12numAllocatedE = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [72 x i8], align 1
@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 [57 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw5Image6createEiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = alloca %"struct.rw::Error", align 4
  %5 = tail call noundef ptr @_ZN2rw10malloc_LOCEmjPKc(i64 noundef 40, i32 noundef 196632, ptr noundef nonnull @.str)
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %14

7:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #6
  store i32 24, ptr %4, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 -2147483646, ptr %8, align 4, !tbaa !10
  %9 = load ptr, ptr @stderr, align 8, !tbaa !11
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 55) #7
  %11 = load ptr, ptr @stderr, align 8, !tbaa !11
  %12 = tail call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483646, i64 noundef 40)
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str.3, ptr noundef %12) #7
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #6
  br label %24

14:                                               ; preds = %3
  %15 = load i32, ptr @_ZN2rw5Image12numAllocatedE, align 4, !tbaa !13
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr @_ZN2rw5Image12numAllocatedE, align 4, !tbaa !13
  store i32 0, ptr %5, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %5, i64 4
  store i32 %0, ptr %17, align 4, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %5, i64 8
  store i32 %1, ptr %18, align 8, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %5, i64 12
  store i32 %2, ptr %19, align 4, !tbaa !18
  %20 = icmp slt i32 %2, 8
  %21 = lshr i32 %2, 3
  %spec.select = select i1 %20, i32 1, i32 %21
  %22 = getelementptr inbounds i8, ptr %5, i64 16
  store i32 %spec.select, ptr %22, align 8, !tbaa !19
  %23 = getelementptr inbounds i8, ptr %5, i64 20
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(20) %23, i8 0, i64 20, i1 false)
  br label %24

24:                                               ; preds = %14, %7
  ret ptr %5
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw10malloc_LOCEmjPKc(i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; 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

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

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

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 = { 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" }
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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }
attributes #7 = { 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 0}
!6 = !{!"_ZTSN2rw5ErrorE", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !7, i64 0}
!15 = !{!"_ZTSN2rw5ImageE", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !12, i64 24, !12, i64 32}
!16 = !{!15, !7, i64 4}
!17 = !{!15, !7, i64 8}
!18 = !{!15, !7, i64 12}
!19 = !{!15, !7, i64 16}


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