; LLVM IR from paroj/gltut :: Tut 10 Plane Lights/VertexPointLighting.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.Framework::Timer" = type { i32, float, i8, i8, float, float }

@g_pCylinderMesh = external dso_local global ptr, align 8
@g_pPlaneMesh = external dso_local global ptr, align 8
@g_pCubeMesh = external dso_local global ptr, align 8
@g_LightTimer = external dso_local global %"class.Framework::Timer", align 4
@_ZL14g_fLightHeight = external hidden global float, align 4
@_ZL14g_fLightRadius = external hidden global float, align 4
@_ZL17g_bDrawColoredCyl = external hidden global i8, align 1
@_ZL12g_bDrawLight = external hidden global i8, align 1

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

declare void @glutPostRedisplay() #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8keyboardhii(i8 noundef zeroext %0, i32 noundef %1, i32 noundef %2) #2 {
  %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 %58 [
    i32 27, label %9
    i32 32, label %22
    i32 105, label %27
    i32 107, label %30
    i32 108, label %33
    i32 106, label %36
    i32 73, label %39
    i32 75, label %42
    i32 76, label %45
    i32 74, label %48
    i32 121, label %51
    i32 98, label %56
  ]

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_pCylinderMesh, 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
  %18 = load ptr, ptr @g_pCubeMesh, align 8, !tbaa !10
  %19 = icmp eq ptr %18, null
  br i1 %19, label %21, label %20

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

21:                                               ; preds = %20, %17
  call void @glutLeaveMainLoop()
  br label %63

22:                                               ; preds = %3
  %23 = load i8, ptr @_ZL17g_bDrawColoredCyl, 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 @_ZL17g_bDrawColoredCyl, align 1, !tbaa !12
  br label %58

27:                                               ; preds = %3
  %28 = load float, ptr @_ZL14g_fLightHeight, align 4, !tbaa !16
  %29 = fadd float %28, 0x3FC99999A0000000
  store float %29, ptr @_ZL14g_fLightHeight, align 4, !tbaa !16
  br label %58

30:                                               ; preds = %3
  %31 = load float, ptr @_ZL14g_fLightHeight, align 4, !tbaa !16
  %32 = fsub float %31, 0x3FC99999A0000000
  store float %32, ptr @_ZL14g_fLightHeight, align 4, !tbaa !16
  br label %58

33:                                               ; preds = %3
  %34 = load float, ptr @_ZL14g_fLightRadius, align 4, !tbaa !16
  %35 = fadd float %34, 0x3FC99999A0000000
  store float %35, ptr @_ZL14g_fLightRadius, align 4, !tbaa !16
  br label %58

36:                                               ; preds = %3
  %37 = load float, ptr @_ZL14g_fLightRadius, align 4, !tbaa !16
  %38 = fsub float %37, 0x3FC99999A0000000
  store float %38, ptr @_ZL14g_fLightRadius, align 4, !tbaa !16
  br label %58

39:                                               ; preds = %3
  %40 = load float, ptr @_ZL14g_fLightHeight, align 4, !tbaa !16
  %41 = fadd float %40, 0x3FA99999A0000000
  store float %41, ptr @_ZL14g_fLightHeight, align 4, !tbaa !16
  br label %58

42:                                               ; preds = %3
  %43 = load float, ptr @_ZL14g_fLightHeight, align 4, !tbaa !16
  %44 = fsub float %43, 0x3FA99999A0000000
  store float %44, ptr @_ZL14g_fLightHeight, align 4, !tbaa !16
  br label %58

45:                                               ; preds = %3
  %46 = load float, ptr @_ZL14g_fLightRadius, align 4, !tbaa !16
  %47 = fadd float %46, 0x3FA99999A0000000
  store float %47, ptr @_ZL14g_fLightRadius, align 4, !tbaa !16
  br label %58

48:                                               ; preds = %3
  %49 = load float, ptr @_ZL14g_fLightRadius, align 4, !tbaa !16
  %50 = fsub float %49, 0x3FA99999A0000000
  store float %50, ptr @_ZL14g_fLightRadius, align 4, !tbaa !16
  br label %58

51:                                               ; preds = %3
  %52 = load i8, ptr @_ZL12g_bDrawLight, align 1, !tbaa !12, !range !14, !noundef !15
  %53 = trunc i8 %52 to i1
  %54 = xor i1 %53, true
  %55 = zext i1 %54 to i8
  store i8 %55, ptr @_ZL12g_bDrawLight, align 1, !tbaa !12
  br label %58

56:                                               ; preds = %3
  %57 = call noundef zeroext i1 @_ZN9Framework5Timer11TogglePauseEv(ptr noundef nonnull align 4 dereferenceable(20) @g_LightTimer)
  br label %58

58:                                               ; preds = %56, %51, %48, %45, %42, %39, %36, %33, %30, %27, %22, %3
  %59 = load float, ptr @_ZL14g_fLightRadius, align 4, !tbaa !16
  %60 = fcmp olt float %59, 0x3FC99999A0000000
  br i1 %60, label %61, label %62

61:                                               ; preds = %58
  store float 0x3FC99999A0000000, ptr @_ZL14g_fLightRadius, align 4, !tbaa !16
  br label %62

62:                                               ; preds = %61, %58
  call void @glutPostRedisplay()
  br label %63

63:                                               ; preds = %62, %21
  ret void
}

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

declare void @glutLeaveMainLoop() #1

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

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 = { "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 "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 = !{}
!16 = !{!17, !17, i64 0}
!17 = !{!"float", !6, 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.Framework::Timer" = type { i32, float, i8, i8, float, float }

@g_pCylinderMesh = external dso_local local_unnamed_addr global ptr, align 8
@g_pPlaneMesh = external dso_local local_unnamed_addr global ptr, align 8
@g_pCubeMesh = external dso_local local_unnamed_addr global ptr, align 8
@g_LightTimer = external dso_local global %"class.Framework::Timer", align 4
@_ZL14g_fLightHeight = external hidden local_unnamed_addr global float, align 4
@_ZL14g_fLightRadius = external hidden local_unnamed_addr global float, align 4
@_ZL17g_bDrawColoredCyl = external hidden local_unnamed_addr global i8, align 1
@_ZL12g_bDrawLight = external hidden local_unnamed_addr global i8, align 1

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

declare void @glutPostRedisplay() local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8keyboardhii(i8 noundef zeroext %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  switch i8 %0, label %thread-pre-split [
    i8 27, label %4
    i8 32, label %17
    i8 105, label %20
    i8 107, label %23
    i8 108, label %26
    i8 106, label %29
    i8 73, label %32
    i8 75, label %35
    i8 76, label %38
    i8 74, label %41
    i8 121, label %44
    i8 98, label %47
  ]

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_pCylinderMesh, 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
  %13 = load ptr, ptr @g_pCubeMesh, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %15, %12
  tail call void @glutLeaveMainLoop()
  br label %54

17:                                               ; preds = %3
  %18 = load i8, ptr @_ZL17g_bDrawColoredCyl, align 1, !tbaa !9, !range !11, !noundef !12
  %19 = xor i8 %18, 1
  store i8 %19, ptr @_ZL17g_bDrawColoredCyl, align 1, !tbaa !9
  br label %thread-pre-split

20:                                               ; preds = %3
  %21 = load float, ptr @_ZL14g_fLightHeight, align 4, !tbaa !13
  %22 = fadd float %21, 0x3FC99999A0000000
  store float %22, ptr @_ZL14g_fLightHeight, align 4, !tbaa !13
  br label %thread-pre-split

23:                                               ; preds = %3
  %24 = load float, ptr @_ZL14g_fLightHeight, align 4, !tbaa !13
  %25 = fadd float %24, 0xBFC99999A0000000
  store float %25, ptr @_ZL14g_fLightHeight, align 4, !tbaa !13
  br label %thread-pre-split

26:                                               ; preds = %3
  %27 = load float, ptr @_ZL14g_fLightRadius, align 4, !tbaa !13
  %28 = fadd float %27, 0x3FC99999A0000000
  store float %28, ptr @_ZL14g_fLightRadius, align 4, !tbaa !13
  br label %49

29:                                               ; preds = %3
  %30 = load float, ptr @_ZL14g_fLightRadius, align 4, !tbaa !13
  %31 = fadd float %30, 0xBFC99999A0000000
  store float %31, ptr @_ZL14g_fLightRadius, align 4, !tbaa !13
  br label %49

32:                                               ; preds = %3
  %33 = load float, ptr @_ZL14g_fLightHeight, align 4, !tbaa !13
  %34 = fadd float %33, 0x3FA99999A0000000
  store float %34, ptr @_ZL14g_fLightHeight, align 4, !tbaa !13
  br label %thread-pre-split

35:                                               ; preds = %3
  %36 = load float, ptr @_ZL14g_fLightHeight, align 4, !tbaa !13
  %37 = fadd float %36, 0xBFA99999A0000000
  store float %37, ptr @_ZL14g_fLightHeight, align 4, !tbaa !13
  br label %thread-pre-split

38:                                               ; preds = %3
  %39 = load float, ptr @_ZL14g_fLightRadius, align 4, !tbaa !13
  %40 = fadd float %39, 0x3FA99999A0000000
  store float %40, ptr @_ZL14g_fLightRadius, align 4, !tbaa !13
  br label %49

41:                                               ; preds = %3
  %42 = load float, ptr @_ZL14g_fLightRadius, align 4, !tbaa !13
  %43 = fadd float %42, 0xBFA99999A0000000
  store float %43, ptr @_ZL14g_fLightRadius, align 4, !tbaa !13
  br label %49

44:                                               ; preds = %3
  %45 = load i8, ptr @_ZL12g_bDrawLight, align 1, !tbaa !9, !range !11, !noundef !12
  %46 = xor i8 %45, 1
  store i8 %46, ptr @_ZL12g_bDrawLight, align 1, !tbaa !9
  br label %thread-pre-split

47:                                               ; preds = %3
  %48 = tail call noundef zeroext i1 @_ZN9Framework5Timer11TogglePauseEv(ptr noundef nonnull align 4 dereferenceable(20) @g_LightTimer)
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %3, %17, %20, %23, %32, %35, %44, %47
  %.pr = load float, ptr @_ZL14g_fLightRadius, align 4, !tbaa !13
  br label %49

49:                                               ; preds = %thread-pre-split, %41, %38, %29, %26
  %50 = phi float [ %.pr, %thread-pre-split ], [ %43, %41 ], [ %40, %38 ], [ %31, %29 ], [ %28, %26 ]
  %51 = fcmp olt float %50, 0x3FC99999A0000000
  br i1 %51, label %52, label %53

52:                                               ; preds = %49
  store float 0x3FC99999A0000000, ptr @_ZL14g_fLightRadius, align 4, !tbaa !13
  br label %53

53:                                               ; preds = %52, %49
  tail call void @glutPostRedisplay()
  br label %54

54:                                               ; preds = %53, %16
  ret void
}

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

declare void @glutLeaveMainLoop() local_unnamed_addr #1

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

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 = { "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 "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 = !{!"float", !7, i64 0}


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