; LLVM IR from kajott/GIPS :: src/gl_util.ll (ZN6GLutil3FBO3endEv)

; 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.GLutil::FBO" = type { i32, i32 }

@_ZN6GLutil11initializedE = external dso_local global i8, align 1
@glad_glBindFramebuffer = external global ptr, align 8
@glad_glFramebufferTexture2D = external global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6GLutil3FBO3endEv(ptr noundef nonnull align 4 dereferenceable(8) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  %4 = load i8, ptr @_ZN6GLutil11initializedE, align 1, !tbaa !9, !range !11, !noundef !12
  %5 = trunc i8 %4 to i1
  br i1 %5, label %6, label %14

6:                                                ; preds = %1
  %7 = getelementptr inbounds %"class.GLutil::FBO", ptr %3, i32 0, i32 0
  %8 = load i32, ptr %7, align 4, !tbaa !13
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %14

10:                                               ; preds = %6
  %11 = getelementptr inbounds %"class.GLutil::FBO", ptr %3, i32 0, i32 1
  %12 = load i32, ptr %11, align 4, !tbaa !16
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %15, label %14

14:                                               ; preds = %10, %6, %1
  br label %19

15:                                               ; preds = %10
  %16 = load ptr, ptr @glad_glFramebufferTexture2D, align 8, !tbaa !5
  call void %16(i32 noundef 36160, i32 noundef 36064, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %17 = load ptr, ptr @glad_glBindFramebuffer, align 8, !tbaa !5
  call void %17(i32 noundef 36160, i32 noundef 0)
  %18 = getelementptr inbounds %"class.GLutil::FBO", ptr %3, i32 0, i32 1
  store i32 0, ptr %18, align 4, !tbaa !16
  br label %19

19:                                               ; preds = %15, %14
  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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTSN6GLutil3FBOE", !15, i64 0, !15, i64 4}
!15 = !{!"int", !7, i64 0}
!16 = !{!14, !15, i64 4}


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

@_ZN6GLutil11initializedE = external dso_local local_unnamed_addr global i8, align 1
@glad_glBindFramebuffer = external local_unnamed_addr global ptr, align 8
@glad_glFramebufferTexture2D = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6GLutil3FBO3endEv(ptr nocapture noundef nonnull align 4 dereferenceable(8) %0) local_unnamed_addr #0 align 2 {
  %2 = load i8, ptr @_ZN6GLutil11initializedE, align 1, !tbaa !5, !range !9, !noundef !10
  %3 = trunc nuw i8 %2 to i1
  %4 = load i32, ptr %0, align 4
  %.not = icmp ne i32 %4, 0
  %or.cond.not = select i1 %3, i1 %.not, i1 false
  br i1 %or.cond.not, label %5, label %11

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %.not1 = icmp eq i32 %7, 0
  br i1 %.not1, label %11, label %8

8:                                                ; preds = %5
  %9 = load ptr, ptr @glad_glFramebufferTexture2D, align 8, !tbaa !14
  tail call void %9(i32 noundef 36160, i32 noundef 36064, i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %10 = load ptr, ptr @glad_glBindFramebuffer, align 8, !tbaa !14
  tail call void %10(i32 noundef 36160, i32 noundef 0)
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %11

11:                                               ; preds = %1, %5, %8
  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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !13, i64 4}
!12 = !{!"_ZTSN6GLutil3FBOE", !13, i64 0, !13, i64 4}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !7, i64 0}


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