; LLVM IR from paroj/gltut :: Tut 08 Getting Oriented/Interpolation.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.Orientation = type { i8, i32, i8, %"class.Orientation::Animation" }
%"class.Orientation::Animation" = type { i32, %"class.Framework::Timer" }
%"class.Framework::Timer" = type { i32, float, i8, i8, float, float }

@g_orient = external dso_local global %class.Orientation, align 4
@.str.14 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [6 x i8], align 1
@_ZL12g_OrientKeys = external hidden global [7 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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z16ApplyOrientationi(i32 noundef) #2

; 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 i8, align 1
  %8 = 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
  %9 = load i8, ptr %4, align 1, !tbaa !5
  %10 = zext i8 %9 to i32
  switch i32 %10, label %20 [
    i32 27, label %11
    i32 32, label %12
  ]

11:                                               ; preds = %3
  call void @glutLeaveMainLoop()
  br label %41

12:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  %13 = call noundef zeroext i1 @_ZN11Orientation11ToggleSlerpEv(ptr noundef nonnull align 4 dereferenceable(36) @g_orient)
  %14 = zext i1 %13 to i8
  store i8 %14, ptr %7, align 1, !tbaa !10
  %15 = load i8, ptr %7, align 1, !tbaa !10, !range !12, !noundef !13
  %16 = trunc i8 %15 to i1
  %17 = zext i1 %16 to i64
  %18 = select i1 %16, ptr @.str.14, ptr @.str.15
  %19 = call i32 (ptr, ...) @printf(ptr noundef %18)
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  br label %20

20:                                               ; preds = %12, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !8
  br label %21

21:                                               ; preds = %38, %20
  %22 = load i32, ptr %8, align 4, !tbaa !8
  %23 = sext i32 %22 to i64
  %24 = icmp ult i64 %23, 7
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %41

26:                                               ; preds = %21
  %27 = load i8, ptr %4, align 1, !tbaa !5
  %28 = zext i8 %27 to i32
  %29 = load i32, ptr %8, align 4, !tbaa !8
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [7 x i8], ptr @_ZL12g_OrientKeys, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !5
  %33 = sext i8 %32 to i32
  %34 = icmp eq i32 %28, %33
  br i1 %34, label %35, label %37

35:                                               ; preds = %26
  %36 = load i32, ptr %8, align 4, !tbaa !8
  call void @_Z16ApplyOrientationi(i32 noundef %36)
  br label %37

37:                                               ; preds = %35, %26
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %8, align 4, !tbaa !8
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %8, align 4, !tbaa !8
  br label %21, !llvm.loop !14

41:                                               ; preds = %25, %11
  ret void
}

declare void @glutLeaveMainLoop() #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN11Orientation11ToggleSlerpEv(ptr noundef nonnull align 4 dereferenceable(36)) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = !{!"bool", !6, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; 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.Orientation = type { i8, i32, i8, %"class.Orientation::Animation" }
%"class.Orientation::Animation" = type { i32, %"class.Framework::Timer" }
%"class.Framework::Timer" = type { i32, float, i8, i8, float, float }

@g_orient = external dso_local global %class.Orientation, align 4
@.str.14 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [6 x i8], align 1
@_ZL12g_OrientKeys = external hidden local_unnamed_addr global [7 x i8], align 1

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z16ApplyOrientationi(i32 noundef) 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 #1 {
  %4 = zext i8 %0 to i32
  switch i8 %0, label %10 [
    i8 27, label %5
    i8 32, label %6
  ]

5:                                                ; preds = %3
  tail call void @glutLeaveMainLoop()
  br label %.loopexit

6:                                                ; preds = %3
  %7 = tail call noundef zeroext i1 @_ZN11Orientation11ToggleSlerpEv(ptr noundef nonnull align 4 dereferenceable(36) @g_orient)
  %8 = select i1 %7, ptr @.str.14, ptr @.str.15
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %8)
  br label %10

10:                                               ; preds = %6, %3
  %11 = load i8, ptr @_ZL12g_OrientKeys, align 1, !tbaa !5
  %12 = sext i8 %11 to i32
  %13 = icmp eq i32 %4, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %10
  tail call void @_Z16ApplyOrientationi(i32 noundef 0)
  br label %15

15:                                               ; preds = %10, %14
  %16 = load i8, ptr getelementptr inbounds (i8, ptr @_ZL12g_OrientKeys, i64 1), align 1, !tbaa !5
  %17 = sext i8 %16 to i32
  %18 = icmp eq i32 %4, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  tail call void @_Z16ApplyOrientationi(i32 noundef 1)
  br label %20

20:                                               ; preds = %19, %15
  %21 = load i8, ptr getelementptr inbounds (i8, ptr @_ZL12g_OrientKeys, i64 2), align 1, !tbaa !5
  %22 = sext i8 %21 to i32
  %23 = icmp eq i32 %4, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %20
  tail call void @_Z16ApplyOrientationi(i32 noundef 2)
  br label %25

25:                                               ; preds = %24, %20
  %26 = load i8, ptr getelementptr inbounds (i8, ptr @_ZL12g_OrientKeys, i64 3), align 1, !tbaa !5
  %27 = sext i8 %26 to i32
  %28 = icmp eq i32 %4, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  tail call void @_Z16ApplyOrientationi(i32 noundef 3)
  br label %30

30:                                               ; preds = %29, %25
  %31 = load i8, ptr getelementptr inbounds (i8, ptr @_ZL12g_OrientKeys, i64 4), align 1, !tbaa !5
  %32 = sext i8 %31 to i32
  %33 = icmp eq i32 %4, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %30
  tail call void @_Z16ApplyOrientationi(i32 noundef 4)
  br label %35

35:                                               ; preds = %34, %30
  %36 = load i8, ptr getelementptr inbounds (i8, ptr @_ZL12g_OrientKeys, i64 5), align 1, !tbaa !5
  %37 = sext i8 %36 to i32
  %38 = icmp eq i32 %4, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %35
  tail call void @_Z16ApplyOrientationi(i32 noundef 5)
  br label %40

40:                                               ; preds = %39, %35
  %41 = load i8, ptr getelementptr inbounds (i8, ptr @_ZL12g_OrientKeys, i64 6), align 1, !tbaa !5
  %42 = sext i8 %41 to i32
  %43 = icmp eq i32 %4, %42
  br i1 %43, label %44, label %.loopexit

44:                                               ; preds = %40
  tail call void @_Z16ApplyOrientationi(i32 noundef 6)
  br label %.loopexit

.loopexit:                                        ; preds = %40, %44, %5
  ret void
}

declare void @glutLeaveMainLoop() local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN11Orientation11ToggleSlerpEv(ptr noundef nonnull align 4 dereferenceable(36)) local_unnamed_addr #3 align 2

attributes #0 = { 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 #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 = { 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" }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass