; LLVM IR from paroj/gltut :: glsdk/glmesh/source/VertexFormat.ll (ZNK6glmesh12VertexFormat13BindAttributeEmm)

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

%"class.glmesh::AttribDesc" = type { i32, i32, i32, i32 }

@_ZN2gl23EnableVertexAttribArrayE = external global ptr, align 8
@_ZN6glmesh12_GLOBAL__N_118t_vertexUploadTypeE = external hidden global [9 x i32], align 16
@_ZN2gl19VertexAttribPointerE = external global ptr, align 8
@_ZN2gl20VertexAttribIPointerE = external global ptr, align 8
@_ZN2gl20VertexAttribLPointerE = 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 nounwind uwtable
declare dso_local noundef i32 @_ZNK6glmesh10AttribDesc17GetVertexDataTypeEv(ptr noundef nonnull align 4 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6glmesh10AttribDesc14GetAttribIndexEv(ptr noundef nonnull align 4 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i64 } @_ZNK6glmesh12VertexFormat13GetAttribDescEm(ptr noundef nonnull align 8 dereferenceable(56), i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNK6glmesh12VertexFormat19GetAttribByteOffsetEm(ptr noundef nonnull align 8 dereferenceable(56), i64 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6glmesh12VertexFormat13BindAttributeEmm(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 noundef %1, i64 noundef %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %"class.glmesh::AttribDesc", align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !9
  %13 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #3
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = call { i64, i64 } @_ZNK6glmesh12VertexFormat13GetAttribDescEm(ptr noundef nonnull align 8 dereferenceable(56) %13, i64 noundef %14)
  %16 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 0
  %17 = extractvalue { i64, i64 } %15, 0
  store i64 %17, ptr %16, align 4
  %18 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 1
  %19 = extractvalue { i64, i64 } %15, 1
  store i64 %19, ptr %18, align 4
  store ptr %8, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %20 = load i64, ptr %6, align 8, !tbaa !9
  %21 = call noundef i64 @_ZNK6glmesh12VertexFormat19GetAttribByteOffsetEm(ptr noundef nonnull align 8 dereferenceable(56) %13, i64 noundef %20)
  store i64 %21, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = call noundef i32 @_ZNK6glmesh10AttribDesc14GetAttribIndexEv(ptr noundef nonnull align 4 dereferenceable(16) %22)
  store i32 %23, ptr %10, align 4, !tbaa !11
  %24 = load ptr, ptr @_ZN2gl23EnableVertexAttribArrayE, align 8, !tbaa !5
  %25 = load i32, ptr %10, align 4, !tbaa !11
  call void %24(i32 noundef %25)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = call noundef i32 @_ZNK6glmesh10AttribDesc17GetVertexDataTypeEv(ptr noundef nonnull align 4 dereferenceable(16) %26)
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds [9 x i32], ptr @_ZN6glmesh12_GLOBAL__N_118t_vertexUploadTypeE, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !11
  store i32 %30, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = call noundef i32 @_ZNK6glmesh10AttribDesc16GetNumComponentsEv(ptr noundef nonnull align 4 dereferenceable(16) %31)
  store i32 %32, ptr %12, align 4, !tbaa !11
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = call noundef i32 @_ZNK6glmesh10AttribDesc17GetAttribDataTypeEv(ptr noundef nonnull align 4 dereferenceable(16) %33)
  switch i32 %34, label %79 [
    i32 0, label %35
    i32 1, label %46
    i32 2, label %57
    i32 3, label %68
  ]

35:                                               ; preds = %3
  %36 = load ptr, ptr @_ZN2gl19VertexAttribPointerE, align 8, !tbaa !5
  %37 = load i32, ptr %10, align 4, !tbaa !11
  %38 = load i32, ptr %12, align 4, !tbaa !11
  %39 = load i32, ptr %11, align 4, !tbaa !11
  %40 = call noundef i64 @_ZNK6glmesh12VertexFormat17GetVertexByteSizeEv(ptr noundef nonnull align 8 dereferenceable(56) %13)
  %41 = trunc i64 %40 to i32
  %42 = load i64, ptr %5, align 8, !tbaa !9
  %43 = load i64, ptr %9, align 8, !tbaa !9
  %44 = add i64 %42, %43
  %45 = inttoptr i64 %44 to ptr
  call void %36(i32 noundef %37, i32 noundef %38, i32 noundef %39, i8 noundef zeroext 0, i32 noundef %41, ptr noundef %45)
  br label %79

46:                                               ; preds = %3
  %47 = load ptr, ptr @_ZN2gl19VertexAttribPointerE, align 8, !tbaa !5
  %48 = load i32, ptr %10, align 4, !tbaa !11
  %49 = load i32, ptr %12, align 4, !tbaa !11
  %50 = load i32, ptr %11, align 4, !tbaa !11
  %51 = call noundef i64 @_ZNK6glmesh12VertexFormat17GetVertexByteSizeEv(ptr noundef nonnull align 8 dereferenceable(56) %13)
  %52 = trunc i64 %51 to i32
  %53 = load i64, ptr %5, align 8, !tbaa !9
  %54 = load i64, ptr %9, align 8, !tbaa !9
  %55 = add i64 %53, %54
  %56 = inttoptr i64 %55 to ptr
  call void %47(i32 noundef %48, i32 noundef %49, i32 noundef %50, i8 noundef zeroext 1, i32 noundef %52, ptr noundef %56)
  br label %79

57:                                               ; preds = %3
  %58 = load ptr, ptr @_ZN2gl20VertexAttribIPointerE, align 8, !tbaa !5
  %59 = load i32, ptr %10, align 4, !tbaa !11
  %60 = load i32, ptr %12, align 4, !tbaa !11
  %61 = load i32, ptr %11, align 4, !tbaa !11
  %62 = call noundef i64 @_ZNK6glmesh12VertexFormat17GetVertexByteSizeEv(ptr noundef nonnull align 8 dereferenceable(56) %13)
  %63 = trunc i64 %62 to i32
  %64 = load i64, ptr %5, align 8, !tbaa !9
  %65 = load i64, ptr %9, align 8, !tbaa !9
  %66 = add i64 %64, %65
  %67 = inttoptr i64 %66 to ptr
  call void %58(i32 noundef %59, i32 noundef %60, i32 noundef %61, i32 noundef %63, ptr noundef %67)
  br label %79

68:                                               ; preds = %3
  %69 = load ptr, ptr @_ZN2gl20VertexAttribLPointerE, align 8, !tbaa !5
  %70 = load i32, ptr %10, align 4, !tbaa !11
  %71 = load i32, ptr %12, align 4, !tbaa !11
  %72 = load i32, ptr %11, align 4, !tbaa !11
  %73 = call noundef i64 @_ZNK6glmesh12VertexFormat17GetVertexByteSizeEv(ptr noundef nonnull align 8 dereferenceable(56) %13)
  %74 = trunc i64 %73 to i32
  %75 = load i64, ptr %5, align 8, !tbaa !9
  %76 = load i64, ptr %9, align 8, !tbaa !9
  %77 = add i64 %75, %76
  %78 = inttoptr i64 %77 to ptr
  call void %69(i32 noundef %70, i32 noundef %71, i32 noundef %72, i32 noundef %74, ptr noundef %78)
  br label %79

79:                                               ; preds = %68, %57, %46, %35, %3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6glmesh10AttribDesc16GetNumComponentsEv(ptr noundef nonnull align 4 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6glmesh10AttribDesc17GetAttribDataTypeEv(ptr noundef nonnull align 4 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK6glmesh12VertexFormat17GetVertexByteSizeEv(ptr noundef nonnull align 8 dereferenceable(56)) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #2 = { 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 }

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

%"class.glmesh::AttribDesc" = type { i32, i32, i32, i32 }

@_ZN2gl23EnableVertexAttribArrayE = external local_unnamed_addr global ptr, align 8
@_ZN6glmesh12_GLOBAL__N_118t_vertexUploadTypeE = external hidden local_unnamed_addr global [9 x i32], align 16
@_ZN2gl19VertexAttribPointerE = external local_unnamed_addr global ptr, align 8
@_ZN2gl20VertexAttribIPointerE = external local_unnamed_addr global ptr, align 8
@_ZN2gl20VertexAttribLPointerE = external local_unnamed_addr global ptr, align 8

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

; 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 nounwind uwtable
declare dso_local noundef i32 @_ZNK6glmesh10AttribDesc17GetVertexDataTypeEv(ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6glmesh10AttribDesc14GetAttribIndexEv(ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i64 } @_ZNK6glmesh12VertexFormat13GetAttribDescEm(ptr noundef nonnull align 8 dereferenceable(56), i64 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNK6glmesh12VertexFormat19GetAttribByteOffsetEm(ptr noundef nonnull align 8 dereferenceable(56), i64 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6glmesh12VertexFormat13BindAttributeEmm(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #2 align 2 {
  %4 = alloca %"class.glmesh::AttribDesc", align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  %5 = tail call { i64, i64 } @_ZNK6glmesh12VertexFormat13GetAttribDescEm(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 noundef %2)
  %6 = extractvalue { i64, i64 } %5, 0
  store i64 %6, ptr %4, align 8
  %7 = getelementptr inbounds i8, ptr %4, i64 8
  %8 = extractvalue { i64, i64 } %5, 1
  store i64 %8, ptr %7, align 8
  %9 = tail call noundef i64 @_ZNK6glmesh12VertexFormat19GetAttribByteOffsetEm(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 noundef %2)
  %10 = call noundef i32 @_ZNK6glmesh10AttribDesc14GetAttribIndexEv(ptr noundef nonnull align 4 dereferenceable(16) %4)
  %11 = load ptr, ptr @_ZN2gl23EnableVertexAttribArrayE, align 8, !tbaa !5
  call void %11(i32 noundef %10)
  %12 = call noundef i32 @_ZNK6glmesh10AttribDesc17GetVertexDataTypeEv(ptr noundef nonnull align 4 dereferenceable(16) %4)
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds [9 x i32], ptr @_ZN6glmesh12_GLOBAL__N_118t_vertexUploadTypeE, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = call noundef i32 @_ZNK6glmesh10AttribDesc16GetNumComponentsEv(ptr noundef nonnull align 4 dereferenceable(16) %4)
  %17 = call noundef i32 @_ZNK6glmesh10AttribDesc17GetAttribDataTypeEv(ptr noundef nonnull align 4 dereferenceable(16) %4)
  switch i32 %17, label %42 [
    i32 0, label %18
    i32 1, label %24
    i32 2, label %30
    i32 3, label %36
  ]

18:                                               ; preds = %3
  %19 = load ptr, ptr @_ZN2gl19VertexAttribPointerE, align 8, !tbaa !5
  %20 = call noundef i64 @_ZNK6glmesh12VertexFormat17GetVertexByteSizeEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
  %21 = trunc i64 %20 to i32
  %22 = add i64 %9, %1
  %23 = inttoptr i64 %22 to ptr
  call void %19(i32 noundef %10, i32 noundef %16, i32 noundef %15, i8 noundef zeroext 0, i32 noundef %21, ptr noundef %23)
  br label %42

24:                                               ; preds = %3
  %25 = load ptr, ptr @_ZN2gl19VertexAttribPointerE, align 8, !tbaa !5
  %26 = call noundef i64 @_ZNK6glmesh12VertexFormat17GetVertexByteSizeEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
  %27 = trunc i64 %26 to i32
  %28 = add i64 %9, %1
  %29 = inttoptr i64 %28 to ptr
  call void %25(i32 noundef %10, i32 noundef %16, i32 noundef %15, i8 noundef zeroext 1, i32 noundef %27, ptr noundef %29)
  br label %42

30:                                               ; preds = %3
  %31 = load ptr, ptr @_ZN2gl20VertexAttribIPointerE, align 8, !tbaa !5
  %32 = call noundef i64 @_ZNK6glmesh12VertexFormat17GetVertexByteSizeEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
  %33 = trunc i64 %32 to i32
  %34 = add i64 %9, %1
  %35 = inttoptr i64 %34 to ptr
  call void %31(i32 noundef %10, i32 noundef %16, i32 noundef %15, i32 noundef %33, ptr noundef %35)
  br label %42

36:                                               ; preds = %3
  %37 = load ptr, ptr @_ZN2gl20VertexAttribLPointerE, align 8, !tbaa !5
  %38 = call noundef i64 @_ZNK6glmesh12VertexFormat17GetVertexByteSizeEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
  %39 = trunc i64 %38 to i32
  %40 = add i64 %9, %1
  %41 = inttoptr i64 %40 to ptr
  call void %37(i32 noundef %10, i32 noundef %16, i32 noundef %15, i32 noundef %39, ptr noundef %41)
  br label %42

42:                                               ; preds = %36, %30, %24, %18, %3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6glmesh10AttribDesc16GetNumComponentsEv(ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK6glmesh10AttribDesc17GetAttribDataTypeEv(ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK6glmesh12VertexFormat17GetVertexByteSizeEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #2 = { 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 }

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


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