; LLVM IR from ARM-software/Arm-2D :: examples/common/benchmark (benchmark_generic)

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

%struct.arm_2d_layer_t = type { ptr, %struct.arm_2d_region_t, i32, i8, i8, i16, %union.arm_2d_alpha_samples_4pts_t }
%struct.arm_2d_region_t = type { %union.anon.9, %union.anon.10 }
%union.anon.9 = type { %struct.arm_2d_location_t }
%struct.arm_2d_location_t = type { i16, i16 }
%union.anon.10 = type { %struct.arm_2d_size_t }
%struct.arm_2d_size_t = type { i16, i16 }
%union.arm_2d_alpha_samples_4pts_t = type { %struct.anon.14 }
%struct.anon.14 = type { i8, i8, i8, i8 }
%struct.floating_range_t = type { %struct.arm_2d_region_t, ptr, %struct.arm_2d_location_t }

@s_ptRefreshLayers = external hidden global [5 x %struct.arm_2d_layer_t], align 16
@benchmark_generic_do_events.s_wCounter = external hidden global i32, align 4
@benchmark_generic_do_events.s_wFrameCounter = external hidden global i32, align 4
@s_ptFloatingBoxes = external hidden global [5 x %struct.floating_range_t], align 16

; Function Attrs: nounwind uwtable
define dso_local void @benchmark_generic_do_events() #0 {
  %1 = load i32, ptr @benchmark_generic_do_events.s_wFrameCounter, align 4, !tbaa !5
  %2 = add i32 %1, 1
  store i32 %2, ptr @benchmark_generic_do_events.s_wFrameCounter, align 4, !tbaa !5
  call void @__update_boxes(ptr noundef @s_ptFloatingBoxes, i64 noundef 5)
  %3 = load i32, ptr @benchmark_generic_do_events.s_wFrameCounter, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 25
  br i1 %4, label %5, label %15

5:                                                ; preds = %0
  store i32 0, ptr @benchmark_generic_do_events.s_wFrameCounter, align 4, !tbaa !5
  %6 = load i32, ptr @benchmark_generic_do_events.s_wCounter, align 4, !tbaa !5
  %7 = add i32 %6, 1
  store i32 %7, ptr @benchmark_generic_do_events.s_wCounter, align 4, !tbaa !5
  %8 = and i32 %6, 3
  switch i32 %8, label %13 [
    i32 0, label %9
    i32 1, label %10
    i32 2, label %11
    i32 3, label %12
  ]

9:                                                ; preds = %5
  store i32 1, ptr getelementptr inbounds (%struct.arm_2d_layer_t, ptr getelementptr inbounds ([5 x %struct.arm_2d_layer_t], ptr @s_ptRefreshLayers, i64 0, i64 3), i32 0, i32 2), align 16, !tbaa !9
  br label %13

10:                                               ; preds = %5
  store i32 9, ptr getelementptr inbounds (%struct.arm_2d_layer_t, ptr getelementptr inbounds ([5 x %struct.arm_2d_layer_t], ptr @s_ptRefreshLayers, i64 0, i64 3), i32 0, i32 2), align 16, !tbaa !9
  br label %13

11:                                               ; preds = %5
  store i32 5, ptr getelementptr inbounds (%struct.arm_2d_layer_t, ptr getelementptr inbounds ([5 x %struct.arm_2d_layer_t], ptr @s_ptRefreshLayers, i64 0, i64 3), i32 0, i32 2), align 16, !tbaa !9
  br label %13

12:                                               ; preds = %5
  store i32 13, ptr getelementptr inbounds (%struct.arm_2d_layer_t, ptr getelementptr inbounds ([5 x %struct.arm_2d_layer_t], ptr @s_ptRefreshLayers, i64 0, i64 3), i32 0, i32 2), align 16, !tbaa !9
  br label %13

13:                                               ; preds = %12, %11, %10, %9, %5
  %14 = load i32, ptr getelementptr inbounds (%struct.arm_2d_layer_t, ptr getelementptr inbounds ([5 x %struct.arm_2d_layer_t], ptr @s_ptRefreshLayers, i64 0, i64 3), i32 0, i32 2), align 16, !tbaa !9
  store i32 %14, ptr getelementptr inbounds (%struct.arm_2d_layer_t, ptr getelementptr inbounds ([5 x %struct.arm_2d_layer_t], ptr @s_ptRefreshLayers, i64 0, i64 1), i32 0, i32 2), align 16, !tbaa !9
  br label %15

15:                                               ; preds = %13, %0
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @__update_boxes(ptr noundef, i64 noundef) #0

attributes #0 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"arm_2d_layer_t", !11, i64 0, !12, i64 8, !6, i64 16, !7, i64 20, !7, i64 21, !7, i64 21, !7, i64 21, !13, i64 22, !7, i64 24}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"arm_2d_region_t", !7, i64 0, !7, i64 4}
!13 = !{!"short", !7, i64 0}


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

%struct.arm_2d_layer_t = type { ptr, %struct.arm_2d_region_t, i32, i8, i8, i16, %union.arm_2d_alpha_samples_4pts_t }
%struct.arm_2d_region_t = type { %union.anon.9, %union.anon.10 }
%union.anon.9 = type { %struct.arm_2d_location_t }
%struct.arm_2d_location_t = type { i16, i16 }
%union.anon.10 = type { %struct.arm_2d_size_t }
%struct.arm_2d_size_t = type { i16, i16 }
%union.arm_2d_alpha_samples_4pts_t = type { %struct.anon.14 }
%struct.anon.14 = type { i8, i8, i8, i8 }
%struct.floating_range_t = type { %struct.arm_2d_region_t, ptr, %struct.arm_2d_location_t }

@s_ptRefreshLayers = external hidden local_unnamed_addr global [5 x %struct.arm_2d_layer_t], align 16
@benchmark_generic_do_events.s_wCounter = external hidden local_unnamed_addr global i32, align 4
@benchmark_generic_do_events.s_wFrameCounter = external hidden local_unnamed_addr global i32, align 4
@s_ptFloatingBoxes = external hidden global [5 x %struct.floating_range_t], align 16
@switch.table.benchmark_generic_do_events = private unnamed_addr constant [4 x i32] [i32 1, i32 9, i32 5, i32 13], align 4

; Function Attrs: nounwind uwtable
define dso_local void @benchmark_generic_do_events() local_unnamed_addr #0 {
  %1 = load i32, ptr @benchmark_generic_do_events.s_wFrameCounter, align 4, !tbaa !5
  %2 = add i32 %1, 1
  store i32 %2, ptr @benchmark_generic_do_events.s_wFrameCounter, align 4, !tbaa !5
  tail call void @__update_boxes(ptr noundef nonnull @s_ptFloatingBoxes, i64 noundef 5)
  %3 = load i32, ptr @benchmark_generic_do_events.s_wFrameCounter, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 25
  br i1 %4, label %switch.lookup, label %9

switch.lookup:                                    ; preds = %0
  store i32 0, ptr @benchmark_generic_do_events.s_wFrameCounter, align 4, !tbaa !5
  %5 = load i32, ptr @benchmark_generic_do_events.s_wCounter, align 4, !tbaa !5
  %6 = add i32 %5, 1
  store i32 %6, ptr @benchmark_generic_do_events.s_wCounter, align 4, !tbaa !5
  %7 = and i32 %5, 3
  %8 = zext nneg i32 %7 to i64
  %switch.gep = getelementptr inbounds [4 x i32], ptr @switch.table.benchmark_generic_do_events, i64 0, i64 %8
  %switch.load = load i32, ptr %switch.gep, align 4
  store i32 %switch.load, ptr getelementptr inbounds (i8, ptr @s_ptRefreshLayers, i64 112), align 16, !tbaa !9
  store i32 %switch.load, ptr getelementptr inbounds (i8, ptr @s_ptRefreshLayers, i64 48), align 16, !tbaa !9
  br label %9

9:                                                ; preds = %switch.lookup, %0
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @__update_boxes(ptr noundef, i64 noundef) local_unnamed_addr #0

attributes #0 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"arm_2d_layer_t", !11, i64 0, !12, i64 8, !6, i64 16, !7, i64 20, !7, i64 21, !7, i64 21, !7, i64 21, !13, i64 22, !7, i64 24}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"arm_2d_region_t", !7, i64 0, !7, i64 4}
!13 = !{!"short", !7, i64 0}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,SCCPPass,SimplifyCFGPass,TailCallElimPass