; LLVM IR from paroj/gltut :: Tut 14 Textures Are Not Pictures/BasicTexture.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_bDrawCameraPos = external dso_local global i8, align 1
@g_bDrawLights = external dso_local global i8, align 1
@g_bUseTexture = external dso_local global i8, align 1
@g_currTexture = external dso_local global i32, align 4
@g_lightTimer = external dso_local global %"class.Framework::Timer", align 4
@.str.21 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [22 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

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

declare i32 @printf(ptr 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 %45 [
    i32 27, label %10
    i32 112, label %19
    i32 45, label %21
    i32 61, label %22
    i32 116, label %23
    i32 103, label %28
    i32 32, label %33
  ]

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
  store ptr null, ptr @g_pObjectMesh, align 8, !tbaa !10
  store ptr null, ptr @g_pCubeMesh, align 8, !tbaa !10
  call void @glutLeaveMainLoop()
  br label %65

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

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

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

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

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

33:                                               ; preds = %3
  %34 = load i8, ptr @g_bUseTexture, align 1, !tbaa !12, !range !14, !noundef !15
  %35 = trunc i8 %34 to i1
  %36 = xor i1 %35, true
  %37 = zext i1 %36 to i8
  store i8 %37, ptr @g_bUseTexture, align 1, !tbaa !12
  %38 = load i8, ptr @g_bUseTexture, align 1, !tbaa !12, !range !14, !noundef !15
  %39 = trunc i8 %38 to i1
  br i1 %39, label %40, label %42

40:                                               ; preds = %33
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.21)
  br label %44

42:                                               ; preds = %33
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.22)
  br label %44

44:                                               ; preds = %42, %40
  br label %45

45:                                               ; preds = %44, %28, %23, %22, %21, %19, %3
  %46 = load i8, ptr %4, align 1, !tbaa !5
  %47 = zext i8 %46 to i32
  %48 = icmp sle i32 49, %47
  br i1 %48, label %49, label %65

49:                                               ; preds = %45
  %50 = load i8, ptr %4, align 1, !tbaa !5
  %51 = zext i8 %50 to i32
  %52 = icmp sle i32 %51, 57
  br i1 %52, label %53, label %65

53:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %54 = load i8, ptr %4, align 1, !tbaa !5
  %55 = zext i8 %54 to i32
  %56 = sub nsw i32 %55, 49
  store i32 %56, ptr %7, align 4, !tbaa !8
  %57 = load i32, ptr %7, align 4, !tbaa !8
  %58 = icmp slt i32 %57, 4
  br i1 %58, label %59, label %64

59:                                               ; preds = %53
  %60 = load i32, ptr %7, align 4, !tbaa !8
  %61 = call noundef i32 @_Z20CalcCosAngResolutioni(i32 noundef %60)
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.23, i32 noundef %61)
  %63 = load i32, ptr %7, align 4, !tbaa !8
  store i32 %63, ptr @g_currTexture, align 4, !tbaa !8
  br label %64

64:                                               ; preds = %59, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %65

65:                                               ; preds = %64, %49, %45, %18
  ret void
}

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

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

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 = { 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 = { "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 = !{}


; 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_bDrawCameraPos = external dso_local local_unnamed_addr global i8, align 1
@g_bDrawLights = external dso_local local_unnamed_addr global i8, align 1
@g_bUseTexture = external dso_local local_unnamed_addr global i8, align 1
@g_currTexture = external dso_local local_unnamed_addr global i32, align 4
@g_lightTimer = external dso_local global %"class.Framework::Timer", align 4
@.str.21 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [22 x i8], align 1

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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 %32 [
    i8 27, label %5
    i8 112, label %14
    i8 45, label %16
    i8 61, label %17
    i8 116, label %18
    i8 103, label %21
    i8 32, label %24
  ]

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
  store ptr null, ptr @g_pObjectMesh, align 8, !tbaa !5
  store ptr null, ptr @g_pCubeMesh, align 8, !tbaa !5
  tail call void @glutLeaveMainLoop()
  br label %.thread

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

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

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

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

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

24:                                               ; preds = %3
  %25 = load i8, ptr @g_bUseTexture, align 1, !tbaa !9, !range !11, !noundef !12
  %26 = trunc nuw i8 %25 to i1
  %27 = xor i8 %25, 1
  store i8 %27, ptr @g_bUseTexture, align 1, !tbaa !9
  br i1 %26, label %30, label %28

28:                                               ; preds = %24
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.21)
  br label %.thread

30:                                               ; preds = %24
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.22)
  br label %.thread

32:                                               ; preds = %3
  %33 = add i8 %0, -49
  %or.cond12 = icmp ult i8 %33, 4
  br i1 %or.cond12, label %34, label %.thread

34:                                               ; preds = %32
  %35 = add nsw i32 %4, -49
  %36 = tail call noundef i32 @_Z20CalcCosAngResolutioni(i32 noundef %35)
  %37 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.23, i32 noundef %36)
  store i32 %35, ptr @g_currTexture, align 4, !tbaa !13
  br label %.thread

.thread:                                          ; preds = %14, %16, %17, %18, %21, %30, %28, %34, %32, %13
  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 = { 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 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 = !{!"int", !7, i64 0}


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