; LLVM IR from paroj/gltut :: Tut 09 Lights on/BasicLighting.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"

@g_pCylinderMesh = external dso_local global ptr, align 8
@g_pPlaneMesh = external dso_local global ptr, align 8
@_ZL17g_bDrawColoredCyl = 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 %23 [
    i32 27, label %9
    i32 32, label %18
  ]

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
  call void @glutLeaveMainLoop()
  br label %24

18:                                               ; preds = %3
  %19 = load i8, ptr @_ZL17g_bDrawColoredCyl, align 1, !tbaa !12, !range !14, !noundef !15
  %20 = trunc i8 %19 to i1
  %21 = xor i1 %20, true
  %22 = zext i1 %21 to i8
  store i8 %22, ptr @_ZL17g_bDrawColoredCyl, align 1, !tbaa !12
  br label %23

23:                                               ; preds = %18, %3
  call void @glutPostRedisplay()
  br label %24

24:                                               ; preds = %23, %17
  ret void
}

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

declare void @glutLeaveMainLoop() #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 = !{}


; 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"

@g_pCylinderMesh = external dso_local local_unnamed_addr global ptr, align 8
@g_pPlaneMesh = external dso_local local_unnamed_addr global ptr, align 8
@_ZL17g_bDrawColoredCyl = 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 %16 [
    i8 27, label %4
    i8 32, label %13
  ]

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
  tail call void @glutLeaveMainLoop()
  br label %17

13:                                               ; preds = %3
  %14 = load i8, ptr @_ZL17g_bDrawColoredCyl, align 1, !tbaa !9, !range !11, !noundef !12
  %15 = xor i8 %14, 1
  store i8 %15, ptr @_ZL17g_bDrawColoredCyl, align 1, !tbaa !9
  br label %16

16:                                               ; preds = %13, %3
  tail call void @glutPostRedisplay()
  br label %17

17:                                               ; preds = %16, %12
  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

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


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