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

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

@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; 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 i32 @image_u8x4_write_pnm(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.image_u8x4, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i8, align 1
  %12 = alloca i8, align 1
  %13 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #5
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %14, i64 24, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = call noalias ptr @fopen(ptr noundef %15, ptr noundef @.str.2)
  store ptr %16, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !10
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %2
  store i32 -1, ptr %7, align 4, !tbaa !10
  br label %95

20:                                               ; preds = %2
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.image_u8x4, ptr %5, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !12
  %24 = getelementptr inbounds %struct.image_u8x4, ptr %5, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !14
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef @.str.3, i32 noundef %23, i32 noundef %25) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %27 = getelementptr inbounds %struct.image_u8x4, ptr %5, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !14
  %29 = sub nsw i32 %28, 1
  store i32 %29, ptr %8, align 4, !tbaa !10
  br label %30

30:                                               ; preds = %91, %20
  %31 = load i32, ptr %8, align 4, !tbaa !10
  %32 = icmp sge i32 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  store i32 3, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %94

34:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !10
  br label %35

35:                                               ; preds = %87, %34
  %36 = load i32, ptr %10, align 4, !tbaa !10
  %37 = getelementptr inbounds %struct.image_u8x4, ptr %5, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !12
  %39 = icmp slt i32 %36, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %35
  store i32 6, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %90

41:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #5
  %42 = getelementptr inbounds %struct.image_u8x4, ptr %5, i32 0, i32 3
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = load i32, ptr %8, align 4, !tbaa !10
  %45 = getelementptr inbounds %struct.image_u8x4, ptr %5, i32 0, i32 2
  %46 = load i32, ptr %45, align 8, !tbaa !16
  %47 = mul nsw i32 %44, %46
  %48 = load i32, ptr %10, align 4, !tbaa !10
  %49 = mul nsw i32 4, %48
  %50 = add nsw i32 %47, %49
  %51 = add nsw i32 %50, 0
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i8, ptr %43, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !17
  store i8 %54, ptr %11, align 1, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #5
  %55 = getelementptr inbounds %struct.image_u8x4, ptr %5, i32 0, i32 3
  %56 = load ptr, ptr %55, align 8, !tbaa !15
  %57 = load i32, ptr %8, align 4, !tbaa !10
  %58 = getelementptr inbounds %struct.image_u8x4, ptr %5, i32 0, i32 2
  %59 = load i32, ptr %58, align 8, !tbaa !16
  %60 = mul nsw i32 %57, %59
  %61 = load i32, ptr %10, align 4, !tbaa !10
  %62 = mul nsw i32 4, %61
  %63 = add nsw i32 %60, %62
  %64 = add nsw i32 %63, 1
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i8, ptr %56, i64 %65
  %67 = load i8, ptr %66, align 1, !tbaa !17
  store i8 %67, ptr %12, align 1, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #5
  %68 = getelementptr inbounds %struct.image_u8x4, ptr %5, i32 0, i32 3
  %69 = load ptr, ptr %68, align 8, !tbaa !15
  %70 = load i32, ptr %8, align 4, !tbaa !10
  %71 = getelementptr inbounds %struct.image_u8x4, ptr %5, i32 0, i32 2
  %72 = load i32, ptr %71, align 8, !tbaa !16
  %73 = mul nsw i32 %70, %72
  %74 = load i32, ptr %10, align 4, !tbaa !10
  %75 = mul nsw i32 4, %74
  %76 = add nsw i32 %73, %75
  %77 = add nsw i32 %76, 2
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds i8, ptr %69, i64 %78
  %80 = load i8, ptr %79, align 1, !tbaa !17
  store i8 %80, ptr %13, align 1, !tbaa !17
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = call i64 @fwrite(ptr noundef %11, i64 noundef 1, i64 noundef 1, ptr noundef %81)
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = call i64 @fwrite(ptr noundef %12, i64 noundef 1, i64 noundef 1, ptr noundef %83)
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = call i64 @fwrite(ptr noundef %13, i64 noundef 1, i64 noundef 1, ptr noundef %85)
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #5
  br label %87

87:                                               ; preds = %41
  %88 = load i32, ptr %10, align 4, !tbaa !10
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %10, align 4, !tbaa !10
  br label %35, !llvm.loop !18

90:                                               ; preds = %40
  br label %91

91:                                               ; preds = %90
  %92 = load i32, ptr %8, align 4, !tbaa !10
  %93 = add nsw i32 %92, -1
  store i32 %93, ptr %8, align 4, !tbaa !10
  br label %30, !llvm.loop !20

94:                                               ; preds = %33
  br label %95

95:                                               ; preds = %94, %19
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = icmp ne ptr %96, null
  br i1 %97, label %98, label %101

98:                                               ; preds = %95
  %99 = load ptr, ptr %6, align 8, !tbaa !5
  %100 = call i32 @fclose(ptr noundef %99)
  br label %101

101:                                              ; preds = %98, %95
  %102 = load i32, ptr %7, align 4, !tbaa !10
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #5
  ret i32 %102
}

declare noalias ptr @fopen(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #4

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #3

declare i32 @fclose(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree 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 = { 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 #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 = !{i64 0, i64 4, !10, i64 4, i64 4, !10, i64 8, i64 4, !10, i64 16, i64 8, !5}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"image_u8x4", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16}
!14 = !{!13, !11, i64 4}
!15 = !{!13, !6, i64 16}
!16 = !{!13, !11, i64 8}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; 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.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local range(i32 -1, 1) i32 @image_u8x4_write_pnm(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %.sroa.0.0.copyload = load i32, ptr %0, align 8, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 4
  %.sroa.5.0.copyload = load i32, ptr %.sroa.5.0..sroa_idx, align 4, !tbaa !5
  %.sroa.7.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 8
  %.sroa.7.0.copyload = load i32, ptr %.sroa.7.0..sroa_idx, align 8, !tbaa !5
  %.sroa.1021.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 16
  %.sroa.1021.0.copyload = load ptr, ptr %.sroa.1021.0..sroa_idx, align 8, !tbaa !9
  %3 = tail call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull @.str.2)
  %4 = icmp eq ptr %3, null
  br i1 %4, label %.thread, label %5

5:                                                ; preds = %2
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %3, ptr noundef nonnull @.str.3, i32 noundef %.sroa.0.0.copyload, i32 noundef %.sroa.5.0.copyload) #3
  %7 = icmp sgt i32 %.sroa.5.0.copyload, 0
  %8 = icmp sgt i32 %.sroa.0.0.copyload, 0
  %or.cond = select i1 %7, i1 %8, i1 false
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge

.preheader.us.preheader:                          ; preds = %5
  %9 = zext nneg i32 %.sroa.5.0.copyload to i64
  %10 = sext i32 %.sroa.7.0.copyload to i64
  %wide.trip.count = zext nneg i32 %.sroa.0.0.copyload to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %..loopexit_crit_edge.us
  %indvars.iv44.in = phi i64 [ %9, %.preheader.us.preheader ], [ %indvars.iv44, %..loopexit_crit_edge.us ]
  %indvars.iv44 = add nsw i64 %indvars.iv44.in, -1
  %11 = mul nsw i64 %indvars.iv44, %10
  %invariant.gep = getelementptr i8, ptr %.sroa.1021.0.copyload, i64 %11
  br label %12

12:                                               ; preds = %.preheader.us, %12
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %12 ]
  %13 = shl nsw i64 %indvars.iv, 2
  %gep = getelementptr i8, ptr %invariant.gep, i64 %13
  %14 = load i8, ptr %gep, align 1, !tbaa !11
  %15 = getelementptr i8, ptr %gep, i64 1
  %16 = load i8, ptr %15, align 1, !tbaa !11
  %17 = getelementptr i8, ptr %gep, i64 2
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %chari.us = sext i8 %14 to i32
  %fputc.us = tail call i32 @fputc(i32 %chari.us, ptr nonnull %3)
  %chari30.us = sext i8 %16 to i32
  %fputc31.us = tail call i32 @fputc(i32 %chari30.us, ptr nonnull %3)
  %chari33.us = sext i8 %18 to i32
  %fputc34.us = tail call i32 @fputc(i32 %chari33.us, ptr nonnull %3)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %..loopexit_crit_edge.us, label %12, !llvm.loop !12

..loopexit_crit_edge.us:                          ; preds = %12
  %19 = icmp sgt i64 %indvars.iv44.in, 1
  br i1 %19, label %.preheader.us, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %..loopexit_crit_edge.us, %5
  %20 = tail call i32 @fclose(ptr noundef nonnull %3)
  br label %.thread

.thread:                                          ; preds = %2, %._crit_edge
  %.02738 = phi i32 [ 0, %._crit_edge ], [ -1, %2 ]
  ret i32 %.02738
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

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

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fputc(i32 noundef, ptr nocapture noundef) local_unnamed_addr #2

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" }
attributes #2 = { nofree nounwind }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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