; LLVM IR from ejoy/ejoy2d :: lib (spritepack)

; 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.sprite_pack = type { i32, i32, i32, [2 x i32] }
%struct.pack_animation = type { i32, i32, i32, i32, i32, [1 x %struct.pack_component] }
%struct.pack_component = type { i32, i32 }

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [1 x i8], align 1

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

10:                                               ; preds = %1
  br label %133

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.sprite_pack, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %11
  br label %26

17:                                               ; preds = %11
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = ptrtoint ptr %18 to i64
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.sprite_pack, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = add i64 %19, %23
  %25 = inttoptr i64 %24 to ptr
  br label %26

26:                                               ; preds = %17, %16
  %27 = phi ptr [ null, %16 ], [ %25, %17 ]
  store ptr %27, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.sprite_pack, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !12
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %26
  br label %42

33:                                               ; preds = %26
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = ptrtoint ptr %34 to i64
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.sprite_pack, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !12
  %39 = zext i32 %38 to i64
  %40 = add i64 %35, %39
  %41 = inttoptr i64 %40 to ptr
  br label %42

42:                                               ; preds = %33, %32
  %43 = phi ptr [ null, %32 ], [ %41, %33 ]
  store ptr %43, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %3, align 4, !tbaa !13
  br label %44

44:                                               ; preds = %129, %42
  %45 = load i32, ptr %3, align 4, !tbaa !13
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.sprite_pack, ptr %46, i32 0, i32 2
  %48 = load i32, ptr %47, align 4, !tbaa !14
  %49 = icmp slt i32 %45, %48
  br i1 %49, label %50, label %132

50:                                               ; preds = %44
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load i32, ptr %3, align 4, !tbaa !13
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i8, ptr %51, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !15
  %56 = zext i8 %55 to i32
  %57 = icmp eq i32 %56, 1
  br i1 %57, label %58, label %61

58:                                               ; preds = %50
  %59 = load i32, ptr %3, align 4, !tbaa !13
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %59)
  br label %128

61:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load i32, ptr %3, align 4, !tbaa !13
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds i32, ptr %62, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !13
  %67 = icmp eq i32 %66, 0
  br i1 %67, label %68, label %69

68:                                               ; preds = %61
  br label %80

69:                                               ; preds = %61
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = ptrtoint ptr %70 to i64
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = load i32, ptr %3, align 4, !tbaa !13
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds i32, ptr %72, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !13
  %77 = zext i32 %76 to i64
  %78 = add i64 %71, %77
  %79 = inttoptr i64 %78 to ptr
  br label %80

80:                                               ; preds = %69, %68
  %81 = phi ptr [ null, %68 ], [ %79, %69 ]
  store ptr %81, ptr %6, align 8, !tbaa !5
  %82 = load i32, ptr %3, align 4, !tbaa !13
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.pack_animation, ptr %83, i32 0, i32 4
  %85 = load i32, ptr %84, align 4, !tbaa !16
  %86 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %82, i32 noundef %85)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !13
  br label %87

87:                                               ; preds = %124, %80
  %88 = load i32, ptr %7, align 4, !tbaa !13
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.pack_animation, ptr %89, i32 0, i32 4
  %91 = load i32, ptr %90, align 4, !tbaa !16
  %92 = icmp slt i32 %88, %91
  br i1 %92, label %93, label %127

93:                                               ; preds = %87
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.pack_animation, ptr %94, i32 0, i32 5
  %96 = load i32, ptr %7, align 4, !tbaa !13
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [1 x %struct.pack_component], ptr %95, i64 0, i64 %97
  %99 = getelementptr inbounds %struct.pack_component, ptr %98, i32 0, i32 1
  %100 = load i32, ptr %99, align 4, !tbaa !18
  %101 = load ptr, ptr %6, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.pack_animation, ptr %101, i32 0, i32 5
  %103 = load i32, ptr %7, align 4, !tbaa !13
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [1 x %struct.pack_component], ptr %102, i64 0, i64 %104
  %106 = getelementptr inbounds %struct.pack_component, ptr %105, i32 0, i32 0
  %107 = load i32, ptr %106, align 4, !tbaa !20
  %108 = icmp ne i32 %107, 0
  br i1 %108, label %109, label %120

109:                                              ; preds = %93
  %110 = load ptr, ptr %2, align 8, !tbaa !5
  %111 = load ptr, ptr %6, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.pack_animation, ptr %111, i32 0, i32 5
  %113 = load i32, ptr %7, align 4, !tbaa !13
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds [1 x %struct.pack_component], ptr %112, i64 0, i64 %114
  %116 = getelementptr inbounds %struct.pack_component, ptr %115, i32 0, i32 0
  %117 = load i32, ptr %116, align 4, !tbaa !20
  %118 = zext i32 %117 to i64
  %119 = getelementptr inbounds i8, ptr %110, i64 %118
  br label %121

120:                                              ; preds = %93
  br label %121

121:                                              ; preds = %120, %109
  %122 = phi ptr [ %119, %109 ], [ @.str.3, %120 ]
  %123 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %100, ptr noundef %122)
  br label %124

124:                                              ; preds = %121
  %125 = load i32, ptr %7, align 4, !tbaa !13
  %126 = add nsw i32 %125, 1
  store i32 %126, ptr %7, align 4, !tbaa !13
  br label %87, !llvm.loop !21

127:                                              ; preds = %87
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %128

128:                                              ; preds = %127, %58
  br label %129

129:                                              ; preds = %128
  %130 = load i32, ptr %3, align 4, !tbaa !13
  %131 = add nsw i32 %130, 1
  store i32 %131, ptr %3, align 4, !tbaa !13
  br label %44, !llvm.loop !23

132:                                              ; preds = %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %133

133:                                              ; preds = %132, %10
  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 @printf(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 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"sprite_pack", !11, i64 0, !11, i64 4, !11, i64 8, !7, i64 12}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 8}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !11, i64 16}
!17 = !{!"pack_animation", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !7, i64 20}
!18 = !{!19, !11, i64 4}
!19 = !{!"pack_component", !11, i64 0, !11, i64 4}
!20 = !{!19, !11, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


; 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.pack_component = type { i32, i32 }

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [1 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @dump_pack(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %.loopexit35, label %3

3:                                                ; preds = %1
  %4 = load i32, ptr %0, align 4, !tbaa !5
  %5 = icmp eq i32 %4, 0
  %6 = ptrtoint ptr %0 to i64
  %7 = zext i32 %4 to i64
  %8 = add i64 %7, %6
  %9 = inttoptr i64 %8 to ptr
  %10 = select i1 %5, ptr null, ptr %9
  %11 = getelementptr inbounds i8, ptr %0, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !10
  %13 = icmp eq i32 %12, 0
  %14 = zext i32 %12 to i64
  %15 = add i64 %14, %6
  %16 = inttoptr i64 %15 to ptr
  %17 = select i1 %13, ptr null, ptr %16
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %.lr.ph38, label %.loopexit35

.lr.ph38:                                         ; preds = %3, %.loopexit
  %indvars.iv40 = phi i64 [ %indvars.iv.next41, %.loopexit ], [ 0, %3 ]
  %21 = getelementptr inbounds i8, ptr %10, i64 %indvars.iv40
  %22 = load i8, ptr %21, align 1, !tbaa !12
  %23 = icmp eq i8 %22, 1
  br i1 %23, label %24, label %27

24:                                               ; preds = %.lr.ph38
  %25 = trunc nuw nsw i64 %indvars.iv40 to i32
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %25)
  br label %.loopexit

27:                                               ; preds = %.lr.ph38
  %28 = getelementptr inbounds i32, ptr %17, i64 %indvars.iv40
  %29 = load i32, ptr %28, align 4, !tbaa !13
  %30 = icmp eq i32 %29, 0
  %31 = zext i32 %29 to i64
  %32 = add i64 %31, %6
  %33 = inttoptr i64 %32 to ptr
  %34 = select i1 %30, ptr null, ptr %33
  %35 = getelementptr inbounds i8, ptr %34, i64 16
  %36 = load i32, ptr %35, align 4, !tbaa !14
  %37 = trunc nuw nsw i64 %indvars.iv40 to i32
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %37, i32 noundef %36)
  %39 = load i32, ptr %35, align 4, !tbaa !14
  %40 = icmp sgt i32 %39, 0
  br i1 %40, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %27
  %41 = getelementptr inbounds i8, ptr %34, i64 20
  br label %42

42:                                               ; preds = %.lr.ph, %42
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %42 ]
  %43 = getelementptr inbounds [1 x %struct.pack_component], ptr %41, i64 0, i64 %indvars.iv
  %44 = getelementptr inbounds i8, ptr %43, i64 4
  %45 = load i32, ptr %44, align 4, !tbaa !16
  %46 = load i32, ptr %43, align 4, !tbaa !18
  %.not = icmp eq i32 %46, 0
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %0, i64 %47
  %49 = select i1 %.not, ptr @.str.3, ptr %48
  %50 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %45, ptr noundef nonnull %49)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %51 = load i32, ptr %35, align 4, !tbaa !14
  %52 = sext i32 %51 to i64
  %53 = icmp slt i64 %indvars.iv.next, %52
  br i1 %53, label %42, label %.loopexit, !llvm.loop !19

.loopexit:                                        ; preds = %42, %27, %24
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %54 = load i32, ptr %18, align 4, !tbaa !11
  %55 = sext i32 %54 to i64
  %56 = icmp slt i64 %indvars.iv.next41, %55
  br i1 %56, label %.lr.ph38, label %.loopexit35, !llvm.loop !21

.loopexit35:                                      ; preds = %.loopexit, %3, %1
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { nofree 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 = { 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" }

!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, !7, i64 0}
!6 = !{!"sprite_pack", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!6, !7, i64 8}
!12 = !{!8, !8, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !7, i64 16}
!15 = !{!"pack_animation", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !8, i64 20}
!16 = !{!17, !7, i64 4}
!17 = !{!"pack_component", !7, i64 0, !7, i64 4}
!18 = !{!17, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass