; LLVM IR from danginsburg/opengles3-book :: Chapter_14/Shadows (Shadows)

; 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, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, %struct.ESMatrix, %struct.ESMatrix, %struct.ESMatrix, %struct.ESMatrix, [3 x float], [3 x float] }
%struct.ESMatrix = type { [4 x [4 x float]] }

; 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: nounwind uwtable
define dso_local i32 @InitShadowMap(ptr noundef %0) #1 {
  %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 i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.ESContext, ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %10, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !13
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.UserData, ptr %11, i32 0, i32 10
  store i32 1024, ptr %12, align 4, !tbaa !14
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.UserData, ptr %13, i32 0, i32 9
  store i32 1024, ptr %14, align 4, !tbaa !17
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.UserData, ptr %15, i32 0, i32 7
  call void @glGenTextures(i32 noundef 1, ptr noundef %16)
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.UserData, ptr %17, i32 0, i32 7
  %19 = load i32, ptr %18, align 4, !tbaa !18
  call void @glBindTexture(i32 noundef 3553, i32 noundef %19)
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 10240, i32 noundef 9729)
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 10241, i32 noundef 9729)
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 10242, i32 noundef 33071)
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 10243, i32 noundef 33071)
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 34892, i32 noundef 34894)
  call void @glTexParameteri(i32 noundef 3553, i32 noundef 34893, i32 noundef 515)
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.UserData, ptr %20, i32 0, i32 9
  %22 = load i32, ptr %21, align 4, !tbaa !17
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.UserData, ptr %23, i32 0, i32 10
  %25 = load i32, ptr %24, align 4, !tbaa !14
  call void @glTexImage2D(i32 noundef 3553, i32 noundef 0, i32 noundef 33190, i32 noundef %22, i32 noundef %25, i32 noundef 0, i32 noundef 6402, i32 noundef 5125, ptr noundef null)
  call void @glBindTexture(i32 noundef 3553, i32 noundef 0)
  call void @glGetIntegerv(i32 noundef 36006, ptr noundef %6)
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.UserData, ptr %26, i32 0, i32 8
  call void @glGenFramebuffers(i32 noundef 1, ptr noundef %27)
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.UserData, ptr %28, i32 0, i32 8
  %30 = load i32, ptr %29, align 4, !tbaa !19
  call void @glBindFramebuffer(i32 noundef 36160, i32 noundef %30)
  call void @glDrawBuffers(i32 noundef 1, ptr noundef %5)
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.UserData, ptr %31, i32 0, i32 7
  %33 = load i32, ptr %32, align 4, !tbaa !18
  call void @glFramebufferTexture2D(i32 noundef 36160, i32 noundef 36096, i32 noundef 3553, i32 noundef %33, i32 noundef 0)
  call void @glActiveTexture(i32 noundef 33984)
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.UserData, ptr %34, i32 0, i32 7
  %36 = load i32, ptr %35, align 4, !tbaa !18
  call void @glBindTexture(i32 noundef 3553, i32 noundef %36)
  %37 = call i32 @glCheckFramebufferStatus(i32 noundef 36160)
  %38 = icmp ne i32 36053, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %42

40:                                               ; preds = %1
  %41 = load i32, ptr %6, align 4, !tbaa !13
  call void @glBindFramebuffer(i32 noundef 36160, i32 noundef %41)
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %42

42:                                               ; preds = %40, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %43 = load i32, ptr %2, align 4
  ret i32 %43
}

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

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

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

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

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

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

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

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

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

declare void @glActiveTexture(i32 noundef) #2

declare i32 @glCheckFramebufferStatus(i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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/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 40}
!15 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !16, i64 72, !16, i64 136, !16, i64 200, !16, i64 264, !7, i64 328, !7, i64 340}
!16 = !{!"", !7, i64 0}
!17 = !{!15, !11, i64 36}
!18 = !{!15, !11, i64 28}
!19 = !{!15, !11, i64 32}


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

; 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: nounwind uwtable
define dso_local range(i32 0, 2) i32 @InitShadowMap(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %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) #3
  store i32 0, ptr %2, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  store i32 0, ptr %3, align 4, !tbaa !12
  %6 = getelementptr inbounds i8, ptr %5, i64 40
  store i32 1024, ptr %6, align 4, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %5, i64 36
  store i32 1024, ptr %7, align 4, !tbaa !16
  %8 = getelementptr inbounds i8, ptr %5, i64 28
  tail call void @glGenTextures(i32 noundef 1, ptr noundef nonnull %8) #3
  %9 = load i32, ptr %8, align 4, !tbaa !17
  tail call void @glBindTexture(i32 noundef 3553, i32 noundef %9) #3
  tail call void @glTexParameteri(i32 noundef 3553, i32 noundef 10240, i32 noundef 9729) #3
  tail call void @glTexParameteri(i32 noundef 3553, i32 noundef 10241, i32 noundef 9729) #3
  tail call void @glTexParameteri(i32 noundef 3553, i32 noundef 10242, i32 noundef 33071) #3
  tail call void @glTexParameteri(i32 noundef 3553, i32 noundef 10243, i32 noundef 33071) #3
  tail call void @glTexParameteri(i32 noundef 3553, i32 noundef 34892, i32 noundef 34894) #3
  tail call void @glTexParameteri(i32 noundef 3553, i32 noundef 34893, i32 noundef 515) #3
  %10 = load i32, ptr %7, align 4, !tbaa !16
  %11 = load i32, ptr %6, align 4, !tbaa !13
  tail call void @glTexImage2D(i32 noundef 3553, i32 noundef 0, i32 noundef 33190, i32 noundef %10, i32 noundef %11, i32 noundef 0, i32 noundef 6402, i32 noundef 5125, ptr noundef null) #3
  tail call void @glBindTexture(i32 noundef 3553, i32 noundef 0) #3
  call void @glGetIntegerv(i32 noundef 36006, ptr noundef nonnull %3) #3
  %12 = getelementptr inbounds i8, ptr %5, i64 32
  call void @glGenFramebuffers(i32 noundef 1, ptr noundef nonnull %12) #3
  %13 = load i32, ptr %12, align 4, !tbaa !18
  call void @glBindFramebuffer(i32 noundef 36160, i32 noundef %13) #3
  call void @glDrawBuffers(i32 noundef 1, ptr noundef nonnull %2) #3
  %14 = load i32, ptr %8, align 4, !tbaa !17
  call void @glFramebufferTexture2D(i32 noundef 36160, i32 noundef 36096, i32 noundef 3553, i32 noundef %14, i32 noundef 0) #3
  call void @glActiveTexture(i32 noundef 33984) #3
  %15 = load i32, ptr %8, align 4, !tbaa !17
  call void @glBindTexture(i32 noundef 3553, i32 noundef %15) #3
  %16 = call i32 @glCheckFramebufferStatus(i32 noundef 36160) #3
  %.not = icmp eq i32 %16, 36053
  br i1 %.not, label %17, label %19

17:                                               ; preds = %1
  %18 = load i32, ptr %3, align 4, !tbaa !12
  call void @glBindFramebuffer(i32 noundef 36160, i32 noundef %18) #3
  br label %19

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

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

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

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

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

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

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

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

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

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

declare void @glActiveTexture(i32 noundef) local_unnamed_addr #2

declare i32 @glCheckFramebufferStatus(i32 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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, !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 40}
!14 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !15, i64 72, !15, i64 136, !15, i64 200, !15, i64 264, !8, i64 328, !8, i64 340}
!15 = !{!"", !8, i64 0}
!16 = !{!14, !10, i64 36}
!17 = !{!14, !10, i64 28}
!18 = !{!14, !10, i64 32}


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