; LLVM IR from danginsburg/opengles3-book :: Chapter_11/MRTs (MRTs)

; 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.ESContext = type { ptr, ptr, i32, i32, ptr, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.UserData = type { i32, i32, [4 x i32], i32, i32 }

@__const.InitFBO.attachments = external hidden unnamed_addr constant [4 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @InitFBO(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca [4 x i32], align 16
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.ESContext, ptr %9, i32 0, i32 1
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %11, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %7, ptr align 16 @__const.InitFBO.attachments, i64 16, i1 false)
  call void @glGetIntegerv(i32 noundef 36006, ptr noundef %6)
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.UserData, ptr %12, i32 0, i32 1
  call void @glGenFramebuffers(i32 noundef 1, ptr noundef %13)
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.UserData, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !14
  call void @glBindFramebuffer(i32 noundef 36160, i32 noundef %16)
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.UserData, ptr %17, i32 0, i32 3
  store i32 400, ptr %18, align 4, !tbaa !16
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.UserData, ptr %19, i32 0, i32 4
  store i32 400, ptr %20, align 4, !tbaa !17
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.UserData, ptr %21, i32 0, i32 2
  %23 = getelementptr inbounds [4 x i32], ptr %22, i64 0, i64 0
  call void @glGenTextures(i32 noundef 4, ptr noundef %23)
  store i32 0, ptr %5, align 4, !tbaa !13
  br label %24

24:                                               ; preds = %50, %1
  %25 = load i32, ptr %5, align 4, !tbaa !13
  %26 = icmp slt i32 %25, 4
  br i1 %26, label %27, label %53

27:                                               ; preds = %24
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.UserData, ptr %28, i32 0, i32 2
  %30 = load i32, ptr %5, align 4, !tbaa !13
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [4 x i32], ptr %29, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !13
  call void @glBindTexture(i32 noundef 3553, i32 noundef %33)
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.UserData, ptr %34, i32 0, i32 3
  %36 = load i32, ptr %35, align 4, !tbaa !16
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.UserData, ptr %37, i32 0, i32 4
  %39 = load i32, ptr %38, align 4, !tbaa !17
  call void @glTexImage2D(i32 noundef 3553, i32 noundef 0, i32 noundef 6408, i32 noundef %36, i32 noundef %39, i32 noundef 0, i32 noundef 6408, i32 noundef 5121, ptr noundef null)
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 10241, i32 noundef 9728)
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 10240, i32 noundef 9728)
  %40 = load i32, ptr %5, align 4, !tbaa !13
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [4 x i32], ptr %7, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !13
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.UserData, ptr %44, i32 0, i32 2
  %46 = load i32, ptr %5, align 4, !tbaa !13
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [4 x i32], ptr %45, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !13
  call void @glFramebufferTexture2D(i32 noundef 36009, i32 noundef %43, i32 noundef 3553, i32 noundef %49, i32 noundef 0)
  br label %50

50:                                               ; preds = %27
  %51 = load i32, ptr %5, align 4, !tbaa !13
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %5, align 4, !tbaa !13
  br label %24, !llvm.loop !18

53:                                               ; preds = %24
  %54 = getelementptr inbounds [4 x i32], ptr %7, i64 0, i64 0
  call void @glDrawBuffers(i32 noundef 4, ptr noundef %54)
  %55 = call i32 @glCheckFramebufferStatus(i32 noundef 36160)
  %56 = icmp ne i32 36053, %55
  br i1 %56, label %57, label %58

57:                                               ; preds = %53
  store i32 0, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %60

58:                                               ; preds = %53
  %59 = load i32, ptr %6, align 4, !tbaa !13
  call void @glBindFramebuffer(i32 noundef 36160, i32 noundef %59)
  store i32 1, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %60

60:                                               ; preds = %58, %57
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %61 = load i32, ptr %2, align 4
  ret i32 %61
}

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

; 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) #2

declare void @glGetIntegerv(i32 noundef, ptr noundef) #3

declare void @glGenFramebuffers(i32 noundef, ptr noundef) #3

declare void @glBindFramebuffer(i32 noundef, i32 noundef) #3

declare void @glGenTextures(i32 noundef, ptr noundef) #3

declare void @glBindTexture(i32 noundef, i32 noundef) #3

declare void @glTexImage2D(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) #3

declare void @glTexParameteri(i32 noundef, i32 noundef, i32 noundef) #3

declare void @glFramebufferTexture2D(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #3

declare void @glDrawBuffers(i32 noundef, ptr noundef) #3

declare i32 @glCheckFramebufferStatus(i32 noundef) #3

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 #4 = { 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/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"ESContext", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !6, i64 24, !12, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !11, i64 4}
!15 = !{!"", !11, i64 0, !11, i64 4, !7, i64 8, !11, i64 24, !11, i64 28}
!16 = !{!15, !11, i64 24}
!17 = !{!15, !11, i64 28}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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

@__const.InitFBO.attachments = external hidden unnamed_addr constant [4 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @InitFBO(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca i32, align 4
  %3 = alloca [4 x i32], align 16
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  store i32 0, ptr %2, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %3, ptr noundef nonnull align 16 dereferenceable(16) @__const.InitFBO.attachments, i64 16, i1 false)
  call void @glGetIntegerv(i32 noundef 36006, ptr noundef nonnull %2) #4
  %6 = getelementptr inbounds i8, ptr %5, i64 4
  call void @glGenFramebuffers(i32 noundef 1, ptr noundef nonnull %6) #4
  %7 = load i32, ptr %6, align 4, !tbaa !13
  call void @glBindFramebuffer(i32 noundef 36160, i32 noundef %7) #4
  %8 = getelementptr inbounds i8, ptr %5, i64 24
  store i32 400, ptr %8, align 4, !tbaa !15
  %9 = getelementptr inbounds i8, ptr %5, i64 28
  store i32 400, ptr %9, align 4, !tbaa !16
  %10 = getelementptr inbounds i8, ptr %5, i64 8
  call void @glGenTextures(i32 noundef 4, ptr noundef nonnull %10) #4
  %11 = load i32, ptr %10, align 4, !tbaa !12
  call void @glBindTexture(i32 noundef 3553, i32 noundef %11) #4
  %12 = load i32, ptr %8, align 4, !tbaa !15
  %13 = load i32, ptr %9, align 4, !tbaa !16
  call void @glTexImage2D(i32 noundef 3553, i32 noundef 0, i32 noundef 6408, i32 noundef %12, i32 noundef %13, i32 noundef 0, i32 noundef 6408, i32 noundef 5121, ptr noundef null) #4
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 10241, i32 noundef 9728) #4
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 10240, i32 noundef 9728) #4
  %14 = load i32, ptr %3, align 16, !tbaa !12
  %15 = load i32, ptr %10, align 4, !tbaa !12
  call void @glFramebufferTexture2D(i32 noundef 36009, i32 noundef %14, i32 noundef 3553, i32 noundef %15, i32 noundef 0) #4
  %16 = getelementptr inbounds i8, ptr %5, i64 12
  %17 = load i32, ptr %16, align 4, !tbaa !12
  call void @glBindTexture(i32 noundef 3553, i32 noundef %17) #4
  %18 = load i32, ptr %8, align 4, !tbaa !15
  %19 = load i32, ptr %9, align 4, !tbaa !16
  call void @glTexImage2D(i32 noundef 3553, i32 noundef 0, i32 noundef 6408, i32 noundef %18, i32 noundef %19, i32 noundef 0, i32 noundef 6408, i32 noundef 5121, ptr noundef null) #4
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 10241, i32 noundef 9728) #4
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 10240, i32 noundef 9728) #4
  %20 = getelementptr inbounds i8, ptr %3, i64 4
  %21 = load i32, ptr %20, align 4, !tbaa !12
  %22 = load i32, ptr %16, align 4, !tbaa !12
  call void @glFramebufferTexture2D(i32 noundef 36009, i32 noundef %21, i32 noundef 3553, i32 noundef %22, i32 noundef 0) #4
  %23 = getelementptr inbounds i8, ptr %5, i64 16
  %24 = load i32, ptr %23, align 4, !tbaa !12
  call void @glBindTexture(i32 noundef 3553, i32 noundef %24) #4
  %25 = load i32, ptr %8, align 4, !tbaa !15
  %26 = load i32, ptr %9, align 4, !tbaa !16
  call void @glTexImage2D(i32 noundef 3553, i32 noundef 0, i32 noundef 6408, i32 noundef %25, i32 noundef %26, i32 noundef 0, i32 noundef 6408, i32 noundef 5121, ptr noundef null) #4
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 10241, i32 noundef 9728) #4
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 10240, i32 noundef 9728) #4
  %27 = getelementptr inbounds i8, ptr %3, i64 8
  %28 = load i32, ptr %27, align 8, !tbaa !12
  %29 = load i32, ptr %23, align 4, !tbaa !12
  call void @glFramebufferTexture2D(i32 noundef 36009, i32 noundef %28, i32 noundef 3553, i32 noundef %29, i32 noundef 0) #4
  %30 = getelementptr inbounds i8, ptr %5, i64 20
  %31 = load i32, ptr %30, align 4, !tbaa !12
  call void @glBindTexture(i32 noundef 3553, i32 noundef %31) #4
  %32 = load i32, ptr %8, align 4, !tbaa !15
  %33 = load i32, ptr %9, align 4, !tbaa !16
  call void @glTexImage2D(i32 noundef 3553, i32 noundef 0, i32 noundef 6408, i32 noundef %32, i32 noundef %33, i32 noundef 0, i32 noundef 6408, i32 noundef 5121, ptr noundef null) #4
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 10241, i32 noundef 9728) #4
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 10240, i32 noundef 9728) #4
  %34 = getelementptr inbounds i8, ptr %3, i64 12
  %35 = load i32, ptr %34, align 4, !tbaa !12
  %36 = load i32, ptr %30, align 4, !tbaa !12
  call void @glFramebufferTexture2D(i32 noundef 36009, i32 noundef %35, i32 noundef 3553, i32 noundef %36, i32 noundef 0) #4
  call void @glDrawBuffers(i32 noundef 4, ptr noundef nonnull %3) #4
  %37 = call i32 @glCheckFramebufferStatus(i32 noundef 36160) #4
  %.not = icmp eq i32 %37, 36053
  br i1 %.not, label %38, label %40

38:                                               ; preds = %1
  %39 = load i32, ptr %2, align 4, !tbaa !12
  call void @glBindFramebuffer(i32 noundef 36160, i32 noundef %39) #4
  br label %40

40:                                               ; preds = %1, %38
  %.015 = phi i32 [ 1, %38 ], [ 0, %1 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  ret i32 %.015
}

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

; Function Attrs: mustprogress 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) #2

declare void @glGetIntegerv(i32 noundef, ptr noundef) local_unnamed_addr #3

declare void @glGenFramebuffers(i32 noundef, ptr noundef) local_unnamed_addr #3

declare void @glBindFramebuffer(i32 noundef, i32 noundef) local_unnamed_addr #3

declare void @glGenTextures(i32 noundef, ptr noundef) local_unnamed_addr #3

declare void @glBindTexture(i32 noundef, i32 noundef) local_unnamed_addr #3

declare void @glTexImage2D(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

declare void @glTexParameteri(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

declare void @glFramebufferTexture2D(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

declare void @glDrawBuffers(i32 noundef, ptr noundef) local_unnamed_addr #3

declare i32 @glCheckFramebufferStatus(i32 noundef) local_unnamed_addr #3

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 #4 = { 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, !7, i64 8}
!6 = !{!"ESContext", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !7, i64 24, !11, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !10, i64 4}
!14 = !{!"", !10, i64 0, !10, i64 4, !8, i64 8, !10, i64 24, !10, i64 28}
!15 = !{!14, !10, i64 24}
!16 = !{!14, !10, i64 28}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass