; LLVM IR from ARM-software/Arm-2D :: Helper/Source/arm_2d_helper_map.ll_ (arm_2d_helper_map_init)

; 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_helper_map_cfg_t = type { %struct.anon, ptr, i32, %struct.anon.0 }
%struct.anon = type { %struct.arm_2d_helper_map_grid_t, %struct.arm_2d_size_t }
%struct.arm_2d_helper_map_grid_t = type { i16, i16 }
%struct.arm_2d_size_t = type { i16, i16 }
%struct.anon.0 = type { %struct.arm_2d_cell_load_evt_t, %struct.arm_2d_cell_draw_evt_t, %struct.arm_2d_cell_unload_evt_t }
%struct.arm_2d_cell_load_evt_t = type { ptr, ptr }
%struct.arm_2d_cell_draw_evt_t = type { ptr, ptr }
%struct.arm_2d_cell_unload_evt_t = type { ptr, ptr }
%struct.arm_2d_helper_map_t = type { %struct.anon.1 }
%struct.anon.1 = type { %struct.arm_2d_helper_map_cfg_t, %struct.arm_2d_tile_t, %struct.arm_2d_helper_map_coordinate_t, %struct.anon.16 }
%struct.arm_2d_tile_t = type { %union.anon, %union.anon.12, %union.anon.15 }
%union.anon = type { %struct.anon.2 }
%struct.anon.2 = type { i8, %union.arm_2d_color_info_t, %union.anon.5 }
%union.arm_2d_color_info_t = type { %struct.anon.3 }
%struct.anon.3 = type { i8 }
%union.anon.5 = type { i16 }
%union.anon.12 = type { %struct.arm_2d_region_t }
%struct.arm_2d_region_t = type { %union.anon.13, %union.anon.14 }
%union.anon.13 = type { %struct.arm_2d_location_t }
%struct.arm_2d_location_t = type { i16, i16 }
%union.anon.14 = type { %struct.arm_2d_size_t }
%union.anon.15 = type { ptr }
%struct.arm_2d_helper_map_coordinate_t = type { i64, i64 }
%struct.anon.16 = type { %struct.arm_2d_helper_map_grid_t, %struct.arm_2d_helper_map_grid_t }

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@__PRETTY_FUNCTION__.__arm_2d_helper_map_init = external hidden unnamed_addr constant [96 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [53 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @__arm_2d_helper_map_init(ptr noundef nonnull %0, ptr noundef nonnull %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp ne ptr null, %8
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  br label %12

11:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 81, ptr noundef @__PRETTY_FUNCTION__.__arm_2d_helper_map_init) #5
  unreachable

12:                                               ; preds = %10
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp ne ptr null, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  br label %17

16:                                               ; preds = %12
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 82, ptr noundef @__PRETTY_FUNCTION__.__arm_2d_helper_map_init) #5
  unreachable

17:                                               ; preds = %15
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.arm_2d_helper_map_cfg_t, ptr %18, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = icmp ne ptr null, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %17
  br label %24

23:                                               ; preds = %17
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 83, ptr noundef @__PRETTY_FUNCTION__.__arm_2d_helper_map_init) #5
  unreachable

24:                                               ; preds = %22
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.arm_2d_helper_map_cfg_t, ptr %25, i32 0, i32 3
  %27 = getelementptr inbounds %struct.anon.0, ptr %26, i32 0, i32 1
  %28 = getelementptr inbounds %struct.arm_2d_cell_draw_evt_t, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !20
  %30 = icmp ne ptr null, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %24
  br label %33

32:                                               ; preds = %24
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 84, ptr noundef @__PRETTY_FUNCTION__.__arm_2d_helper_map_init) #5
  unreachable

33:                                               ; preds = %31
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %34, i8 0, i64 120, i1 false)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.arm_2d_helper_map_t, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds %struct.anon.1, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %37, ptr align 8 %38, i64 72, i1 false), !tbaa.struct !21
  br label %39

39:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.arm_2d_helper_map_t, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds %struct.anon.1, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds %struct.arm_2d_helper_map_cfg_t, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds %struct.anon, ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds %struct.arm_2d_helper_map_grid_t, ptr %44, i32 0, i32 0
  %46 = load i16, ptr %45, align 8, !tbaa !24
  %47 = zext i16 %46 to i32
  %48 = add nsw i32 %47, 1
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.arm_2d_helper_map_t, ptr %49, i32 0, i32 0
  %51 = getelementptr inbounds %struct.anon.1, ptr %50, i32 0, i32 0
  %52 = getelementptr inbounds %struct.arm_2d_helper_map_cfg_t, ptr %51, i32 0, i32 0
  %53 = getelementptr inbounds %struct.anon, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds %struct.arm_2d_helper_map_grid_t, ptr %53, i32 0, i32 1
  %55 = load i16, ptr %54, align 2, !tbaa !31
  %56 = zext i16 %55 to i32
  %57 = add nsw i32 %56, 1
  %58 = mul nsw i32 %48, %57
  store i32 %58, ptr %6, align 4, !tbaa !23
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.arm_2d_helper_map_t, ptr %59, i32 0, i32 0
  %61 = getelementptr inbounds %struct.anon.1, ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds %struct.arm_2d_helper_map_cfg_t, ptr %61, i32 0, i32 2
  %63 = load i32, ptr %62, align 8, !tbaa !32
  %64 = load i32, ptr %6, align 4, !tbaa !23
  %65 = icmp ult i32 %63, %64
  br i1 %65, label %66, label %67

66:                                               ; preds = %39
  store i32 2, ptr %7, align 4
  br label %79

67:                                               ; preds = %39
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.arm_2d_helper_map_cfg_t, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !9
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.arm_2d_helper_map_t, ptr %71, i32 0, i32 0
  %73 = getelementptr inbounds %struct.anon.1, ptr %72, i32 0, i32 0
  %74 = getelementptr inbounds %struct.arm_2d_helper_map_cfg_t, ptr %73, i32 0, i32 2
  %75 = load i32, ptr %74, align 8, !tbaa !32
  %76 = zext i32 %75 to i64
  %77 = mul i64 8, %76
  call void @llvm.memset.p0.i64(ptr align 8 %70, i8 0, i64 %77, i1 false)
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %78, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %79

79:                                               ; preds = %67, %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  %80 = load i32, ptr %7, align 4
  switch i32 %80, label %84 [
    i32 2, label %81
    i32 1, label %82
  ]

81:                                               ; preds = %79
  store ptr null, ptr %3, align 8
  br label %82

82:                                               ; preds = %81, %79
  %83 = load ptr, ptr %3, align 8
  ret ptr %83

84:                                               ; preds = %79
  unreachable
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

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

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 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { noreturn nounwind }
attributes #6 = { 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, !6, i64 8}
!10 = !{!"arm_2d_helper_map_cfg_t", !11, i64 0, !6, i64 8, !15, i64 16, !16, i64 24}
!11 = !{!"", !12, i64 0, !14, i64 4}
!12 = !{!"arm_2d_helper_map_grid_t", !13, i64 0, !13, i64 2}
!13 = !{!"short", !7, i64 0}
!14 = !{!"arm_2d_size_t", !13, i64 0, !13, i64 2}
!15 = !{!"int", !7, i64 0}
!16 = !{!"", !17, i64 0, !18, i64 16, !19, i64 32}
!17 = !{!"arm_2d_cell_load_evt_t", !6, i64 0, !6, i64 8}
!18 = !{!"arm_2d_cell_draw_evt_t", !6, i64 0, !6, i64 8}
!19 = !{!"arm_2d_cell_unload_evt_t", !6, i64 0, !6, i64 8}
!20 = !{!10, !6, i64 40}
!21 = !{i64 0, i64 2, !22, i64 2, i64 2, !22, i64 4, i64 2, !22, i64 6, i64 2, !22, i64 8, i64 8, !5, i64 16, i64 4, !23, i64 24, i64 8, !5, i64 32, i64 8, !5, i64 40, i64 8, !5, i64 48, i64 8, !5, i64 56, i64 8, !5, i64 64, i64 8, !5}
!22 = !{!13, !13, i64 0}
!23 = !{!15, !15, i64 0}
!24 = !{!25, !13, i64 0}
!25 = !{!"arm_2d_helper_map_t", !26, i64 0}
!26 = !{!"", !10, i64 0, !27, i64 72, !28, i64 96, !30, i64 112}
!27 = !{!"arm_2d_tile_t", !7, i64 0, !7, i64 4, !7, i64 16}
!28 = !{!"arm_2d_helper_map_coordinate_t", !29, i64 0, !29, i64 8}
!29 = !{!"long", !7, i64 0}
!30 = !{!"", !12, i64 0, !12, i64 4}
!31 = !{!25, !13, i64 2}
!32 = !{!25, !15, i64 16}


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

@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@__PRETTY_FUNCTION__.__arm_2d_helper_map_init = external hidden unnamed_addr constant [96 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [53 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @__arm_2d_helper_map_init(ptr noundef nonnull %0, ptr nocapture noundef nonnull readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %5, label %6

5:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 83, ptr noundef nonnull @__PRETTY_FUNCTION__.__arm_2d_helper_map_init) #4
  unreachable

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %1, i64 40
  %8 = load ptr, ptr %7, align 8, !tbaa !19
  %.not17 = icmp eq ptr %8, null
  br i1 %.not17, label %9, label %10

9:                                                ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 84, ptr noundef nonnull @__PRETTY_FUNCTION__.__arm_2d_helper_map_init) #4
  unreachable

10:                                               ; preds = %6
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(120) %0, i8 0, i64 120, i1 false)
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef nonnull align 8 dereferenceable(72) %1, i64 72, i1 false), !tbaa.struct !20
  %11 = load i16, ptr %0, align 8, !tbaa !24
  %12 = zext i16 %11 to i32
  %13 = add nuw nsw i32 %12, 1
  %14 = getelementptr inbounds i8, ptr %0, i64 2
  %15 = load i16, ptr %14, align 2, !tbaa !31
  %16 = zext i16 %15 to i32
  %17 = add nuw nsw i32 %16, 1
  %18 = mul nuw nsw i32 %17, %13
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  %20 = load i32, ptr %19, align 8, !tbaa !32
  %21 = icmp ult i32 %20, %18
  br i1 %21, label %26, label %22

22:                                               ; preds = %10
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = zext i32 %20 to i64
  %25 = shl nuw nsw i64 %24, 3
  tail call void @llvm.memset.p0.i64(ptr align 8 %23, i8 0, i64 %25, i1 false)
  br label %26

26:                                               ; preds = %10, %22
  %spec.select = phi ptr [ %0, %22 ], [ null, %10 ]
  ret ptr %spec.select
}

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { noreturn 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, !13, i64 8}
!6 = !{!"arm_2d_helper_map_cfg_t", !7, i64 0, !13, i64 8, !14, i64 16, !15, i64 24}
!7 = !{!"", !8, i64 0, !12, i64 4}
!8 = !{!"arm_2d_helper_map_grid_t", !9, i64 0, !9, i64 2}
!9 = !{!"short", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"arm_2d_size_t", !9, i64 0, !9, i64 2}
!13 = !{!"any pointer", !10, i64 0}
!14 = !{!"int", !10, i64 0}
!15 = !{!"", !16, i64 0, !17, i64 16, !18, i64 32}
!16 = !{!"arm_2d_cell_load_evt_t", !13, i64 0, !13, i64 8}
!17 = !{!"arm_2d_cell_draw_evt_t", !13, i64 0, !13, i64 8}
!18 = !{!"arm_2d_cell_unload_evt_t", !13, i64 0, !13, i64 8}
!19 = !{!6, !13, i64 40}
!20 = !{i64 0, i64 2, !21, i64 2, i64 2, !21, i64 4, i64 2, !21, i64 6, i64 2, !21, i64 8, i64 8, !22, i64 16, i64 4, !23, i64 24, i64 8, !22, i64 32, i64 8, !22, i64 40, i64 8, !22, i64 48, i64 8, !22, i64 56, i64 8, !22, i64 64, i64 8, !22}
!21 = !{!9, !9, i64 0}
!22 = !{!13, !13, i64 0}
!23 = !{!14, !14, i64 0}
!24 = !{!25, !9, i64 0}
!25 = !{!"arm_2d_helper_map_t", !26, i64 0}
!26 = !{!"", !6, i64 0, !27, i64 72, !28, i64 96, !30, i64 112}
!27 = !{!"arm_2d_tile_t", !10, i64 0, !10, i64 4, !10, i64 16}
!28 = !{!"arm_2d_helper_map_coordinate_t", !29, i64 0, !29, i64 8}
!29 = !{!"long", !10, i64 0}
!30 = !{!"", !8, i64 0, !8, i64 4}
!31 = !{!25, !9, i64 2}
!32 = !{!25, !14, i64 16}


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