; LLVM IR from paroj/gltut :: glsdk/glmesh/source/StreamBuffer.ll (ZN6glmesh12StreamBuffer3Map7ReleaseEv)

; 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::StreamBuffer::Map" = type { ptr, ptr, i64 }
%"class.glmesh::StreamBuffer" = type { i32, i64, i64, i8, i32 }

@_ZN2gl10BindBufferE = external global ptr, align 8
@_ZN2gl11UnmapBufferE = 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 noundef zeroext i1 @_ZN6glmesh12StreamBuffer3Map7ReleaseEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1 align 2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8
  %6 = getelementptr inbounds %"class.glmesh::StreamBuffer::Map", ptr %5, i32 0, i32 0
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = icmp ne ptr %7, null
  br i1 %8, label %10, label %9

9:                                                ; preds = %1
  store i1 false, ptr %2, align 1
  br label %37

10:                                               ; preds = %1
  %11 = getelementptr inbounds %"class.glmesh::StreamBuffer::Map", ptr %5, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds %"class.glmesh::StreamBuffer", ptr %12, i32 0, i32 3
  store i8 0, ptr %13, align 8, !tbaa !12
  %14 = getelementptr inbounds %"class.glmesh::StreamBuffer::Map", ptr %5, i32 0, i32 2
  %15 = load i64, ptr %14, align 8, !tbaa !16
  %16 = getelementptr inbounds %"class.glmesh::StreamBuffer::Map", ptr %5, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds %"class.glmesh::StreamBuffer", ptr %17, i32 0, i32 2
  %19 = load i64, ptr %18, align 8, !tbaa !17
  %20 = add i64 %19, %15
  store i64 %20, ptr %18, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  store i8 1, ptr %4, align 1, !tbaa !18
  %21 = load ptr, ptr @_ZN2gl10BindBufferE, align 8, !tbaa !5
  %22 = getelementptr inbounds %"class.glmesh::StreamBuffer::Map", ptr %5, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds %"class.glmesh::StreamBuffer", ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !19
  call void %21(i32 noundef 34962, i32 noundef %25)
  %26 = load ptr, ptr @_ZN2gl11UnmapBufferE, align 8, !tbaa !5
  %27 = call noundef zeroext i8 %26(i32 noundef 34962)
  %28 = zext i8 %27 to i32
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %10
  store i8 0, ptr %4, align 1, !tbaa !18
  br label %31

31:                                               ; preds = %30, %10
  %32 = load ptr, ptr @_ZN2gl10BindBufferE, align 8, !tbaa !5
  call void %32(i32 noundef 34962, i32 noundef 0)
  %33 = getelementptr inbounds %"class.glmesh::StreamBuffer::Map", ptr %5, i32 0, i32 0
  store ptr null, ptr %33, align 8, !tbaa !9
  %34 = getelementptr inbounds %"class.glmesh::StreamBuffer::Map", ptr %5, i32 0, i32 1
  store ptr null, ptr %34, align 8, !tbaa !20
  %35 = load i8, ptr %4, align 1, !tbaa !18, !range !21, !noundef !22
  %36 = trunc i8 %35 to i1
  store i1 %36, ptr %2, align 1
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  br label %37

37:                                               ; preds = %31, %9
  %38 = load i1, ptr %2, align 1
  ret i1 %38
}

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, !6, i64 0}
!10 = !{!"_ZTSN6glmesh12StreamBuffer3MapE", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !15, i64 24}
!13 = !{!"_ZTSN6glmesh12StreamBufferE", !14, i64 0, !11, i64 8, !11, i64 16, !15, i64 24, !14, i64 28}
!14 = !{!"int", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{!10, !11, i64 16}
!17 = !{!13, !11, i64 16}
!18 = !{!15, !15, i64 0}
!19 = !{!13, !14, i64 0}
!20 = !{!10, !6, i64 8}
!21 = !{i8 0, i8 2}
!22 = !{}


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

@_ZN2gl10BindBufferE = external local_unnamed_addr global ptr, align 8
@_ZN2gl11UnmapBufferE = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN6glmesh12StreamBuffer3Map7ReleaseEv(ptr nocapture noundef nonnull align 8 dereferenceable(24) %0) local_unnamed_addr #0 align 2 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %16, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %2, i64 24
  store i8 0, ptr %4, align 8, !tbaa !11
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load i64, ptr %5, align 8, !tbaa !15
  %7 = getelementptr inbounds i8, ptr %2, i64 16
  %8 = load i64, ptr %7, align 8, !tbaa !16
  %9 = add i64 %8, %6
  store i64 %9, ptr %7, align 8, !tbaa !16
  %10 = load ptr, ptr @_ZN2gl10BindBufferE, align 8, !tbaa !17
  %11 = load i32, ptr %2, align 8, !tbaa !18
  tail call void %10(i32 noundef 34962, i32 noundef %11)
  %12 = load ptr, ptr @_ZN2gl11UnmapBufferE, align 8, !tbaa !17
  %13 = tail call noundef zeroext i8 %12(i32 noundef 34962)
  %14 = icmp ne i8 %13, 0
  %15 = load ptr, ptr @_ZN2gl10BindBufferE, align 8, !tbaa !17
  tail call void %15(i32 noundef 34962, i32 noundef 0)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %0, i8 0, i64 16, i1 false)
  br label %16

16:                                               ; preds = %1, %3
  %.02 = phi i1 [ %14, %3 ], [ false, %1 ]
  ret i1 %.02
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }

!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 = !{!"_ZTSN6glmesh12StreamBuffer3MapE", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!12, !14, i64 24}
!12 = !{!"_ZTSN6glmesh12StreamBufferE", !13, i64 0, !10, i64 8, !10, i64 16, !14, i64 24, !13, i64 28}
!13 = !{!"int", !8, i64 0}
!14 = !{!"bool", !8, i64 0}
!15 = !{!6, !10, i64 16}
!16 = !{!12, !10, i64 16}
!17 = !{!7, !7, i64 0}
!18 = !{!12, !13, i64 0}


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