; LLVM IR from paroj/gltut :: Tut 16 Gamma and Textures/GammaLandscape.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.5 }
%union.anon.5 = type { %struct.anon }
%struct.anon = type { float, float, float }
%"struct.glm::detail::tvec2" = type { %union.anon.8 }
%union.anon.8 = type { %struct.anon.9 }
%struct.anon.9 = type { i32, i32 }
%"struct.glm::detail::tquat" = type { float, float, float, float }

@g_viewPole = external dso_local global %"class.glutil::ViewPole", align 8
@g_pLightEnv = external dso_local global ptr, align 8
@g_pTerrain = external dso_local global ptr, align 8
@g_pSphere = external dso_local global ptr, align 8
@g_currSampler = external dso_local global i32, align 4
@g_bDrawCameraPos = external dso_local global i8, align 1
@g_useGammaDisplay = external dso_local global 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: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #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
  %7 = 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
  %8 = load i8, ptr %4, align 1, !tbaa !5
  %9 = zext i8 %8 to i32
  switch i32 %9, label %39 [
    i32 27, label %10
    i32 32, label %23
    i32 45, label %28
    i32 61, label %30
    i32 116, label %32
    i32 112, label %37
  ]

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

13:                                               ; preds = %10
  call void @_ZN9Framework4MeshD1Ev(ptr noundef nonnull align 8 dereferenceable(8) %11) #6
  call void @_ZdlPvm(ptr noundef %11, i64 noundef 8) #7
  br label %14

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

17:                                               ; preds = %14
  call void @_ZN9Framework4MeshD1Ev(ptr noundef nonnull align 8 dereferenceable(8) %15) #6
  call void @_ZdlPvm(ptr noundef %15, i64 noundef 8) #7
  br label %18

18:                                               ; preds = %17, %14
  %19 = load ptr, ptr @g_pLightEnv, align 8, !tbaa !10
  %20 = icmp eq ptr %19, null
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  call void @_ZN8LightEnvD2Ev(ptr noundef nonnull align 8 dereferenceable(192) %19) #6
  call void @_ZdlPvm(ptr noundef %19, i64 noundef 192) #7
  br label %22

22:                                               ; preds = %21, %18
  store ptr null, ptr @g_pSphere, align 8, !tbaa !10
  store ptr null, ptr @g_pTerrain, align 8, !tbaa !10
  store ptr null, ptr @g_pLightEnv, align 8, !tbaa !10
  call void @glutLeaveMainLoop()
  br label %58

23:                                               ; preds = %3
  %24 = load i8, ptr @g_useGammaDisplay, 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_useGammaDisplay, align 1, !tbaa !12
  br label %39

28:                                               ; preds = %3
  %29 = load ptr, ptr @g_pLightEnv, align 8, !tbaa !10
  call void @_ZN8LightEnv10RewindTimeEf(ptr noundef nonnull align 8 dereferenceable(192) %29, float noundef 1.000000e+00)
  br label %39

30:                                               ; preds = %3
  %31 = load ptr, ptr @g_pLightEnv, align 8, !tbaa !10
  call void @_ZN8LightEnv15FastForwardTimeEf(ptr noundef nonnull align 8 dereferenceable(192) %31, float noundef 1.000000e+00)
  br label %39

32:                                               ; preds = %3
  %33 = load i8, ptr @g_bDrawCameraPos, 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_bDrawCameraPos, align 1, !tbaa !12
  br label %39

37:                                               ; preds = %3
  %38 = load ptr, ptr @g_pLightEnv, align 8, !tbaa !10
  call void @_ZN8LightEnv11TogglePauseEv(ptr noundef nonnull align 8 dereferenceable(192) %38)
  br label %39

39:                                               ; preds = %37, %32, %30, %28, %23, %3
  %40 = load i8, ptr %4, align 1, !tbaa !5
  %41 = zext i8 %40 to i32
  %42 = icmp sle i32 49, %41
  br i1 %42, label %43, label %56

43:                                               ; preds = %39
  %44 = load i8, ptr %4, align 1, !tbaa !5
  %45 = zext i8 %44 to i32
  %46 = icmp sle i32 %45, 57
  br i1 %46, label %47, label %56

47:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %48 = load i8, ptr %4, align 1, !tbaa !5
  %49 = zext i8 %48 to i32
  %50 = sub nsw i32 %49, 49
  store i32 %50, ptr %7, align 4, !tbaa !8
  %51 = load i32, ptr %7, align 4, !tbaa !8
  %52 = icmp slt i32 %51, 2
  br i1 %52, label %53, label %55

53:                                               ; preds = %47
  %54 = load i32, ptr %7, align 4, !tbaa !8
  store i32 %54, ptr @g_currSampler, align 4, !tbaa !8
  br label %55

55:                                               ; preds = %53, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  br label %56

56:                                               ; preds = %55, %43, %39
  %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, %22
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN8LightEnvD2Ev(ptr noundef nonnull align 8 dereferenceable(192)) unnamed_addr #4 align 2

declare void @glutLeaveMainLoop() #5

declare void @_ZN8LightEnv10RewindTimeEf(ptr noundef nonnull align 8 dereferenceable(192), float noundef) #5

declare void @_ZN8LightEnv15FastForwardTimeEf(ptr noundef nonnull align 8 dereferenceable(192), float noundef) #5

declare void @_ZN8LightEnv11TogglePauseEv(ptr noundef nonnull align 8 dereferenceable(192)) #5

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { inlinehint mustprogress 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 #5 = { "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 = { nounwind }
attributes #7 = { 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.5 }
%union.anon.5 = type { %struct.anon }
%struct.anon = type { float, float, float }
%"struct.glm::detail::tvec2" = type { %union.anon.8 }
%union.anon.8 = type { %struct.anon.9 }
%struct.anon.9 = type { i32, i32 }
%"struct.glm::detail::tquat" = type { float, float, float, float }

@g_viewPole = external dso_local global %"class.glutil::ViewPole", align 8
@g_pLightEnv = external dso_local local_unnamed_addr global ptr, align 8
@g_pTerrain = external dso_local local_unnamed_addr global ptr, align 8
@g_pSphere = external dso_local local_unnamed_addr global ptr, align 8
@g_currSampler = external dso_local local_unnamed_addr global i32, align 4
@g_bDrawCameraPos = external dso_local local_unnamed_addr global i8, align 1
@g_useGammaDisplay = external dso_local local_unnamed_addr global 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 {
  %4 = zext i8 %0 to i32
  switch i8 %0, label %30 [
    i8 27, label %5
    i8 32, label %18
    i8 45, label %21
    i8 61, label %23
    i8 116, label %25
    i8 112, label %28
  ]

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

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

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

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

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

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

17:                                               ; preds = %16, %13
  store ptr null, ptr @g_pSphere, align 8, !tbaa !5
  store ptr null, ptr @g_pTerrain, align 8, !tbaa !5
  store ptr null, ptr @g_pLightEnv, align 8, !tbaa !5
  tail call void @glutLeaveMainLoop()
  br label %34

18:                                               ; preds = %3
  %19 = load i8, ptr @g_useGammaDisplay, align 1, !tbaa !9, !range !11, !noundef !12
  %20 = xor i8 %19, 1
  store i8 %20, ptr @g_useGammaDisplay, align 1, !tbaa !9
  br label %.thread

21:                                               ; preds = %3
  %22 = load ptr, ptr @g_pLightEnv, align 8, !tbaa !5
  tail call void @_ZN8LightEnv10RewindTimeEf(ptr noundef nonnull align 8 dereferenceable(192) %22, float noundef 1.000000e+00)
  br label %.thread

23:                                               ; preds = %3
  %24 = load ptr, ptr @g_pLightEnv, align 8, !tbaa !5
  tail call void @_ZN8LightEnv15FastForwardTimeEf(ptr noundef nonnull align 8 dereferenceable(192) %24, float noundef 1.000000e+00)
  br label %.thread

25:                                               ; preds = %3
  %26 = load i8, ptr @g_bDrawCameraPos, align 1, !tbaa !9, !range !11, !noundef !12
  %27 = xor i8 %26, 1
  store i8 %27, ptr @g_bDrawCameraPos, align 1, !tbaa !9
  br label %.thread

28:                                               ; preds = %3
  %29 = load ptr, ptr @g_pLightEnv, align 8, !tbaa !5
  tail call void @_ZN8LightEnv11TogglePauseEv(ptr noundef nonnull align 8 dereferenceable(192) %29)
  br label %.thread

30:                                               ; preds = %3
  %31 = add i8 %0, -49
  %or.cond13 = icmp ult i8 %31, 2
  br i1 %or.cond13, label %32, label %.thread

32:                                               ; preds = %30
  %33 = add nsw i32 %4, -49
  store i32 %33, ptr @g_currSampler, align 4, !tbaa !13
  br label %.thread

.thread:                                          ; preds = %18, %21, %23, %25, %28, %32, %30
  tail call void @_ZN6glutil8ViewPole9CharPressEc(ptr noundef nonnull align 8 dereferenceable(148) @g_viewPole, i8 noundef signext %0)
  br label %34

34:                                               ; preds = %.thread, %17
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN8LightEnvD2Ev(ptr noundef nonnull align 8 dereferenceable(192)) unnamed_addr #3 align 2

declare void @glutLeaveMainLoop() local_unnamed_addr #4

declare void @_ZN8LightEnv10RewindTimeEf(ptr noundef nonnull align 8 dereferenceable(192), float noundef) local_unnamed_addr #4

declare void @_ZN8LightEnv15FastForwardTimeEf(ptr noundef nonnull align 8 dereferenceable(192), float noundef) local_unnamed_addr #4

declare void @_ZN8LightEnv11TogglePauseEv(ptr noundef nonnull align 8 dereferenceable(192)) local_unnamed_addr #4

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

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 = { inlinehint mustprogress 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 #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 = { nounwind }
attributes #6 = { 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,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass