; LLVM IR from paroj/gltut :: Tut 15 Many Images/ManyImages.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_useMipmapTexture = external dso_local global i8, align 1
@g_drawCorridor = external dso_local global i8, align 1
@g_samplerNames = external dso_local global [6 x ptr], align 16
@.str.18 = external hidden unnamed_addr constant [13 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 %31 [
    i32 27, label %10
    i32 32, label %19
    i32 121, label %24
    i32 112, label %29
  ]

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 %53

19:                                               ; preds = %3
  %20 = load i8, ptr @g_useMipmapTexture, 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_useMipmapTexture, align 1, !tbaa !12
  br label %31

24:                                               ; preds = %3
  %25 = load i8, ptr @g_drawCorridor, 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_drawCorridor, align 1, !tbaa !12
  br label %31

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

31:                                               ; preds = %29, %24, %19, %3
  %32 = load i8, ptr %4, align 1, !tbaa !5
  %33 = zext i8 %32 to i32
  %34 = icmp sle i32 49, %33
  br i1 %34, label %35, label %53

35:                                               ; preds = %31
  %36 = load i8, ptr %4, align 1, !tbaa !5
  %37 = zext i8 %36 to i32
  %38 = icmp sle i32 %37, 57
  br i1 %38, label %39, label %53

39:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %40 = load i8, ptr %4, align 1, !tbaa !5
  %41 = zext i8 %40 to i32
  %42 = sub nsw i32 %41, 49
  store i32 %42, ptr %7, align 4, !tbaa !8
  %43 = load i32, ptr %7, align 4, !tbaa !8
  %44 = icmp slt i32 %43, 6
  br i1 %44, label %45, label %52

45:                                               ; preds = %39
  %46 = load i32, ptr %7, align 4, !tbaa !8
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [6 x ptr], ptr @g_samplerNames, i64 0, i64 %47
  %49 = load ptr, ptr %48, align 8, !tbaa !10
  %50 = call i32 (ptr, ...) @printf(ptr noundef @.str.18, ptr noundef %49)
  %51 = load i32, ptr %7, align 4, !tbaa !8
  store i32 %51, ptr @g_currSampler, align 4, !tbaa !8
  br label %52

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

53:                                               ; preds = %52, %35, %31, %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_useMipmapTexture = external dso_local local_unnamed_addr global i8, align 1
@g_drawCorridor = external dso_local local_unnamed_addr global i8, align 1
@g_samplerNames = external dso_local local_unnamed_addr global [6 x ptr], align 16
@.str.18 = external hidden unnamed_addr constant [13 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 %22 [
    i8 27, label %5
    i8 32, label %14
    i8 121, label %17
    i8 112, label %20
  ]

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 %.thread

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

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

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

22:                                               ; preds = %3
  %23 = add i8 %0, -49
  %or.cond12 = icmp ult i8 %23, 6
  br i1 %or.cond12, label %24, label %.thread

24:                                               ; preds = %22
  %25 = add nsw i32 %4, -49
  %26 = zext nneg i32 %25 to i64
  %27 = getelementptr inbounds [6 x ptr], ptr @g_samplerNames, i64 0, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.18, ptr noundef %28)
  store i32 %25, ptr @g_currSampler, align 4, !tbaa !13
  br label %.thread

.thread:                                          ; preds = %14, %17, %20, %24, %22, %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,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass