; LLVM IR from ARM-software/Arm-2D :: Helper/Source (arm_2d_helper_scene)

; 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_scene_player_t = type { %struct.arm_2d_helper_pfb_t, %struct.anon.1, %struct.anon.2 }
%struct.arm_2d_helper_pfb_t = type { [344 x i8], %struct.anon.0 }
%struct.anon.0 = type { i64, i32, i32 }
%struct.anon.1 = type { i32, i32, i64, i64, i32, float, i16, i16, i32, i64 }
%struct.anon.2 = type { %struct.anon.3, %struct.anon.4, %struct.anon.5, %struct.anon.31 }
%struct.anon.3 = type { ptr, ptr }
%struct.anon.4 = type { i16, i8, i8 }
%struct.anon.5 = type { ptr, i8, i16, %union.anon, %union.__arm_2d_helper_scene_switch_t, %struct.arm_2d_location_t, i16, i16, i64 }
%union.anon = type { %struct.anon.23 }
%struct.anon.23 = type { %struct.arm_2d_tile_t, %struct.arm_2d_filter_iir_blur_descriptor_t }
%struct.arm_2d_tile_t = type { %union.anon.8, %union.anon.19, %union.anon.22 }
%union.anon.8 = type { %struct.anon.9 }
%struct.anon.9 = type { i8, %union.arm_2d_color_info_t, %union.anon.12 }
%union.arm_2d_color_info_t = type { %struct.anon.10 }
%struct.anon.10 = type { i8 }
%union.anon.12 = type { i16 }
%union.anon.19 = type { %struct.arm_2d_region_t }
%struct.arm_2d_region_t = type { %union.anon.20, %union.anon.21 }
%union.anon.20 = type { %struct.arm_2d_location_t }
%union.anon.21 = type { %struct.arm_2d_size_t }
%struct.arm_2d_size_t = type { i16, i16 }
%union.anon.22 = type { ptr }
%struct.arm_2d_filter_iir_blur_descriptor_t = type { [72 x i8], %struct.arm_2d_scratch_mem_t }
%struct.arm_2d_scratch_mem_t = type { %union.anon.24, i64 }
%union.anon.24 = type { %union.anon.25 }
%union.anon.25 = type { %struct.anon.26 }
%struct.anon.26 = type { i32 }
%union.__arm_2d_helper_scene_switch_t = type { i16 }
%struct.arm_2d_location_t = type { i16, i16 }
%struct.anon.31 = type { %struct.arm_2d_scene_evt_t, %struct.arm_2d_scene_evt_t }
%struct.arm_2d_scene_evt_t = type { ptr, ptr }
%struct.anon = type { i8, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [89 x i8], align 1
@__PRETTY_FUNCTION__.arm_2d_scene_player_finish_manual_switching = external hidden unnamed_addr constant [103 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @arm_2d_scene_player_get_switching_status(ptr noundef nonnull) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @arm_2d_scene_player_finish_manual_switching(ptr noundef nonnull %0, i1 noundef zeroext %1, i64 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  %10 = zext i1 %1 to i8
  store i8 %10, ptr %6, align 1, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !11
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp ne ptr null, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  br label %15

14:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 509, ptr noundef @__PRETTY_FUNCTION__.arm_2d_scene_player_finish_manual_switching) #4
  unreachable

15:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = call i32 @arm_2d_scene_player_get_switching_status(ptr noundef %16)
  store i32 %17, ptr %8, align 4, !tbaa !13
  %18 = load i32, ptr %8, align 4, !tbaa !13
  %19 = icmp eq i32 0, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  store i32 -13, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %104

21:                                               ; preds = %15
  %22 = load i32, ptr %8, align 4, !tbaa !13
  %23 = icmp ne i32 %22, 1
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %104

25:                                               ; preds = %21
  br label %26

26:                                               ; preds = %25
  %27 = call i64 @arm_2d_helper_get_system_timestamp()
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.arm_2d_scene_player_t, ptr %28, i32 0, i32 2
  %30 = getelementptr inbounds %struct.anon.2, ptr %29, i32 0, i32 2
  %31 = getelementptr inbounds %struct.anon.5, ptr %30, i32 0, i32 8
  store i64 %27, ptr %31, align 8, !tbaa !15
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.arm_2d_scene_player_t, ptr %32, i32 0, i32 2
  %34 = getelementptr inbounds %struct.anon.2, ptr %33, i32 0, i32 1
  %35 = load i16, ptr %34, align 8
  %36 = and i16 %35, -9
  %37 = or i16 %36, 8
  store i16 %37, ptr %34, align 8
  %38 = load i8, ptr %6, align 1, !tbaa !9, !range !29, !noundef !30
  %39 = trunc i8 %38 to i1
  %40 = zext i1 %39 to i8
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.arm_2d_scene_player_t, ptr %41, i32 0, i32 2
  %43 = getelementptr inbounds %struct.anon.2, ptr %42, i32 0, i32 1
  %44 = zext i8 %40 to i16
  %45 = load i16, ptr %43, align 8
  %46 = and i16 %44, 1
  %47 = shl i16 %46, 2
  %48 = and i16 %45, -5
  %49 = or i16 %48, %47
  store i16 %49, ptr %43, align 8
  %50 = trunc i16 %46 to i8
  %51 = load i64, ptr %7, align 8, !tbaa !11
  %52 = icmp slt i64 %51, 65535
  br i1 %52, label %53, label %55

53:                                               ; preds = %26
  %54 = load i64, ptr %7, align 8, !tbaa !11
  br label %56

55:                                               ; preds = %26
  br label %56

56:                                               ; preds = %55, %53
  %57 = phi i64 [ %54, %53 ], [ 65535, %55 ]
  %58 = trunc i64 %57 to i16
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.arm_2d_scene_player_t, ptr %59, i32 0, i32 2
  %61 = getelementptr inbounds %struct.anon.2, ptr %60, i32 0, i32 2
  %62 = getelementptr inbounds %struct.anon.5, ptr %61, i32 0, i32 7
  store i16 %58, ptr %62, align 8, !tbaa !31
  %63 = load i64, ptr %7, align 8, !tbaa !11
  %64 = icmp sgt i64 %63, 200
  br i1 %64, label %65, label %67

65:                                               ; preds = %56
  %66 = load i64, ptr %7, align 8, !tbaa !11
  br label %68

67:                                               ; preds = %56
  br label %68

68:                                               ; preds = %67, %65
  %69 = phi i64 [ %66, %65 ], [ 200, %67 ]
  %70 = trunc i64 %69 to i16
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.arm_2d_scene_player_t, ptr %71, i32 0, i32 2
  %73 = getelementptr inbounds %struct.anon.2, ptr %72, i32 0, i32 2
  %74 = getelementptr inbounds %struct.anon.5, ptr %73, i32 0, i32 7
  store i16 %70, ptr %74, align 8, !tbaa !31
  br label %75

75:                                               ; preds = %68
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.arm_2d_scene_player_t, ptr %76, i32 0, i32 2
  %78 = getelementptr inbounds %struct.anon.2, ptr %77, i32 0, i32 2
  %79 = getelementptr inbounds %struct.anon.5, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !32
  %81 = icmp eq ptr null, %80
  br i1 %81, label %82, label %83

82:                                               ; preds = %75
  br label %103

83:                                               ; preds = %75
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.arm_2d_scene_player_t, ptr %84, i32 0, i32 2
  %86 = getelementptr inbounds %struct.anon.2, ptr %85, i32 0, i32 2
  %87 = getelementptr inbounds %struct.anon.5, ptr %86, i32 0, i32 0
  %88 = load ptr, ptr %87, align 8, !tbaa !32
  %89 = getelementptr inbounds %struct.anon, ptr %88, i32 0, i32 2
  %90 = load ptr, ptr %89, align 8, !tbaa !33
  %91 = icmp ne ptr null, %90
  br i1 %91, label %92, label %101

92:                                               ; preds = %83
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.arm_2d_scene_player_t, ptr %93, i32 0, i32 2
  %95 = getelementptr inbounds %struct.anon.2, ptr %94, i32 0, i32 2
  %96 = getelementptr inbounds %struct.anon.5, ptr %95, i32 0, i32 0
  %97 = load ptr, ptr %96, align 8, !tbaa !32
  %98 = getelementptr inbounds %struct.anon, ptr %97, i32 0, i32 2
  %99 = load ptr, ptr %98, align 8, !tbaa !33
  %100 = load ptr, ptr %5, align 8, !tbaa !5
  call void %99(ptr noundef %100)
  br label %101

101:                                              ; preds = %92, %83
  br label %102

102:                                              ; preds = %101
  br label %103

103:                                              ; preds = %102, %82
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %104

104:                                              ; preds = %103, %24, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %105 = load i32, ptr %4, align 4
  ret i32 %105
}

declare i64 @arm_2d_helper_get_system_timestamp() #3

attributes #0 = { noreturn 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 = { noreturn nounwind }
attributes #5 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !12, i64 576}
!16 = !{!"arm_2d_scene_player_t", !17, i64 0, !19, i64 360, !22, i64 408}
!17 = !{!"arm_2d_helper_pfb_t", !7, i64 0, !18, i64 344}
!18 = !{!"", !12, i64 0, !14, i64 8, !14, i64 12}
!19 = !{!"", !14, i64 0, !14, i64 4, !12, i64 8, !12, i64 16, !14, i64 24, !20, i64 28, !21, i64 32, !21, i64 34, !14, i64 36, !12, i64 40}
!20 = !{!"float", !7, i64 0}
!21 = !{!"short", !7, i64 0}
!22 = !{!"", !23, i64 0, !24, i64 16, !25, i64 24, !27, i64 176}
!23 = !{!"", !6, i64 0, !6, i64 8}
!24 = !{!"", !7, i64 0, !7, i64 0, !7, i64 0, !7, i64 0, !7, i64 1, !7, i64 1, !7, i64 1, !7, i64 1, !7, i64 2, !7, i64 2, !7, i64 2, !7, i64 2, !7, i64 2, !7, i64 2, !7, i64 3}
!25 = !{!"", !6, i64 0, !7, i64 8, !21, i64 10, !7, i64 16, !7, i64 128, !26, i64 130, !21, i64 134, !21, i64 136, !12, i64 144}
!26 = !{!"arm_2d_location_t", !21, i64 0, !21, i64 2}
!27 = !{!"", !28, i64 0, !28, i64 16}
!28 = !{!"arm_2d_scene_evt_t", !6, i64 0, !6, i64 8}
!29 = !{i8 0, i8 2}
!30 = !{}
!31 = !{!16, !21, i64 568}
!32 = !{!16, !6, i64 432}
!33 = !{!34, !6, i64 16}
!34 = !{!"", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}


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

; Function Attrs: nounwind uwtable
declare dso_local i32 @arm_2d_scene_player_get_switching_status(ptr noundef nonnull) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -13, 1) i32 @arm_2d_scene_player_finish_manual_switching(ptr noundef nonnull %0, i1 noundef zeroext %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = tail call i32 @arm_2d_scene_player_get_switching_status(ptr noundef %0)
  switch i32 %4, label %5 [
    i32 0, label %24
    i32 1, label %6
  ]

5:                                                ; preds = %3
  br label %24

6:                                                ; preds = %3
  %7 = tail call i64 @arm_2d_helper_get_system_timestamp() #3
  %8 = getelementptr inbounds i8, ptr %0, i64 432
  %9 = getelementptr inbounds i8, ptr %0, i64 576
  store i64 %7, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 424
  %11 = load i16, ptr %10, align 8
  %12 = and i16 %11, -13
  %13 = select i1 %1, i16 12, i16 8
  %14 = or disjoint i16 %13, %12
  store i16 %14, ptr %10, align 8
  %15 = getelementptr inbounds i8, ptr %0, i64 568
  %16 = tail call i64 @llvm.smax.i64(i64 %2, i64 200)
  %17 = trunc i64 %16 to i16
  store i16 %17, ptr %15, align 8, !tbaa !24
  %18 = load ptr, ptr %8, align 8, !tbaa !25
  %19 = icmp eq ptr %18, null
  br i1 %19, label %24, label %20

20:                                               ; preds = %6
  %21 = getelementptr inbounds i8, ptr %18, i64 16
  %22 = load ptr, ptr %21, align 8, !tbaa !26
  %.not21 = icmp eq ptr %22, null
  br i1 %.not21, label %24, label %23

23:                                               ; preds = %20
  tail call void %22(ptr noundef nonnull %0) #3
  br label %24

24:                                               ; preds = %6, %20, %23, %3, %5
  %.0 = phi i32 [ 0, %5 ], [ -13, %3 ], [ 0, %23 ], [ 0, %20 ], [ 0, %6 ]
  ret i32 %.0
}

declare i64 @arm_2d_helper_get_system_timestamp() local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #2

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" }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !11, i64 576}
!6 = !{!"arm_2d_scene_player_t", !7, i64 0, !13, i64 360, !16, i64 408}
!7 = !{!"arm_2d_helper_pfb_t", !8, i64 0, !10, i64 344}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !12, i64 8, !12, i64 12}
!11 = !{!"long", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 4, !11, i64 8, !11, i64 16, !12, i64 24, !14, i64 28, !15, i64 32, !15, i64 34, !12, i64 36, !11, i64 40}
!14 = !{!"float", !8, i64 0}
!15 = !{!"short", !8, i64 0}
!16 = !{!"", !17, i64 0, !19, i64 16, !20, i64 24, !22, i64 176}
!17 = !{!"", !18, i64 0, !18, i64 8}
!18 = !{!"any pointer", !8, i64 0}
!19 = !{!"", !8, i64 0, !8, i64 0, !8, i64 0, !8, i64 0, !8, i64 1, !8, i64 1, !8, i64 1, !8, i64 1, !8, i64 2, !8, i64 2, !8, i64 2, !8, i64 2, !8, i64 2, !8, i64 2, !8, i64 3}
!20 = !{!"", !18, i64 0, !8, i64 8, !15, i64 10, !8, i64 16, !8, i64 128, !21, i64 130, !15, i64 134, !15, i64 136, !11, i64 144}
!21 = !{!"arm_2d_location_t", !15, i64 0, !15, i64 2}
!22 = !{!"", !23, i64 0, !23, i64 16}
!23 = !{!"arm_2d_scene_evt_t", !18, i64 0, !18, i64 8}
!24 = !{!6, !15, i64 568}
!25 = !{!6, !18, i64 432}
!26 = !{!27, !18, i64 16}
!27 = !{!"", !8, i64 0, !18, i64 8, !18, i64 16, !18, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass