; LLVM IR from paroj/gltut :: Tut 14 Textures Are Not Pictures/MaterialTexture.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_pObjectMesh = external dso_local global ptr, align 8
@g_pCubeMesh = external dso_local global ptr, align 8
@g_pPlaneMesh = external dso_local global ptr, align 8
@.str.20 = external hidden unnamed_addr constant [4 x i8], align 1
@g_bDrawCameraPos = external dso_local global i8, align 1
@g_bDrawLights = external dso_local global i8, align 1
@g_bUseInfinity = external dso_local global i8, align 1
@g_eMode = external dso_local global i32, align 4
@g_currTexture = external dso_local global i32, align 4
@g_currMaterial = external dso_local global i32, align 4
@g_lightTimer = external dso_local global %"class.Framework::Timer", align 4
@g_shaderModeNames = external dso_local global [3 x ptr], align 16
@.str.31 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [20 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 noundef i32 @_Z20CalcCosAngResolutioni(i32 noundef) #1

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

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

; 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
  %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 %52 [
    i32 27, label %10
    i32 112, label %23
    i32 45, label %25
    i32 61, label %26
    i32 116, label %27
    i32 103, label %32
    i32 121, label %37
    i32 32, label %42
  ]

10:                                               ; preds = %3
  %11 = load ptr, ptr @g_pObjectMesh, 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) #5
  call void @_ZdlPvm(ptr noundef %11, i64 noundef 8) #6
  br label %14

14:                                               ; preds = %13, %10
  %15 = load ptr, ptr @g_pCubeMesh, 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) #5
  call void @_ZdlPvm(ptr noundef %15, i64 noundef 8) #6
  br label %18

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

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

22:                                               ; preds = %21, %18
  store ptr null, ptr @g_pObjectMesh, align 8, !tbaa !10
  store ptr null, ptr @g_pCubeMesh, align 8, !tbaa !10
  store ptr null, ptr @g_pPlaneMesh, align 8, !tbaa !10
  call void @glutLeaveMainLoop()
  br label %81

23:                                               ; preds = %3
  %24 = call noundef zeroext i1 @_ZN9Framework5Timer11TogglePauseEv(ptr noundef nonnull align 4 dereferenceable(20) @g_lightTimer)
  br label %52

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

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

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

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

37:                                               ; preds = %3
  %38 = load i8, ptr @g_bUseInfinity, 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 @g_bUseInfinity, align 1, !tbaa !12
  br label %52

42:                                               ; preds = %3
  %43 = load i32, ptr @g_eMode, align 4, !tbaa !16
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr @g_eMode, align 4, !tbaa !16
  %45 = load i32, ptr @g_eMode, align 4, !tbaa !16
  %46 = srem i32 %45, 3
  store i32 %46, ptr @g_eMode, align 4, !tbaa !16
  %47 = load i32, ptr @g_eMode, align 4, !tbaa !16
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds [3 x ptr], ptr @g_shaderModeNames, i64 0, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !10
  %51 = call i32 (ptr, ...) @printf(ptr noundef @.str.20, ptr noundef %50)
  br label %52

52:                                               ; preds = %42, %37, %32, %27, %26, %25, %23, %3
  %53 = load i8, ptr %4, align 1, !tbaa !5
  %54 = zext i8 %53 to i32
  %55 = icmp sle i32 49, %54
  br i1 %55, label %56, label %81

56:                                               ; preds = %52
  %57 = load i8, ptr %4, align 1, !tbaa !5
  %58 = zext i8 %57 to i32
  %59 = icmp sle i32 %58, 57
  br i1 %59, label %60, label %81

60:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %61 = load i8, ptr %4, align 1, !tbaa !5
  %62 = zext i8 %61 to i32
  %63 = sub nsw i32 %62, 49
  store i32 %63, ptr %7, align 4, !tbaa !8
  %64 = load i32, ptr %7, align 4, !tbaa !8
  %65 = icmp slt i32 %64, 4
  br i1 %65, label %66, label %71

66:                                               ; preds = %60
  %67 = load i32, ptr %7, align 4, !tbaa !8
  %68 = call noundef i32 @_Z20CalcCosAngResolutioni(i32 noundef %67)
  %69 = call i32 (ptr, ...) @printf(ptr noundef @.str.31, i32 noundef %68)
  %70 = load i32, ptr %7, align 4, !tbaa !8
  store i32 %70, ptr @g_currTexture, align 4, !tbaa !8
  br label %71

71:                                               ; preds = %66, %60
  %72 = load i32, ptr %7, align 4, !tbaa !8
  %73 = icmp sge i32 %72, 7
  br i1 %73, label %74, label %80

74:                                               ; preds = %71
  %75 = load i32, ptr %7, align 4, !tbaa !8
  %76 = sub nsw i32 %75, 7
  store i32 %76, ptr %7, align 4, !tbaa !8
  %77 = load i32, ptr %7, align 4, !tbaa !8
  %78 = call i32 (ptr, ...) @printf(ptr noundef @.str.32, i32 noundef %77)
  %79 = load i32, ptr %7, align 4, !tbaa !8
  store i32 %79, ptr @g_currMaterial, align 4, !tbaa !8
  br label %80

80:                                               ; preds = %74, %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %81

81:                                               ; preds = %80, %56, %52, %22
  ret void
}

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

declare void @glutLeaveMainLoop() #2

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

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = { 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 #4 = { 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 #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 = !{!"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 = !{!"_ZTS10ShaderMode", !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_pObjectMesh = external dso_local local_unnamed_addr global ptr, align 8
@g_pCubeMesh = external dso_local local_unnamed_addr global ptr, align 8
@g_pPlaneMesh = external dso_local local_unnamed_addr global ptr, align 8
@.str.20 = external hidden unnamed_addr constant [4 x i8], align 1
@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_bUseInfinity = external dso_local local_unnamed_addr global i8, align 1
@g_eMode = external dso_local local_unnamed_addr global i32, align 4
@g_currTexture = external dso_local local_unnamed_addr global i32, align 4
@g_currMaterial = external dso_local local_unnamed_addr global i32, align 4
@g_lightTimer = external dso_local global %"class.Framework::Timer", align 4
@g_shaderModeNames = external dso_local local_unnamed_addr global [3 x ptr], align 16
@.str.31 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z20CalcCosAngResolutioni(i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8keyboardhii(i8 noundef zeroext %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = zext i8 %0 to i32
  switch i8 %0, label %39 [
    i8 27, label %5
    i8 112, label %18
    i8 45, label %20
    i8 61, label %21
    i8 116, label %22
    i8 103, label %25
    i8 121, label %28
    i8 32, label %31
  ]

5:                                                ; preds = %3
  %6 = load ptr, ptr @g_pObjectMesh, 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_pCubeMesh, 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_pPlaneMesh, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %16, %13
  store ptr null, ptr @g_pObjectMesh, align 8, !tbaa !5
  store ptr null, ptr @g_pCubeMesh, align 8, !tbaa !5
  store ptr null, ptr @g_pPlaneMesh, align 8, !tbaa !5
  tail call void @glutLeaveMainLoop()
  br label %.thread

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

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

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

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

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

28:                                               ; preds = %3
  %29 = load i8, ptr @g_bUseInfinity, align 1, !tbaa !9, !range !11, !noundef !12
  %30 = xor i8 %29, 1
  store i8 %30, ptr @g_bUseInfinity, align 1, !tbaa !9
  br label %.thread

31:                                               ; preds = %3
  %32 = load i32, ptr @g_eMode, align 4, !tbaa !13
  %33 = add nsw i32 %32, 1
  %34 = srem i32 %33, 3
  store i32 %34, ptr @g_eMode, align 4, !tbaa !13
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds [3 x ptr], ptr @g_shaderModeNames, i64 0, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.20, ptr noundef %37)
  br label %.thread

39:                                               ; preds = %3
  %40 = add i8 %0, -49
  %or.cond = icmp ult i8 %40, 9
  br i1 %or.cond, label %41, label %.thread

41:                                               ; preds = %39
  %42 = icmp ult i8 %0, 53
  br i1 %42, label %.thread18, label %46

.thread18:                                        ; preds = %41
  %43 = add nsw i32 %4, -49
  %44 = tail call noundef i32 @_Z20CalcCosAngResolutioni(i32 noundef %43)
  %45 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.31, i32 noundef %44)
  store i32 %43, ptr @g_currTexture, align 4, !tbaa !15
  br label %.thread

46:                                               ; preds = %41
  %47 = icmp ugt i8 %0, 55
  br i1 %47, label %48, label %.thread

48:                                               ; preds = %46
  %49 = add nsw i32 %4, -56
  %50 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.32, i32 noundef %49)
  store i32 %49, ptr @g_currMaterial, align 4, !tbaa !15
  br label %.thread

.thread:                                          ; preds = %18, %20, %21, %22, %25, %28, %31, %.thread18, %46, %48, %39, %17
  ret void
}

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

declare void @glutLeaveMainLoop() local_unnamed_addr #4

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

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

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

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


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