; LLVM IR from Phoenix15049/Absolute :: Input.ll (ZN5Input6UpdateEv)

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

%union.SDL_Event = type { %struct.SDL_SensorEvent, [8 x i8] }
%struct.SDL_SensorEvent = type { i32, i32, i32, [6 x float], i64 }
%class.Input = type { i8, i8, i8, i8, i8, i8, i8, i32, i32, i32, i32 }
%struct.SDL_KeyboardEvent = type { i32, i32, i32, i8, i8, i8, i8, %struct.SDL_Keysym }
%struct.SDL_Keysym = type { i32, i32, i16, i32 }
%struct.SDL_MouseButtonEvent = type { i32, i32, i32, i32, i8, i8, i8, i8, i32, i32 }
%struct.SDL_MouseMotionEvent = type { i32, i32, i32, i32, i32, i32, i32, i32, i32 }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5Input6UpdateEv(ptr noundef nonnull align 4 dereferenceable(24) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca %union.SDL_Event, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 56, ptr %3) #3
  %5 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 7
  store i32 0, ptr %5, align 4, !tbaa !9
  %6 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 8
  store i32 0, ptr %6, align 4, !tbaa !13
  %7 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 9
  store i32 0, ptr %7, align 4, !tbaa !14
  %8 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 10
  store i32 0, ptr %8, align 4, !tbaa !15
  br label %9

9:                                                ; preds = %65, %1
  %10 = call i32 @SDL_PollEvent(ptr noundef %3)
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %66

12:                                               ; preds = %9
  %13 = load i32, ptr %3, align 8, !tbaa !16
  switch i32 %13, label %65 [
    i32 256, label %14
    i32 768, label %16
    i32 769, label %23
    i32 1025, label %30
    i32 1026, label %41
    i32 1024, label %52
  ]

14:                                               ; preds = %12
  %15 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 2
  store i8 1, ptr %15, align 2, !tbaa !17
  br label %65

16:                                               ; preds = %12
  %17 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 3
  store i8 1, ptr %17, align 1, !tbaa !18
  %18 = getelementptr inbounds %struct.SDL_KeyboardEvent, ptr %3, i32 0, i32 7
  %19 = getelementptr inbounds %struct.SDL_Keysym, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !16
  %21 = trunc i32 %20 to i8
  %22 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 1
  store i8 %21, ptr %22, align 1, !tbaa !19
  br label %65

23:                                               ; preds = %12
  %24 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 3
  store i8 0, ptr %24, align 1, !tbaa !18
  %25 = getelementptr inbounds %struct.SDL_KeyboardEvent, ptr %3, i32 0, i32 7
  %26 = getelementptr inbounds %struct.SDL_Keysym, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !16
  %28 = trunc i32 %27 to i8
  %29 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 0
  store i8 %28, ptr %29, align 4, !tbaa !20
  br label %65

30:                                               ; preds = %12
  %31 = getelementptr inbounds %struct.SDL_MouseButtonEvent, ptr %3, i32 0, i32 4
  %32 = load i8, ptr %31, align 8, !tbaa !16
  %33 = zext i8 %32 to i32
  switch i32 %33, label %40 [
    i32 1, label %34
    i32 3, label %36
    i32 2, label %38
  ]

34:                                               ; preds = %30
  %35 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 4
  store i8 1, ptr %35, align 4, !tbaa !21
  br label %40

36:                                               ; preds = %30
  %37 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 5
  store i8 1, ptr %37, align 1, !tbaa !22
  br label %40

38:                                               ; preds = %30
  %39 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 6
  store i8 1, ptr %39, align 2, !tbaa !23
  br label %40

40:                                               ; preds = %38, %36, %34, %30
  br label %65

41:                                               ; preds = %12
  %42 = getelementptr inbounds %struct.SDL_MouseButtonEvent, ptr %3, i32 0, i32 4
  %43 = load i8, ptr %42, align 8, !tbaa !16
  %44 = zext i8 %43 to i32
  switch i32 %44, label %51 [
    i32 1, label %45
    i32 3, label %47
    i32 2, label %49
  ]

45:                                               ; preds = %41
  %46 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 4
  store i8 0, ptr %46, align 4, !tbaa !21
  br label %51

47:                                               ; preds = %41
  %48 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 5
  store i8 0, ptr %48, align 1, !tbaa !22
  br label %51

49:                                               ; preds = %41
  %50 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 6
  store i8 0, ptr %50, align 2, !tbaa !23
  br label %51

51:                                               ; preds = %49, %47, %45, %41
  br label %65

52:                                               ; preds = %12
  %53 = getelementptr inbounds %struct.SDL_MouseMotionEvent, ptr %3, i32 0, i32 7
  %54 = load i32, ptr %53, align 4, !tbaa !16
  %55 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 7
  store i32 %54, ptr %55, align 4, !tbaa !9
  %56 = getelementptr inbounds %struct.SDL_MouseMotionEvent, ptr %3, i32 0, i32 8
  %57 = load i32, ptr %56, align 8, !tbaa !16
  %58 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 8
  store i32 %57, ptr %58, align 4, !tbaa !13
  %59 = getelementptr inbounds %struct.SDL_MouseMotionEvent, ptr %3, i32 0, i32 5
  %60 = load i32, ptr %59, align 4, !tbaa !16
  %61 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 9
  store i32 %60, ptr %61, align 4, !tbaa !14
  %62 = getelementptr inbounds %struct.SDL_MouseMotionEvent, ptr %3, i32 0, i32 6
  %63 = load i32, ptr %62, align 8, !tbaa !16
  %64 = getelementptr inbounds %class.Input, ptr %4, i32 0, i32 10
  store i32 %63, ptr %64, align 4, !tbaa !15
  br label %65

65:                                               ; preds = %52, %51, %40, %23, %16, %14, %12
  br label %9, !llvm.loop !24

66:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 56, ptr %3) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare i32 @SDL_PollEvent(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !12, i64 8}
!10 = !{!"_ZTS5Input", !7, i64 0, !7, i64 1, !11, i64 2, !11, i64 3, !11, i64 4, !11, i64 5, !11, i64 6, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20}
!11 = !{!"bool", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 12}
!14 = !{!10, !12, i64 16}
!15 = !{!10, !12, i64 20}
!16 = !{!7, !7, i64 0}
!17 = !{!10, !11, i64 2}
!18 = !{!10, !11, i64 3}
!19 = !{!10, !7, i64 1}
!20 = !{!10, !7, i64 0}
!21 = !{!10, !11, i64 4}
!22 = !{!10, !11, i64 5}
!23 = !{!10, !11, i64 6}
!24 = distinct !{!24, !25}
!25 = !{!"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"

%union.SDL_Event = type { %struct.SDL_SensorEvent, [8 x i8] }
%struct.SDL_SensorEvent = type { i32, i32, i32, [6 x float], i64 }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5Input6UpdateEv(ptr nocapture noundef nonnull writeonly align 4 dereferenceable(24) %0) local_unnamed_addr #0 align 2 {
  %2 = alloca %union.SDL_Event, align 8
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %2) #4
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %3, i8 0, i64 16, i1 false)
  %4 = call i32 @SDL_PollEvent(ptr noundef nonnull %2)
  %.not1 = icmp eq i32 %4, 0
  br i1 %.not1, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds i8, ptr %2, i64 20
  %6 = getelementptr inbounds i8, ptr %2, i64 16
  %7 = getelementptr inbounds i8, ptr %0, i64 6
  %8 = getelementptr inbounds i8, ptr %0, i64 5
  %9 = getelementptr inbounds i8, ptr %0, i64 4
  %10 = getelementptr inbounds i8, ptr %0, i64 3
  %11 = getelementptr inbounds i8, ptr %0, i64 1
  %12 = getelementptr inbounds i8, ptr %0, i64 2
  br label %13

13:                                               ; preds = %.lr.ph, %35
  %14 = load i32, ptr %2, align 8, !tbaa !5
  switch i32 %14, label %35 [
    i32 256, label %15
    i32 768, label %16
    i32 769, label %19
    i32 1025, label %22
    i32 1026, label %27
    i32 1024, label %32
  ]

15:                                               ; preds = %13
  store i8 1, ptr %12, align 2, !tbaa !8
  br label %35

16:                                               ; preds = %13
  store i8 1, ptr %10, align 1, !tbaa !12
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = trunc i32 %17 to i8
  store i8 %18, ptr %11, align 1, !tbaa !13
  br label %35

19:                                               ; preds = %13
  store i8 0, ptr %10, align 1, !tbaa !12
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = trunc i32 %20 to i8
  store i8 %21, ptr %0, align 4, !tbaa !14
  br label %35

22:                                               ; preds = %13
  %23 = load i8, ptr %6, align 8, !tbaa !5
  switch i8 %23, label %35 [
    i8 1, label %24
    i8 3, label %25
    i8 2, label %26
  ]

24:                                               ; preds = %22
  store i8 1, ptr %9, align 4, !tbaa !15
  br label %35

25:                                               ; preds = %22
  store i8 1, ptr %8, align 1, !tbaa !16
  br label %35

26:                                               ; preds = %22
  store i8 1, ptr %7, align 2, !tbaa !17
  br label %35

27:                                               ; preds = %13
  %28 = load i8, ptr %6, align 8, !tbaa !5
  switch i8 %28, label %35 [
    i8 1, label %29
    i8 3, label %30
    i8 2, label %31
  ]

29:                                               ; preds = %27
  store i8 0, ptr %9, align 4, !tbaa !15
  br label %35

30:                                               ; preds = %27
  store i8 0, ptr %8, align 1, !tbaa !16
  br label %35

31:                                               ; preds = %27
  store i8 0, ptr %7, align 2, !tbaa !17
  br label %35

32:                                               ; preds = %13
  %33 = load <4 x i32>, ptr %5, align 4, !tbaa !5
  %34 = shufflevector <4 x i32> %33, <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 0, i32 1>
  store <4 x i32> %34, ptr %3, align 4, !tbaa !18
  br label %35

35:                                               ; preds = %27, %29, %30, %31, %22, %24, %25, %26, %32, %19, %16, %15, %13
  %36 = call i32 @SDL_PollEvent(ptr noundef nonnull %2)
  %.not = icmp eq i32 %36, 0
  br i1 %.not, label %._crit_edge, label %13, !llvm.loop !19

._crit_edge:                                      ; preds = %35, %1
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %2) #4
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare i32 @SDL_PollEvent(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !10, i64 2}
!9 = !{!"_ZTS5Input", !6, i64 0, !6, i64 1, !10, i64 2, !10, i64 3, !10, i64 4, !10, i64 5, !10, i64 6, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!10 = !{!"bool", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!9, !10, i64 3}
!13 = !{!9, !6, i64 1}
!14 = !{!9, !6, i64 0}
!15 = !{!9, !10, i64 4}
!16 = !{!9, !10, i64 5}
!17 = !{!9, !10, i64 6}
!18 = !{!11, !11, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass