; LLVM IR from paroj/gltut :: Tut 16 Gamma and Textures/GammaCheckers.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_pPlane = external dso_local global ptr, align 8
@g_pCorridor = external dso_local global ptr, align 8
@g_camTimer = external dso_local global %"class.Framework::Timer", align 4
@g_currSampler = external dso_local global i32, align 4
@g_drawCorridor = external dso_local global i8, align 1
@g_drawGammaTexture = external dso_local global i8, align 1
@g_drawGammaProgram = external dso_local global i8, align 1
@.str.13 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [23 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: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8keyboardhii(i8 noundef zeroext %0, i32 noundef %1, i32 noundef %2) #3 {
  %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 97, label %19
    i32 103, label %24
    i32 32, label %29
    i32 121, label %38
    i32 112, label %43
  ]

10:                                               ; preds = %3
  %11 = load ptr, ptr @g_pPlane, 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_pCorridor, 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_pPlane, align 8, !tbaa !10
  store ptr null, ptr @g_pCorridor, align 8, !tbaa !10
  call void @glutLeaveMainLoop()
  br label %73

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

24:                                               ; preds = %3
  %25 = load i8, ptr @g_drawGammaTexture, align 1, !tbaa !12, !range !14, !noundef !15
  %26 = trunc i8 %25 to i1
  %27 = xor i1 %26, true
  %28 = zext i1 %27 to i8
  store i8 %28, ptr @g_drawGammaTexture, align 1, !tbaa !12
  br label %45

29:                                               ; preds = %3
  %30 = load i8, ptr @g_drawGammaProgram, align 1, !tbaa !12, !range !14, !noundef !15
  %31 = trunc i8 %30 to i1
  %32 = xor i1 %31, true
  %33 = zext i1 %32 to i8
  store i8 %33, ptr @g_drawGammaProgram, align 1, !tbaa !12
  %34 = load i8, ptr @g_drawGammaTexture, 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_drawGammaTexture, align 1, !tbaa !12
  br label %45

38:                                               ; preds = %3
  %39 = load i8, ptr @g_drawCorridor, align 1, !tbaa !12, !range !14, !noundef !15
  %40 = trunc i8 %39 to i1
  %41 = xor i1 %40, true
  %42 = zext i1 %41 to i8
  store i8 %42, ptr @g_drawCorridor, align 1, !tbaa !12
  br label %45

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

45:                                               ; preds = %43, %38, %29, %24, %19, %3
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.13)
  %47 = load i8, ptr @g_drawGammaProgram, align 1, !tbaa !12, !range !14, !noundef !15
  %48 = trunc i8 %47 to i1
  %49 = zext i1 %48 to i64
  %50 = select i1 %48, ptr @.str.15, ptr @.str.16
  %51 = call i32 (ptr, ...) @printf(ptr noundef @.str.14, ptr noundef %50)
  %52 = load i8, ptr @g_drawGammaTexture, align 1, !tbaa !12, !range !14, !noundef !15
  %53 = trunc i8 %52 to i1
  %54 = zext i1 %53 to i64
  %55 = select i1 %53, ptr @.str.15, ptr @.str.16
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.17, ptr noundef %55)
  %57 = load i8, ptr %4, align 1, !tbaa !5
  %58 = zext i8 %57 to i32
  %59 = icmp sle i32 49, %58
  br i1 %59, label %60, label %73

60:                                               ; preds = %45
  %61 = load i8, ptr %4, align 1, !tbaa !5
  %62 = zext i8 %61 to i32
  %63 = icmp sle i32 %62, 57
  br i1 %63, label %64, label %73

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

70:                                               ; preds = %64
  %71 = load i32, ptr %7, align 4, !tbaa !8
  store i32 %71, ptr @g_currSampler, align 4, !tbaa !8
  br label %72

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

73:                                               ; preds = %72, %60, %45, %18
  ret void
}

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

declare void @glutLeaveMainLoop() #1

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

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 = { 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 = { 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 #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_pPlane = external dso_local local_unnamed_addr global ptr, align 8
@g_pCorridor = external dso_local local_unnamed_addr global ptr, align 8
@g_camTimer = external dso_local global %"class.Framework::Timer", align 4
@g_currSampler = external dso_local local_unnamed_addr global i32, align 4
@g_drawCorridor = external dso_local local_unnamed_addr global i8, align 1
@g_drawGammaTexture = external dso_local local_unnamed_addr global i8, align 1
@g_drawGammaProgram = external dso_local local_unnamed_addr global i8, align 1
@.str.13 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [23 x i8], align 1

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 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 #2 {
  %4 = zext i8 %0 to i32
  switch i8 %0, label %30 [
    i8 27, label %5
    i8 97, label %14
    i8 103, label %17
    i8 32, label %20
    i8 121, label %25
    i8 112, label %28
  ]

5:                                                ; preds = %3
  %6 = load ptr, ptr @g_pPlane, 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_pCorridor, 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_pPlane, align 8, !tbaa !5
  store ptr null, ptr @g_pCorridor, align 8, !tbaa !5
  tail call void @glutLeaveMainLoop()
  br label %43

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

17:                                               ; preds = %3
  %18 = load i8, ptr @g_drawGammaTexture, align 1, !tbaa !9, !range !11, !noundef !12
  %19 = xor i8 %18, 1
  store i8 %19, ptr @g_drawGammaTexture, align 1, !tbaa !9
  br label %30

20:                                               ; preds = %3
  %21 = load i8, ptr @g_drawGammaProgram, align 1, !tbaa !9, !range !11, !noundef !12
  %22 = xor i8 %21, 1
  store i8 %22, ptr @g_drawGammaProgram, align 1, !tbaa !9
  %23 = load i8, ptr @g_drawGammaTexture, align 1, !tbaa !9, !range !11, !noundef !12
  %24 = xor i8 %23, 1
  store i8 %24, ptr @g_drawGammaTexture, align 1, !tbaa !9
  br label %30

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

28:                                               ; preds = %3
  %29 = tail call noundef zeroext i1 @_ZN9Framework5Timer11TogglePauseEv(ptr noundef nonnull align 4 dereferenceable(20) @g_camTimer)
  br label %30

30:                                               ; preds = %28, %25, %20, %17, %14, %3
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13)
  %32 = load i8, ptr @g_drawGammaProgram, align 1, !tbaa !9, !range !11, !noundef !12
  %33 = trunc nuw i8 %32 to i1
  %34 = select i1 %33, ptr @.str.15, ptr @.str.16
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.14, ptr noundef nonnull %34)
  %36 = load i8, ptr @g_drawGammaTexture, align 1, !tbaa !9, !range !11, !noundef !12
  %37 = trunc nuw i8 %36 to i1
  %38 = select i1 %37, ptr @.str.15, ptr @.str.16
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.17, ptr noundef nonnull %38)
  %40 = add i8 %0, -49
  %or.cond11 = icmp ult i8 %40, 2
  br i1 %or.cond11, label %41, label %43

41:                                               ; preds = %30
  %42 = add nsw i32 %4, -49
  store i32 %42, ptr @g_currSampler, align 4, !tbaa !13
  br label %43

43:                                               ; preds = %41, %30, %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

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 = { 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 = { "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,SROAPass,SimplifyCFGPass,TailCallElimPass