; LLVM IR from paroj/gltut :: Tut 17 Spotlight on Textures/DoubleProjection.ll (Z8keyboardhii)

; 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::ViewPole" = type <{ %"class.glutil::ViewProvider", %"struct.glutil::ViewData", %"struct.glutil::ViewScale", %"struct.glutil::ViewData", i32, i8, i8, [2 x i8], i32, float, %"struct.glm::detail::tvec2", %"struct.glm::detail::tquat", [4 x i8] }>
%"class.glutil::ViewProvider" = type { ptr }
%"struct.glutil::ViewScale" = type { float, float, float, float, float, float, float }
%"struct.glutil::ViewData" = type { %"struct.glm::detail::tvec3", %"struct.glm::detail::tquat", float, float }
%"struct.glm::detail::tvec3" = type { %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { float, float, float }
%"struct.glm::detail::tvec2" = type { %union.anon.2 }
%union.anon.2 = type { %struct.anon.3 }
%struct.anon.3 = type { i32, i32 }
%"struct.glm::detail::tquat" = type { float, float, float, float }
%"class.Framework::Timer" = type { i32, float, i8, i8, float, float }

@g_viewPole = external dso_local global %"class.glutil::ViewPole", align 8
@g_persViewPole = external dso_local global %"class.glutil::ViewPole", align 8
@g_pScene = external dso_local global ptr, align 8
@g_timer = external dso_local global %"class.Framework::Timer", align 4
@_ZTISt9exception = external constant ptr
@g_bDrawCameraPos = external dso_local global i8, align 1
@g_bDepthClampProj = external dso_local global i8, align 1
@.str.20 = external hidden unnamed_addr constant [30 x i8], align 1

; 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
declare dso_local void @_Z17LoadAndSetupScenev() #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind memory(none)
declare i32 @llvm.eh.typeid.for.p0(ptr) #3

declare ptr @__cxa_begin_catch(ptr)

declare i32 @printf(ptr noundef, ...) #4

declare void @__cxa_end_catch()

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #5

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8keyboardhii(i8 noundef zeroext %0, i32 noundef %1, i32 noundef %2) #6 personality ptr @__gxx_personality_v0 {
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store i8 %0, ptr %4, align 1, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !8
  store i32 %2, ptr %6, align 4, !tbaa !8
  %10 = load i8, ptr %4, align 1, !tbaa !5
  %11 = zext i8 %10 to i32
  switch i32 %11, label %56 [
    i32 27, label %12
    i32 32, label %17
    i32 116, label %18
    i32 121, label %23
    i32 112, label %28
    i32 13, label %30
  ]

12:                                               ; preds = %3
  %13 = load ptr, ptr @g_pScene, align 8, !tbaa !10
  %14 = icmp eq ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @_ZN9Framework5SceneD1Ev(ptr noundef nonnull align 8 dereferenceable(8) %13) #8
  call void @_ZdlPvm(ptr noundef %13, i64 noundef 8) #9
  br label %16

16:                                               ; preds = %15, %12
  store ptr null, ptr @g_pScene, align 8, !tbaa !10
  call void @glutLeaveMainLoop()
  br label %58

17:                                               ; preds = %3
  call void @_ZN6glutil8ViewPole5ResetEv(ptr noundef nonnull align 8 dereferenceable(148) @g_persViewPole)
  br label %56

18:                                               ; preds = %3
  %19 = load i8, ptr @g_bDrawCameraPos, align 1, !tbaa !12, !range !14, !noundef !15
  %20 = trunc i8 %19 to i1
  %21 = xor i1 %20, true
  %22 = zext i1 %21 to i8
  store i8 %22, ptr @g_bDrawCameraPos, align 1, !tbaa !12
  br label %56

23:                                               ; preds = %3
  %24 = load i8, ptr @g_bDepthClampProj, align 1, !tbaa !12, !range !14, !noundef !15
  %25 = trunc i8 %24 to i1
  %26 = xor i1 %25, true
  %27 = zext i1 %26 to i8
  store i8 %27, ptr @g_bDepthClampProj, align 1, !tbaa !12
  br label %56

28:                                               ; preds = %3
  %29 = call noundef zeroext i1 @_ZN9Framework5Timer11TogglePauseEv(ptr noundef nonnull align 4 dereferenceable(20) @g_timer)
  br label %56

30:                                               ; preds = %3
  invoke void @_Z17LoadAndSetupScenev()
          to label %31 unwind label %32

31:                                               ; preds = %30
  br label %55

32:                                               ; preds = %30
  %33 = landingpad { ptr, i32 }
          catch ptr @_ZTISt9exception
  %34 = extractvalue { ptr, i32 } %33, 0
  store ptr %34, ptr %7, align 8
  %35 = extractvalue { ptr, i32 } %33, 1
  store i32 %35, ptr %8, align 4
  br label %36

36:                                               ; preds = %32
  %37 = load i32, ptr %8, align 4
  %38 = call i32 @llvm.eh.typeid.for.p0(ptr @_ZTISt9exception) #8
  %39 = icmp eq i32 %37, %38
  br i1 %39, label %40, label %59

40:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #8
  %41 = load ptr, ptr %7, align 8
  %42 = call ptr @__cxa_begin_catch(ptr %41) #8
  store ptr %42, ptr %9, align 8
  %43 = load ptr, ptr %9, align 8, !tbaa !10
  %44 = load ptr, ptr %43, align 8, !tbaa !16
  %45 = getelementptr inbounds ptr, ptr %44, i64 2
  %46 = load ptr, ptr %45, align 8
  %47 = call noundef ptr %46(ptr noundef nonnull align 8 dereferenceable(8) %43) #8
  %48 = invoke i32 (ptr, ...) @printf(ptr noundef @.str.20, ptr noundef %47)
          to label %49 unwind label %50

49:                                               ; preds = %40
  call void @__cxa_end_catch()
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #8
  br label %58

50:                                               ; preds = %40
  %51 = landingpad { ptr, i32 }
          cleanup
  %52 = extractvalue { ptr, i32 } %51, 0
  store ptr %52, ptr %7, align 8
  %53 = extractvalue { ptr, i32 } %51, 1
  store i32 %53, ptr %8, align 4
  invoke void @__cxa_end_catch()
          to label %54 unwind label %64

54:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #8
  br label %59

55:                                               ; preds = %31
  br label %56

56:                                               ; preds = %55, %28, %23, %18, %17, %3
  %57 = load i8, ptr %4, align 1, !tbaa !5
  call void @_ZN6glutil8ViewPole9CharPressEc(ptr noundef nonnull align 8 dereferenceable(148) @g_viewPole, i8 noundef signext %57)
  br label %58

58:                                               ; preds = %56, %49, %16
  ret void

59:                                               ; preds = %54, %36
  %60 = load ptr, ptr %7, align 8
  %61 = load i32, ptr %8, align 4
  %62 = insertvalue { ptr, i32 } poison, ptr %60, 0
  %63 = insertvalue { ptr, i32 } %62, i32 %61, 1
  resume { ptr, i32 } %63

64:                                               ; preds = %50
  %65 = landingpad { ptr, i32 }
          catch ptr null
  %66 = extractvalue { ptr, i32 } %65, 0
  call void @__clang_call_terminate(ptr %66) #10
  unreachable
}

; Function Attrs: nounwind
declare void @_ZN9Framework5SceneD1Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #7

declare void @glutLeaveMainLoop() #4

declare void @_ZN6glutil8ViewPole5ResetEv(ptr noundef nonnull align 8 dereferenceable(148)) #4

declare noundef zeroext i1 @_ZN9Framework5Timer11TogglePauseEv(ptr noundef nonnull align 4 dereferenceable(20)) #4

declare void @_ZN6glutil8ViewPole9CharPressEc(ptr noundef nonnull align 8 dereferenceable(148), i8 noundef signext) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { nobuiltin 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 #3 = { nounwind memory(none) }
attributes #4 = { "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 #5 = { noinline noreturn nounwind uwtable "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 #6 = { 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 #7 = { 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 #8 = { nounwind }
attributes #9 = { builtin nounwind }
attributes #10 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"bool", !6, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!17, !17, i64 0}
!17 = !{!"vtable pointer", !7, i64 0}


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

%"class.glutil::ViewPole" = type <{ %"class.glutil::ViewProvider", %"struct.glutil::ViewData", %"struct.glutil::ViewScale", %"struct.glutil::ViewData", i32, i8, i8, [2 x i8], i32, float, %"struct.glm::detail::tvec2", %"struct.glm::detail::tquat", [4 x i8] }>
%"class.glutil::ViewProvider" = type { ptr }
%"struct.glutil::ViewScale" = type { float, float, float, float, float, float, float }
%"struct.glutil::ViewData" = type { %"struct.glm::detail::tvec3", %"struct.glm::detail::tquat", float, float }
%"struct.glm::detail::tvec3" = type { %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { float, float, float }
%"struct.glm::detail::tvec2" = type { %union.anon.2 }
%union.anon.2 = type { %struct.anon.3 }
%struct.anon.3 = type { i32, i32 }
%"struct.glm::detail::tquat" = type { float, float, float, float }
%"class.Framework::Timer" = type { i32, float, i8, i8, float, float }

@g_viewPole = external dso_local global %"class.glutil::ViewPole", align 8
@g_persViewPole = external dso_local global %"class.glutil::ViewPole", align 8
@g_pScene = external dso_local local_unnamed_addr global ptr, align 8
@g_timer = external dso_local global %"class.Framework::Timer", align 4
@_ZTISt9exception = external constant ptr
@g_bDrawCameraPos = external dso_local local_unnamed_addr global i8, align 1
@g_bDepthClampProj = external dso_local local_unnamed_addr global i8, align 1
@.str.20 = external hidden unnamed_addr constant [30 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z17LoadAndSetupScenev() local_unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nofree nosync nounwind memory(none)
declare i32 @llvm.eh.typeid.for.p0(ptr) #2

declare ptr @__cxa_begin_catch(ptr) local_unnamed_addr

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

declare void @__cxa_end_catch() local_unnamed_addr

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8keyboardhii(i8 noundef zeroext %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #4 personality ptr @__gxx_personality_v0 {
  switch i8 %0, label %32 [
    i8 27, label %4
    i8 32, label %9
    i8 116, label %10
    i8 121, label %13
    i8 112, label %16
    i8 13, label %18
  ]

4:                                                ; preds = %3
  %5 = load ptr, ptr @g_pScene, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %8, label %7

7:                                                ; preds = %4
  tail call void @_ZN9Framework5SceneD1Ev(ptr noundef nonnull align 8 dereferenceable(8) %5) #7
  tail call void @_ZdlPvm(ptr noundef nonnull %5, i64 noundef 8) #8
  br label %8

8:                                                ; preds = %7, %4
  store ptr null, ptr @g_pScene, align 8, !tbaa !5
  tail call void @glutLeaveMainLoop()
  br label %33

9:                                                ; preds = %3
  tail call void @_ZN6glutil8ViewPole5ResetEv(ptr noundef nonnull align 8 dereferenceable(148) @g_persViewPole)
  br label %32

10:                                               ; preds = %3
  %11 = load i8, ptr @g_bDrawCameraPos, align 1, !tbaa !9, !range !11, !noundef !12
  %12 = xor i8 %11, 1
  store i8 %12, ptr @g_bDrawCameraPos, align 1, !tbaa !9
  br label %32

13:                                               ; preds = %3
  %14 = load i8, ptr @g_bDepthClampProj, align 1, !tbaa !9, !range !11, !noundef !12
  %15 = xor i8 %14, 1
  store i8 %15, ptr @g_bDepthClampProj, align 1, !tbaa !9
  br label %32

16:                                               ; preds = %3
  %17 = tail call noundef zeroext i1 @_ZN9Framework5Timer11TogglePauseEv(ptr noundef nonnull align 4 dereferenceable(20) @g_timer)
  br label %32

18:                                               ; preds = %3
  invoke void @_Z17LoadAndSetupScenev()
          to label %32 unwind label %19

19:                                               ; preds = %18
  %20 = landingpad { ptr, i32 }
          catch ptr @_ZTISt9exception
  %21 = extractvalue { ptr, i32 } %20, 1
  %22 = tail call i32 @llvm.eh.typeid.for.p0(ptr nonnull @_ZTISt9exception) #7
  %23 = icmp eq i32 %21, %22
  br i1 %23, label %24, label %34

24:                                               ; preds = %19
  %25 = extractvalue { ptr, i32 } %20, 0
  %26 = tail call ptr @__cxa_begin_catch(ptr %25) #7
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  %29 = load ptr, ptr %28, align 8
  %30 = tail call noundef ptr %29(ptr noundef nonnull align 8 dereferenceable(8) %26) #7
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.20, ptr noundef %30)
  tail call void @__cxa_end_catch()
  br label %33

32:                                               ; preds = %18, %16, %13, %10, %9, %3
  tail call void @_ZN6glutil8ViewPole9CharPressEc(ptr noundef nonnull align 8 dereferenceable(148) @g_viewPole, i8 noundef signext %0)
  br label %33

33:                                               ; preds = %32, %24, %8
  ret void

34:                                               ; preds = %19
  resume { ptr, i32 } %20
}

; Function Attrs: nounwind
declare void @_ZN9Framework5SceneD1Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #5

declare void @glutLeaveMainLoop() local_unnamed_addr #6

declare void @_ZN6glutil8ViewPole5ResetEv(ptr noundef nonnull align 8 dereferenceable(148)) local_unnamed_addr #6

declare noundef zeroext i1 @_ZN9Framework5Timer11TogglePauseEv(ptr noundef nonnull align 4 dereferenceable(20)) local_unnamed_addr #6

declare void @_ZN6glutil8ViewPole9CharPressEc(ptr noundef nonnull align 8 dereferenceable(148), i8 noundef signext) local_unnamed_addr #6

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { nobuiltin 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 = { nofree nosync nounwind memory(none) }
attributes #3 = { nofree 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 #4 = { 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 #5 = { 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 #6 = { "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 #7 = { nounwind }
attributes #8 = { builtin 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 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"vtable pointer", !8, i64 0}


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