; LLVM IR from openxrlab/xrsfm :: 3rdparty/apriltag/common (pjpeg)

; 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.pjpeg = type { i32, i32, i32, i32, ptr }
%struct.pjpeg_component = type { i32, i32, i32, ptr, i8, i8, i8, i8, i8, i8 }
%struct.image_u8 = type { i32, i32, i32, ptr }

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [82 x i8], align 1
@__PRETTY_FUNCTION__.pjpeg_to_u8_baseline = external hidden unnamed_addr constant [44 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [55 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @pjpeg_to_u8_baseline(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.pjpeg, ptr %6, i32 0, i32 3
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  br label %12

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

12:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.pjpeg, ptr %13, i32 0, i32 4
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = getelementptr inbounds %struct.pjpeg_component, ptr %15, i64 0
  store ptr %16, ptr %3, align 8, !tbaa !5
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.pjpeg_component, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !13
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.pjpeg, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !15
  %23 = icmp uge i32 %19, %22
  br i1 %23, label %24, label %33

24:                                               ; preds = %12
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.pjpeg_component, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !16
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.pjpeg, ptr %28, i32 0, i32 2
  %30 = load i32, ptr %29, align 8, !tbaa !17
  %31 = icmp uge i32 %27, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %24
  br label %34

33:                                               ; preds = %24, %12
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 723, ptr noundef @__PRETTY_FUNCTION__.pjpeg_to_u8_baseline) #5
  unreachable

34:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.pjpeg, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !15
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.pjpeg, ptr %38, i32 0, i32 2
  %40 = load i32, ptr %39, align 8, !tbaa !17
  %41 = call ptr @image_u8_create(i32 noundef %37, i32 noundef %40)
  store ptr %41, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !18
  br label %42

42:                                               ; preds = %74, %34
  %43 = load i32, ptr %5, align 4, !tbaa !18
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.image_u8, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !19
  %47 = icmp slt i32 %43, %46
  br i1 %47, label %49, label %48

48:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %77

49:                                               ; preds = %42
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.image_u8, ptr %50, i32 0, i32 3
  %52 = load ptr, ptr %51, align 8, !tbaa !21
  %53 = load i32, ptr %5, align 4, !tbaa !18
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.image_u8, ptr %54, i32 0, i32 2
  %56 = load i32, ptr %55, align 8, !tbaa !22
  %57 = mul nsw i32 %53, %56
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i8, ptr %52, i64 %58
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.pjpeg_component, ptr %60, i32 0, i32 3
  %62 = load ptr, ptr %61, align 8, !tbaa !23
  %63 = load i32, ptr %5, align 4, !tbaa !18
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.pjpeg_component, ptr %64, i32 0, i32 2
  %66 = load i32, ptr %65, align 8, !tbaa !24
  %67 = mul i32 %63, %66
  %68 = zext i32 %67 to i64
  %69 = getelementptr inbounds i8, ptr %62, i64 %68
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.pjpeg, ptr %70, i32 0, i32 1
  %72 = load i32, ptr %71, align 4, !tbaa !15
  %73 = zext i32 %72 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %59, ptr align 1 %69, i64 %73, i1 false)
  br label %74

74:                                               ; preds = %49
  %75 = load i32, ptr %5, align 4, !tbaa !18
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %5, align 4, !tbaa !18
  br label %42, !llvm.loop !25

77:                                               ; preds = %48
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  ret ptr %78
}

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

declare ptr @image_u8_create(i32 noundef, i32 noundef) #3

; 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) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 = { nocallback nofree 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, !11, i64 12}
!10 = !{!"pjpeg", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!14, !11, i64 0}
!14 = !{!"pjpeg_component", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !7, i64 28, !7, i64 29}
!15 = !{!10, !11, i64 4}
!16 = !{!14, !11, i64 4}
!17 = !{!10, !11, i64 8}
!18 = !{!11, !11, i64 0}
!19 = !{!20, !11, i64 4}
!20 = !{!"image_u8", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16}
!21 = !{!20, !6, i64 16}
!22 = !{!20, !11, i64 8}
!23 = !{!14, !6, i64 16}
!24 = !{!14, !11, i64 8}
!25 = distinct !{!25, !26}
!26 = !{!"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"

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [82 x i8], align 1
@__PRETTY_FUNCTION__.pjpeg_to_u8_baseline = external hidden unnamed_addr constant [44 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [55 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @pjpeg_to_u8_baseline(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 12
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %6, label %5

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

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = load i32, ptr %8, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %0, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !14
  %.not = icmp ult i32 %9, %11
  br i1 %.not, label %17, label %12

12:                                               ; preds = %6
  %13 = getelementptr inbounds i8, ptr %8, i64 4
  %14 = load i32, ptr %13, align 4, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load i32, ptr %15, align 8, !tbaa !16
  %.not20 = icmp ult i32 %14, %16
  br i1 %.not20, label %17, label %18

17:                                               ; preds = %12, %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 723, ptr noundef nonnull @__PRETTY_FUNCTION__.pjpeg_to_u8_baseline) #4
  unreachable

18:                                               ; preds = %12
  %19 = tail call ptr @image_u8_create(i32 noundef %11, i32 noundef %16) #5
  %20 = getelementptr inbounds i8, ptr %19, i64 4
  %21 = load i32, ptr %20, align 4, !tbaa !17
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %18
  %23 = getelementptr inbounds i8, ptr %19, i64 16
  %24 = getelementptr inbounds i8, ptr %19, i64 8
  %25 = getelementptr inbounds i8, ptr %8, i64 16
  %26 = getelementptr inbounds i8, ptr %8, i64 8
  br label %27

._crit_edge:                                      ; preds = %27, %18
  ret ptr %19

27:                                               ; preds = %.lr.ph, %27
  %.021 = phi i32 [ 0, %.lr.ph ], [ %40, %27 ]
  %28 = load ptr, ptr %23, align 8, !tbaa !19
  %29 = load i32, ptr %24, align 8, !tbaa !20
  %30 = mul nsw i32 %29, %.021
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i8, ptr %28, i64 %31
  %33 = load ptr, ptr %25, align 8, !tbaa !21
  %34 = load i32, ptr %26, align 8, !tbaa !22
  %35 = mul i32 %34, %.021
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %33, i64 %36
  %38 = load i32, ptr %10, align 4, !tbaa !14
  %39 = zext i32 %38 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %32, ptr align 1 %37, i64 %39, i1 false)
  %40 = add nuw nsw i32 %.021, 1
  %41 = load i32, ptr %20, align 4, !tbaa !17
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %27, label %._crit_edge, !llvm.loop !23
}

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

declare ptr @image_u8_create(i32 noundef, i32 noundef) local_unnamed_addr #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 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 12}
!6 = !{!"pjpeg", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!13, !7, i64 0}
!13 = !{!"pjpeg_component", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !8, i64 24, !8, i64 25, !8, i64 26, !8, i64 27, !8, i64 28, !8, i64 29}
!14 = !{!6, !7, i64 4}
!15 = !{!13, !7, i64 4}
!16 = !{!6, !7, i64 8}
!17 = !{!18, !7, i64 4}
!18 = !{!"image_u8", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16}
!19 = !{!18, !10, i64 16}
!20 = !{!18, !7, i64 8}
!21 = !{!13, !10, i64 16}
!22 = !{!13, !7, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


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