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

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

@.str.22 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [3 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
declare void @free(ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @str_expand_envs(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = call i64 @strlen(ptr noundef %10) #5
  store i64 %11, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %12

12:                                               ; preds = %64, %23, %1
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = load i64, ptr %3, align 8, !tbaa !9
  %15 = icmp ult i64 %13, %14
  br i1 %15, label %16, label %65

16:                                               ; preds = %12
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = load i64, ptr %4, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %17, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !13
  %21 = sext i8 %20 to i32
  %22 = icmp ne i32 %21, 36
  br i1 %22, label %23, label %31

23:                                               ; preds = %16
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = load i64, ptr %4, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %24, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !13
  %28 = sext i8 %27 to i32
  call void (ptr, ptr, ptr, ...) @buffer_appendf(ptr noundef %5, ptr noundef %6, ptr noundef @.str.22, i32 noundef %28)
  %29 = load i64, ptr %4, align 8, !tbaa !9
  %30 = add i64 %29, 1
  store i64 %30, ptr %4, align 8, !tbaa !9
  br label %12, !llvm.loop !14

31:                                               ; preds = %16
  %32 = load i64, ptr %4, align 8, !tbaa !9
  %33 = add i64 %32, 1
  store i64 %33, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %34

34:                                               ; preds = %47, %31
  %35 = load i64, ptr %4, align 8, !tbaa !9
  %36 = load i64, ptr %3, align 8, !tbaa !9
  %37 = icmp ult i64 %35, %36
  br i1 %37, label %38, label %45

38:                                               ; preds = %34
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = load i64, ptr %4, align 8, !tbaa !9
  %41 = getelementptr inbounds i8, ptr %39, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !13
  %43 = call i32 @is_variable_character(i8 noundef signext %42)
  %44 = icmp ne i32 %43, 0
  br label %45

45:                                               ; preds = %38, %34
  %46 = phi i1 [ false, %34 ], [ %44, %38 ]
  br i1 %46, label %47, label %55

47:                                               ; preds = %45
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = load i64, ptr %4, align 8, !tbaa !9
  %50 = getelementptr inbounds i8, ptr %48, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !13
  %52 = sext i8 %51 to i32
  call void (ptr, ptr, ptr, ...) @buffer_appendf(ptr noundef %7, ptr noundef %8, ptr noundef @.str.22, i32 noundef %52)
  %53 = load i64, ptr %4, align 8, !tbaa !9
  %54 = add i64 %53, 1
  store i64 %54, ptr %4, align 8, !tbaa !9
  br label %34, !llvm.loop !16

55:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = call ptr @getenv(ptr noundef %56) #4
  store ptr %57, ptr %9, align 8, !tbaa !5
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %62

60:                                               ; preds = %55
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  call void (ptr, ptr, ptr, ...) @buffer_appendf(ptr noundef %5, ptr noundef %6, ptr noundef @.str.23, ptr noundef %61)
  br label %62

62:                                               ; preds = %60, %55
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free(ptr noundef %63) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %64

64:                                               ; preds = %62
  br label %12, !llvm.loop !14

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

; Function Attrs: nounwind uwtable
declare hidden void @buffer_appendf(ptr noundef, ptr noundef, ptr noundef, ...) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @is_variable_character(i8 noundef signext) #3

; Function Attrs: nounwind
declare ptr @getenv(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nounwind willreturn memory(read) "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 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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

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

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local ptr @str_expand_envs(ptr nocapture noundef readonly %0) local_unnamed_addr #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #6
  store ptr null, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  store i32 0, ptr %3, align 4, !tbaa !9
  %.not28 = icmp eq i64 %6, 0
  br i1 %.not28, label %._crit_edge, label %.lr.ph27

.lr.ph27:                                         ; preds = %1, %.backedge
  %.026 = phi i64 [ %.0.be, %.backedge ], [ 0, %1 ]
  %7 = getelementptr inbounds i8, ptr %0, i64 %.026
  %8 = load i8, ptr %7, align 1, !tbaa !11
  %.not = icmp eq i8 %8, 36
  br i1 %.not, label %13, label %9

9:                                                ; preds = %.lr.ph27
  %10 = sext i8 %8 to i32
  call void (ptr, ptr, ptr, ...) @buffer_appendf(ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull @.str.22, i32 noundef %10)
  %11 = add nuw i64 %.026, 1
  br label %.backedge

.backedge:                                        ; preds = %9, %24
  %.0.be = phi i64 [ %11, %9 ], [ %.1.lcssa, %24 ]
  %12 = icmp ult i64 %.0.be, %6
  br i1 %12, label %.lr.ph27, label %._crit_edge.loopexit, !llvm.loop !12

13:                                               ; preds = %.lr.ph27
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #6
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #6
  store i32 0, ptr %5, align 4, !tbaa !9
  %.122 = add nuw i64 %.026, 1
  %14 = icmp ult i64 %.122, %6
  br i1 %14, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %13, %18
  %.123 = phi i64 [ %.1, %18 ], [ %.122, %13 ]
  %15 = getelementptr inbounds i8, ptr %0, i64 %.123
  %16 = load i8, ptr %15, align 1, !tbaa !11
  %17 = call i32 @is_variable_character(i8 noundef signext %16)
  %.not20 = icmp eq i32 %17, 0
  br i1 %.not20, label %.critedge.loopexit, label %18

18:                                               ; preds = %.lr.ph
  %19 = load i8, ptr %15, align 1, !tbaa !11
  %20 = sext i8 %19 to i32
  call void (ptr, ptr, ptr, ...) @buffer_appendf(ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull @.str.22, i32 noundef %20)
  %.1 = add nuw i64 %.123, 1
  %exitcond.not = icmp eq i64 %.1, %6
  br i1 %exitcond.not, label %.critedge.loopexit, label %.lr.ph, !llvm.loop !14

.critedge.loopexit:                               ; preds = %18, %.lr.ph
  %.1.lcssa.ph = phi i64 [ %.123, %.lr.ph ], [ %6, %18 ]
  %.pre = load ptr, ptr %4, align 8, !tbaa !5
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %13
  %21 = phi ptr [ null, %13 ], [ %.pre, %.critedge.loopexit ]
  %.1.lcssa = phi i64 [ %.122, %13 ], [ %.1.lcssa.ph, %.critedge.loopexit ]
  %22 = call ptr @getenv(ptr noundef %21) #6
  %.not21 = icmp eq ptr %22, null
  br i1 %.not21, label %24, label %23

23:                                               ; preds = %.critedge
  call void (ptr, ptr, ptr, ...) @buffer_appendf(ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull @.str.23, ptr noundef nonnull %22)
  %.pre29 = load ptr, ptr %4, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %23, %.critedge
  %25 = phi ptr [ %.pre29, %23 ], [ %21, %.critedge ]
  call void @free(ptr noundef %25) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #6
  br label %.backedge

._crit_edge.loopexit:                             ; preds = %.backedge
  %.pre30 = load ptr, ptr %2, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %26 = phi ptr [ %.pre30, %._crit_edge.loopexit ], [ null, %1 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #6
  ret ptr %26
}

; Function Attrs: nounwind uwtable
declare hidden void @buffer_appendf(ptr noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i32 @is_variable_character(i8 noundef signext) local_unnamed_addr #3

; Function Attrs: nofree nounwind memory(read)
declare noundef ptr @getenv(ptr nocapture noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nofree nounwind willreturn memory(argmem: read) "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 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 #4 = { nofree nounwind memory(read) "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 willreturn memory(read) }
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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass