; LLVM IR from syby119/CG-projects :: projects/base/texture2d.ll (ZN14ImageTexture2D6uploadEPKviiiijj)

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

@glad_glTexImage2D = external global ptr, align 8
@glad_glPixelStorei = external global ptr, align 8

; 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 void @_ZN14ImageTexture2D6uploadEPKviiiijj(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7) #1 align 2 {
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i64, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store i32 %2, ptr %11, align 4, !tbaa !9
  store i32 %3, ptr %12, align 4, !tbaa !9
  store i32 %4, ptr %13, align 4, !tbaa !9
  store i32 %5, ptr %14, align 4, !tbaa !9
  store i32 %6, ptr %15, align 4, !tbaa !9
  store i32 %7, ptr %16, align 4, !tbaa !9
  %19 = load ptr, ptr %9, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #2
  store i32 1, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #2
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = load i32, ptr %13, align 4, !tbaa !9
  %22 = mul nsw i32 %20, %21
  %23 = sext i32 %22 to i64
  %24 = mul i64 %23, 1
  store i64 %24, ptr %18, align 8, !tbaa !11
  %25 = load i64, ptr %18, align 8, !tbaa !11
  %26 = urem i64 %25, 8
  %27 = icmp eq i64 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %8
  store i32 8, ptr %17, align 4, !tbaa !9
  br label %42

29:                                               ; preds = %8
  %30 = load i64, ptr %18, align 8, !tbaa !11
  %31 = urem i64 %30, 4
  %32 = icmp eq i64 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %29
  store i32 4, ptr %17, align 4, !tbaa !9
  br label %41

34:                                               ; preds = %29
  %35 = load i64, ptr %18, align 8, !tbaa !11
  %36 = urem i64 %35, 2
  %37 = icmp eq i64 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %34
  store i32 2, ptr %17, align 4, !tbaa !9
  br label %40

39:                                               ; preds = %34
  store i32 1, ptr %17, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %39, %38
  br label %41

41:                                               ; preds = %40, %33
  br label %42

42:                                               ; preds = %41, %28
  %43 = load ptr, ptr @glad_glPixelStorei, align 8, !tbaa !5
  %44 = load i32, ptr %17, align 4, !tbaa !9
  call void %43(i32 noundef 3317, i32 noundef %44)
  %45 = load ptr, ptr @glad_glTexImage2D, align 8, !tbaa !5
  %46 = load i32, ptr %14, align 4, !tbaa !9
  %47 = load i32, ptr %11, align 4, !tbaa !9
  %48 = load i32, ptr %12, align 4, !tbaa !9
  %49 = load i32, ptr %15, align 4, !tbaa !9
  %50 = load i32, ptr %16, align 4, !tbaa !9
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  call void %45(i32 noundef 3553, i32 noundef 0, i32 noundef %46, i32 noundef %47, i32 noundef %48, i32 noundef 0, i32 noundef %49, i32 noundef %50, ptr noundef %51)
  %52 = load ptr, ptr @glad_glPixelStorei, align 8, !tbaa !5
  call void %52(i32 noundef 3317, i32 noundef 4)
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #2
  ret void
}

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 = { 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, !12, i64 0}
!12 = !{!"long", !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"

@glad_glTexImage2D = external local_unnamed_addr global ptr, align 8
@glad_glPixelStorei = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14ImageTexture2D6uploadEPKviiiijj(ptr nocapture noundef nonnull readnone align 8 dereferenceable(48) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7) local_unnamed_addr #0 align 2 {
  %9 = mul nsw i32 %4, %2
  %10 = zext i32 %9 to i64
  %11 = and i64 %10, 7
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %19, label %13

13:                                               ; preds = %8
  %14 = and i64 %10, 3
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %19, label %16

16:                                               ; preds = %13
  %17 = and i64 %10, 1
  %18 = icmp eq i64 %17, 0
  %. = select i1 %18, i32 2, i32 1
  br label %19

19:                                               ; preds = %16, %13, %8
  %.0 = phi i32 [ 8, %8 ], [ 4, %13 ], [ %., %16 ]
  %20 = load ptr, ptr @glad_glPixelStorei, align 8, !tbaa !5
  tail call void %20(i32 noundef 3317, i32 noundef %.0)
  %21 = load ptr, ptr @glad_glTexImage2D, align 8, !tbaa !5
  tail call void %21(i32 noundef 3553, i32 noundef 0, i32 noundef %5, i32 noundef %2, i32 noundef %3, i32 noundef 0, i32 noundef %6, i32 noundef %7, ptr noundef %1)
  %22 = load ptr, ptr @glad_glPixelStorei, align 8, !tbaa !5
  tail call void %22(i32 noundef 3317, i32 noundef 4)
  ret void
}

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

!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"}


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