; LLVM IR from paroj/gltut :: Tut 13 Impostors/BasicImpostor.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.3 }
%union.anon.3 = type { %struct.anon }
%struct.anon = type { float, float, float }
%"struct.glm::detail::tvec2" = type { %union.anon.6 }
%union.anon.6 = type { %struct.anon.7 }
%struct.anon.7 = 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_pPlaneMesh = external dso_local global ptr, align 8
@g_pSphereMesh = external dso_local global ptr, align 8
@g_currImpostor = external dso_local global i32, align 4
@g_bDrawCameraPos = external dso_local global i8, align 1
@g_bDrawLights = external dso_local global i8, align 1
@g_sphereTimer = external dso_local global %"class.Framework::Timer", align 4
@g_drawImposter = external dso_local global [4 x i8], align 1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8keyboardhii(i8 noundef zeroext %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  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
  %7 = load i8, ptr %4, align 1, !tbaa !5
  %8 = zext i8 %7 to i32
  switch i32 %8, label %55 [
    i32 27, label %9
    i32 112, label %18
    i32 45, label %20
    i32 61, label %21
    i32 116, label %22
    i32 103, label %27
    i32 49, label %32
    i32 50, label %37
    i32 51, label %42
    i32 52, label %47
    i32 108, label %52
    i32 106, label %53
    i32 104, label %54
  ]

9:                                                ; preds = %3
  %10 = load ptr, ptr @g_pPlaneMesh, align 8, !tbaa !10
  %11 = icmp eq ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  call void @_ZN9Framework4MeshD1Ev(ptr noundef nonnull align 8 dereferenceable(8) %10) #4
  call void @_ZdlPvm(ptr noundef %10, i64 noundef 8) #5
  br label %13

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

16:                                               ; preds = %13
  call void @_ZN9Framework4MeshD1Ev(ptr noundef nonnull align 8 dereferenceable(8) %14) #4
  call void @_ZdlPvm(ptr noundef %14, i64 noundef 8) #5
  br label %17

17:                                               ; preds = %16, %13
  store ptr null, ptr @g_pPlaneMesh, align 8, !tbaa !10
  store ptr null, ptr @g_pSphereMesh, align 8, !tbaa !10
  call void @glutLeaveMainLoop()
  br label %57

18:                                               ; preds = %3
  %19 = call noundef zeroext i1 @_ZN9Framework5Timer11TogglePauseEv(ptr noundef nonnull align 4 dereferenceable(20) @g_sphereTimer)
  br label %55

20:                                               ; preds = %3
  call void @_ZN9Framework5Timer6RewindEf(ptr noundef nonnull align 4 dereferenceable(20) @g_sphereTimer, float noundef 5.000000e-01)
  br label %55

21:                                               ; preds = %3
  call void @_ZN9Framework5Timer11FastforwardEf(ptr noundef nonnull align 4 dereferenceable(20) @g_sphereTimer, float noundef 5.000000e-01)
  br label %55

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

27:                                               ; preds = %3
  %28 = load i8, ptr @g_bDrawLights, align 1, !tbaa !12, !range !14, !noundef !15
  %29 = trunc i8 %28 to i1
  %30 = xor i1 %29, true
  %31 = zext i1 %30 to i8
  store i8 %31, ptr @g_bDrawLights, align 1, !tbaa !12
  br label %55

32:                                               ; preds = %3
  %33 = load i8, ptr @g_drawImposter, align 1, !tbaa !12, !range !14, !noundef !15
  %34 = trunc i8 %33 to i1
  %35 = xor i1 %34, true
  %36 = zext i1 %35 to i8
  store i8 %36, ptr @g_drawImposter, align 1, !tbaa !12
  br label %55

37:                                               ; preds = %3
  %38 = load i8, ptr getelementptr inbounds ([4 x i8], ptr @g_drawImposter, i64 0, i64 1), align 1, !tbaa !12, !range !14, !noundef !15
  %39 = trunc i8 %38 to i1
  %40 = xor i1 %39, true
  %41 = zext i1 %40 to i8
  store i8 %41, ptr getelementptr inbounds ([4 x i8], ptr @g_drawImposter, i64 0, i64 1), align 1, !tbaa !12
  br label %55

42:                                               ; preds = %3
  %43 = load i8, ptr getelementptr inbounds ([4 x i8], ptr @g_drawImposter, i64 0, i64 2), align 1, !tbaa !12, !range !14, !noundef !15
  %44 = trunc i8 %43 to i1
  %45 = xor i1 %44, true
  %46 = zext i1 %45 to i8
  store i8 %46, ptr getelementptr inbounds ([4 x i8], ptr @g_drawImposter, i64 0, i64 2), align 1, !tbaa !12
  br label %55

47:                                               ; preds = %3
  %48 = load i8, ptr getelementptr inbounds ([4 x i8], ptr @g_drawImposter, i64 0, i64 3), align 1, !tbaa !12, !range !14, !noundef !15
  %49 = trunc i8 %48 to i1
  %50 = xor i1 %49, true
  %51 = zext i1 %50 to i8
  store i8 %51, ptr getelementptr inbounds ([4 x i8], ptr @g_drawImposter, i64 0, i64 3), align 1, !tbaa !12
  br label %55

52:                                               ; preds = %3
  store i32 0, ptr @g_currImpostor, align 4, !tbaa !8
  br label %55

53:                                               ; preds = %3
  store i32 1, ptr @g_currImpostor, align 4, !tbaa !8
  br label %55

54:                                               ; preds = %3
  store i32 2, ptr @g_currImpostor, align 4, !tbaa !8
  br label %55

55:                                               ; preds = %54, %53, %52, %47, %42, %37, %32, %27, %22, %21, %20, %18, %3
  %56 = load i8, ptr %4, align 1, !tbaa !5
  call void @_ZN6glutil8ViewPole9CharPressEc(ptr noundef nonnull align 8 dereferenceable(148) @g_viewPole, i8 noundef signext %56)
  br label %57

57:                                               ; preds = %55, %17
  ret void
}

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

declare void @glutLeaveMainLoop() #3

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

declare void @_ZN9Framework5Timer6RewindEf(ptr noundef nonnull align 4 dereferenceable(20), float noundef) #3

declare void @_ZN9Framework5Timer11FastforwardEf(ptr noundef nonnull align 4 dereferenceable(20), float noundef) #3

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

attributes #0 = { 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 #1 = { 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 #2 = { 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 = { "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 }
attributes #5 = { 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 = !{!"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 = !{}


; 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.3 }
%union.anon.3 = type { %struct.anon }
%struct.anon = type { float, float, float }
%"struct.glm::detail::tvec2" = type { %union.anon.6 }
%union.anon.6 = type { %struct.anon.7 }
%struct.anon.7 = 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_pPlaneMesh = external dso_local local_unnamed_addr global ptr, align 8
@g_pSphereMesh = external dso_local local_unnamed_addr global ptr, align 8
@g_currImpostor = external dso_local local_unnamed_addr global i32, align 4
@g_bDrawCameraPos = external dso_local local_unnamed_addr global i8, align 1
@g_bDrawLights = external dso_local local_unnamed_addr global i8, align 1
@g_sphereTimer = external dso_local global %"class.Framework::Timer", align 4
@g_drawImposter = external dso_local local_unnamed_addr global [4 x i8], align 1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8keyboardhii(i8 noundef zeroext %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  switch i8 %0, label %38 [
    i8 27, label %4
    i8 112, label %13
    i8 45, label %15
    i8 61, label %16
    i8 116, label %17
    i8 103, label %20
    i8 49, label %23
    i8 50, label %26
    i8 51, label %29
    i8 52, label %32
    i8 108, label %35
    i8 106, label %36
    i8 104, label %37
  ]

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

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

8:                                                ; preds = %7, %4
  %9 = load ptr, ptr @g_pSphereMesh, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %11, %8
  store ptr null, ptr @g_pPlaneMesh, align 8, !tbaa !5
  store ptr null, ptr @g_pSphereMesh, align 8, !tbaa !5
  tail call void @glutLeaveMainLoop()
  br label %39

13:                                               ; preds = %3
  %14 = tail call noundef zeroext i1 @_ZN9Framework5Timer11TogglePauseEv(ptr noundef nonnull align 4 dereferenceable(20) @g_sphereTimer)
  br label %38

15:                                               ; preds = %3
  tail call void @_ZN9Framework5Timer6RewindEf(ptr noundef nonnull align 4 dereferenceable(20) @g_sphereTimer, float noundef 5.000000e-01)
  br label %38

16:                                               ; preds = %3
  tail call void @_ZN9Framework5Timer11FastforwardEf(ptr noundef nonnull align 4 dereferenceable(20) @g_sphereTimer, float noundef 5.000000e-01)
  br label %38

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

20:                                               ; preds = %3
  %21 = load i8, ptr @g_bDrawLights, align 1, !tbaa !9, !range !11, !noundef !12
  %22 = xor i8 %21, 1
  store i8 %22, ptr @g_bDrawLights, align 1, !tbaa !9
  br label %38

23:                                               ; preds = %3
  %24 = load i8, ptr @g_drawImposter, align 1, !tbaa !9, !range !11, !noundef !12
  %25 = xor i8 %24, 1
  store i8 %25, ptr @g_drawImposter, align 1, !tbaa !9
  br label %38

26:                                               ; preds = %3
  %27 = load i8, ptr getelementptr inbounds (i8, ptr @g_drawImposter, i64 1), align 1, !tbaa !9, !range !11, !noundef !12
  %28 = xor i8 %27, 1
  store i8 %28, ptr getelementptr inbounds (i8, ptr @g_drawImposter, i64 1), align 1, !tbaa !9
  br label %38

29:                                               ; preds = %3
  %30 = load i8, ptr getelementptr inbounds (i8, ptr @g_drawImposter, i64 2), align 1, !tbaa !9, !range !11, !noundef !12
  %31 = xor i8 %30, 1
  store i8 %31, ptr getelementptr inbounds (i8, ptr @g_drawImposter, i64 2), align 1, !tbaa !9
  br label %38

32:                                               ; preds = %3
  %33 = load i8, ptr getelementptr inbounds (i8, ptr @g_drawImposter, i64 3), align 1, !tbaa !9, !range !11, !noundef !12
  %34 = xor i8 %33, 1
  store i8 %34, ptr getelementptr inbounds (i8, ptr @g_drawImposter, i64 3), align 1, !tbaa !9
  br label %38

35:                                               ; preds = %3
  store i32 0, ptr @g_currImpostor, align 4, !tbaa !13
  br label %38

36:                                               ; preds = %3
  store i32 1, ptr @g_currImpostor, align 4, !tbaa !13
  br label %38

37:                                               ; preds = %3
  store i32 2, ptr @g_currImpostor, align 4, !tbaa !13
  br label %38

38:                                               ; preds = %37, %36, %35, %32, %29, %26, %23, %20, %17, %16, %15, %13, %3
  tail call void @_ZN6glutil8ViewPole9CharPressEc(ptr noundef nonnull align 8 dereferenceable(148) @g_viewPole, i8 noundef signext %0)
  br label %39

39:                                               ; preds = %38, %12
  ret void
}

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

declare void @glutLeaveMainLoop() local_unnamed_addr #3

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

declare void @_ZN9Framework5Timer6RewindEf(ptr noundef nonnull align 4 dereferenceable(20), float noundef) local_unnamed_addr #3

declare void @_ZN9Framework5Timer11FastforwardEf(ptr noundef nonnull align 4 dereferenceable(20), float noundef) local_unnamed_addr #3

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

attributes #0 = { 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 #1 = { 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 #2 = { 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 = { "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 }
attributes #5 = { 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 = !{!"int", !7, i64 0}


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