; LLVM IR from ChenyangZhang-cs/iMLBench :: KNN/co-run&zero-copy/clutils.ll (Z13cl_allocImagemmcm)

; 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._cl_image_format = type { i32, i32 }

@_ZL7context = external hidden global ptr, align 8
@.str.20 = external hidden unnamed_addr constant [47 x i8], align 1
@_ZZ13cl_allocImagemmcmE15allocationCount = external hidden global i32, align 4
@_ZZ13cl_allocImagemmcmE14allocationSize = external hidden global i64, align 8
@.str.21 = external hidden unnamed_addr constant [68 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

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

; 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 @_Z13cl_allocImagemmcm(i64 noundef %0, i64 noundef %1, i8 noundef signext %2, i64 noundef %3) #3 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i8, align 1
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca %struct._cl_image_format, align 4
  store i64 %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !5
  store i8 %2, ptr %7, align 1, !tbaa !9
  store i64 %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store i64 0, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %13 = getelementptr inbounds %struct._cl_image_format, ptr %12, i32 0, i32 0
  store i32 4272, ptr %13, align 4, !tbaa !10
  %14 = load i8, ptr %7, align 1, !tbaa !9
  %15 = sext i8 %14 to i32
  switch i32 %15, label %20 [
    i32 102, label %16
    i32 105, label %18
  ]

16:                                               ; preds = %4
  store i64 4, ptr %11, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._cl_image_format, ptr %12, i32 0, i32 1
  store i32 4318, ptr %17, align 4, !tbaa !13
  br label %22

18:                                               ; preds = %4
  store i64 4, ptr %11, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._cl_image_format, ptr %12, i32 0, i32 1
  store i32 4313, ptr %19, align 4, !tbaa !13
  br label %22

20:                                               ; preds = %4
  %21 = call i32 (ptr, ...) @printf(ptr noundef @.str.20)
  call void @exit(i32 noundef -1) #6
  unreachable

22:                                               ; preds = %18, %16
  %23 = load i32, ptr @_ZZ13cl_allocImagemmcmE15allocationCount, align 4, !tbaa !14
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr @_ZZ13cl_allocImagemmcmE15allocationCount, align 4, !tbaa !14
  %25 = load i64, ptr %5, align 8, !tbaa !5
  %26 = load i64, ptr %6, align 8, !tbaa !5
  %27 = mul i64 %25, %26
  %28 = load i64, ptr %11, align 8, !tbaa !5
  %29 = mul i64 %27, %28
  %30 = load i64, ptr @_ZZ13cl_allocImagemmcmE14allocationSize, align 8, !tbaa !5
  %31 = add i64 %30, %29
  store i64 %31, ptr @_ZZ13cl_allocImagemmcmE14allocationSize, align 8, !tbaa !5
  %32 = load ptr, ptr @_ZL7context, align 8, !tbaa !15
  %33 = load i64, ptr %8, align 8, !tbaa !5
  %34 = load i64, ptr %6, align 8, !tbaa !5
  %35 = load i64, ptr %5, align 8, !tbaa !5
  %36 = call ptr @clCreateImage2D(ptr noundef %32, i64 noundef %33, ptr noundef %12, i64 noundef %34, i64 noundef %35, i64 noundef 0, ptr noundef null, ptr noundef %10)
  store ptr %36, ptr %9, align 8, !tbaa !15
  %37 = load i32, ptr %10, align 4, !tbaa !14
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %42

39:                                               ; preds = %22
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.21)
  call void @_Z26printSupportedImageFormatsv()
  %41 = call i32 @getchar()
  call void @exit(i32 noundef -1) #6
  unreachable

42:                                               ; preds = %22
  %43 = load ptr, ptr %9, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  ret ptr %43
}

declare ptr @clCreateImage2D(ptr noundef, i64 noundef, ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z26printSupportedImageFormatsv() #3

; Function Attrs: inlinehint mustprogress uwtable
declare i32 @getchar() #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { noreturn 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 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { noreturn 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"_ZTS16_cl_image_format", !12, i64 0, !12, i64 4}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !12, i64 4}
!14 = !{!12, !12, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"any pointer", !7, i64 0}


; 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._cl_image_format = type { i32, i32 }

@_ZL7context = external hidden local_unnamed_addr global ptr, align 8
@.str.20 = external hidden unnamed_addr constant [47 x i8], align 1
@_ZZ13cl_allocImagemmcmE15allocationCount = external hidden local_unnamed_addr global i32, align 4
@_ZZ13cl_allocImagemmcmE14allocationSize = external hidden local_unnamed_addr global i64, align 8
@.str.21 = external hidden unnamed_addr constant [68 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: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

; 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 @_Z13cl_allocImagemmcm(i64 noundef %0, i64 noundef %1, i8 noundef signext %2, i64 noundef %3) local_unnamed_addr #3 {
  %5 = alloca i32, align 4
  %6 = alloca %struct._cl_image_format, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #6
  store i32 4272, ptr %6, align 4, !tbaa !5
  switch i8 %2, label %8 [
    i8 102, label %10
    i8 105, label %7
  ]

7:                                                ; preds = %4
  br label %10

8:                                                ; preds = %4
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.20)
  tail call void @exit(i32 noundef -1) #7
  unreachable

10:                                               ; preds = %4, %7
  %.sink = phi i32 [ 4313, %7 ], [ 4318, %4 ]
  %11 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 %.sink, ptr %11, align 4, !tbaa !10
  %12 = load i32, ptr @_ZZ13cl_allocImagemmcmE15allocationCount, align 4, !tbaa !11
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr @_ZZ13cl_allocImagemmcmE15allocationCount, align 4, !tbaa !11
  %14 = shl i64 %0, 2
  %15 = mul i64 %14, %1
  %16 = load i64, ptr @_ZZ13cl_allocImagemmcmE14allocationSize, align 8, !tbaa !12
  %17 = add i64 %16, %15
  store i64 %17, ptr @_ZZ13cl_allocImagemmcmE14allocationSize, align 8, !tbaa !12
  %18 = load ptr, ptr @_ZL7context, align 8, !tbaa !14
  %19 = call ptr @clCreateImage2D(ptr noundef %18, i64 noundef %3, ptr noundef nonnull %6, i64 noundef %1, i64 noundef %0, i64 noundef 0, ptr noundef null, ptr noundef nonnull %5)
  %20 = load i32, ptr %5, align 4, !tbaa !11
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %24, label %21

21:                                               ; preds = %10
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.21)
  call void @_Z26printSupportedImageFormatsv()
  %23 = call i32 @getchar()
  call void @exit(i32 noundef -1) #7
  unreachable

24:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #6
  ret ptr %19
}

declare ptr @clCreateImage2D(ptr noundef, i64 noundef, ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z26printSupportedImageFormatsv() local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nofree nounwind uwtable
declare noundef i32 @getchar() local_unnamed_addr #5

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { noreturn 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 = { 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 #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 = { inlinehint mustprogress nofree 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 #6 = { nounwind }
attributes #7 = { noreturn 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 = !{!"_ZTS16_cl_image_format", !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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !8, i64 0}


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