; LLVM IR from erwincoumans/tiny-differentiable-simulator :: src/visualizer/opengl/tiny_gl_render_to_texture.ll (ZN17GLRenderToTexture6enableEv)

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

@gIntelLinuxglDrawBufferWorkaround = external dso_local global i8, align 1
@glad_glBindFramebuffer = external global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [128 x i8], align 1
@__const._ZN17GLRenderToTexture6enableEv.drawBuffers = external hidden unnamed_addr constant [2 x i32], align 4
@glad_glDrawBuffers = external global ptr, align 8
@__const._ZN17GLRenderToTexture6enableEv.drawBuffers.5 = external hidden unnamed_addr constant [2 x i32], align 4
@glad_glDrawBuffer = external global ptr, align 8
@__PRETTY_FUNCTION__._ZN17GLRenderToTexture6enableEv = external hidden unnamed_addr constant [33 x i8], align 1
@glad_glCheckFramebufferStatus = 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN17GLRenderToTexture6enableEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca [2 x i32], align 4
  %5 = alloca [2 x i32], align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #4
  store i8 0, ptr %3, align 1, !tbaa !9
  %7 = load ptr, ptr @glad_glBindFramebuffer, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.GLRenderToTexture, ptr %6, i32 0, i32 1
  %9 = load i32, ptr %8, align 8, !tbaa !11
  call void %7(i32 noundef 36160, i32 noundef %9)
  %10 = getelementptr inbounds %struct.GLRenderToTexture, ptr %6, i32 0, i32 4
  %11 = load i32, ptr %10, align 4, !tbaa !14
  switch i32 %11, label %24 [
    i32 1, label %12
    i32 2, label %15
  ]

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %4, ptr align 4 @__const._ZN17GLRenderToTexture6enableEv.drawBuffers, i64 8, i1 false)
  %13 = load ptr, ptr @glad_glDrawBuffers, align 8, !tbaa !5
  %14 = getelementptr inbounds [2 x i32], ptr %4, i64 0, i64 0
  call void %13(i32 noundef 1, ptr noundef %14)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %25

15:                                               ; preds = %1
  %16 = load i8, ptr @gIntelLinuxglDrawBufferWorkaround, align 1, !tbaa !9, !range !15, !noundef !16
  %17 = trunc i8 %16 to i1
  br i1 %17, label %18, label %21

18:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 4 @__const._ZN17GLRenderToTexture6enableEv.drawBuffers.5, i64 8, i1 false)
  %19 = load ptr, ptr @glad_glDrawBuffers, align 8, !tbaa !5
  %20 = getelementptr inbounds [2 x i32], ptr %5, i64 0, i64 0
  call void %19(i32 noundef 1, ptr noundef %20)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %23

21:                                               ; preds = %15
  %22 = load ptr, ptr @glad_glDrawBuffer, align 8, !tbaa !5
  call void %22(i32 noundef 0)
  br label %23

23:                                               ; preds = %21, %18
  br label %25

24:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.4, i32 noundef 95, ptr noundef @__PRETTY_FUNCTION__._ZN17GLRenderToTexture6enableEv) #5
  unreachable

25:                                               ; preds = %23, %12
  %26 = load ptr, ptr @glad_glCheckFramebufferStatus, align 8, !tbaa !5
  %27 = call i32 %26(i32 noundef 36160)
  %28 = icmp eq i32 %27, 36053
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  store i8 1, ptr %3, align 1, !tbaa !9
  br label %30

30:                                               ; preds = %29, %25
  %31 = load i8, ptr %3, align 1, !tbaa !9, !range !15, !noundef !16
  %32 = trunc i8 %31 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #4
  ret i1 %32
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind }
attributes #5 = { 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 = !{!"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 = !{!12, !13, i64 8}
!12 = !{!"_ZTS17GLRenderToTexture", !13, i64 8, !13, i64 12, !10, i64 16, !13, i64 20}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 20}
!15 = !{i8 0, i8 2}
!16 = !{}


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

@gIntelLinuxglDrawBufferWorkaround = external dso_local local_unnamed_addr global i8, align 1
@glad_glBindFramebuffer = external local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [128 x i8], align 1
@__const._ZN17GLRenderToTexture6enableEv.drawBuffers = external hidden unnamed_addr constant [2 x i32], align 4
@glad_glDrawBuffers = external local_unnamed_addr global ptr, align 8
@__const._ZN17GLRenderToTexture6enableEv.drawBuffers.5 = external hidden unnamed_addr constant [2 x i32], align 4
@glad_glDrawBuffer = external local_unnamed_addr global ptr, align 8
@__PRETTY_FUNCTION__._ZN17GLRenderToTexture6enableEv = external hidden unnamed_addr constant [33 x i8], align 1
@glad_glCheckFramebufferStatus = 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN17GLRenderToTexture6enableEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %0) local_unnamed_addr #2 align 2 {
  %2 = alloca [2 x i32], align 8
  %3 = alloca [2 x i32], align 8
  %4 = load ptr, ptr @glad_glBindFramebuffer, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !9
  tail call void %4(i32 noundef 36160, i32 noundef %6)
  %7 = getelementptr inbounds i8, ptr %0, i64 20
  %8 = load i32, ptr %7, align 4, !tbaa !13
  switch i32 %8, label %20 [
    i32 1, label %9
    i32 2, label %12
  ]

9:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %10 = load i64, ptr @__const._ZN17GLRenderToTexture6enableEv.drawBuffers, align 4
  store i64 %10, ptr %2, align 8
  %11 = load ptr, ptr @glad_glDrawBuffers, align 8, !tbaa !5
  call void %11(i32 noundef 1, ptr noundef nonnull %2)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  br label %21

12:                                               ; preds = %1
  %13 = load i8, ptr @gIntelLinuxglDrawBufferWorkaround, align 1, !tbaa !14, !range !15, !noundef !16
  %14 = trunc nuw i8 %13 to i1
  br i1 %14, label %15, label %18

15:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %16 = load i64, ptr @__const._ZN17GLRenderToTexture6enableEv.drawBuffers.5, align 4
  store i64 %16, ptr %3, align 8
  %17 = load ptr, ptr @glad_glDrawBuffers, align 8, !tbaa !5
  call void %17(i32 noundef 1, ptr noundef nonnull %3)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %21

18:                                               ; preds = %12
  %19 = load ptr, ptr @glad_glDrawBuffer, align 8, !tbaa !5
  tail call void %19(i32 noundef 0)
  br label %21

20:                                               ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4, i32 noundef 95, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN17GLRenderToTexture6enableEv) #4
  unreachable

21:                                               ; preds = %15, %18, %9
  %22 = load ptr, ptr @glad_glCheckFramebufferStatus, align 8, !tbaa !5
  %23 = call i32 %22(i32 noundef 36160)
  %24 = icmp eq i32 %23, 36053
  ret i1 %24
}

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


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