; LLVM IR from holzschu/ios_system :: shell_cmds/locate/locate (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"

%union.anon = type { i32 }

@.str.6 = external hidden unnamed_addr constant [37 x i8], align 1

; Function Attrs: noreturn
declare void @errx(i32 noundef, ptr noundef, ...) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @getwm(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca %union.anon, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %16, %1
  %6 = load i32, ptr %4, align 4, !tbaa !9
  %7 = sext i32 %6 to i64
  %8 = icmp ult i64 %7, 4
  br i1 %8, label %9, label %19

9:                                                ; preds = %5
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i32 1
  store ptr %11, ptr %2, align 8, !tbaa !5
  %12 = load i8, ptr %10, align 1, !tbaa !11
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [4 x i8], ptr %3, i64 0, i64 %14
  store i8 %12, ptr %15, align 1, !tbaa !11
  br label %16

16:                                               ; preds = %9
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %4, align 4, !tbaa !9
  br label %5, !llvm.loop !12

19:                                               ; preds = %5
  %20 = load i32, ptr %3, align 4, !tbaa !11
  store i32 %20, ptr %4, align 4, !tbaa !9
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = icmp sgt i32 %21, 4096
  br i1 %22, label %26, label %23

23:                                               ; preds = %19
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = icmp slt i32 %24, -4096
  br i1 %25, label %26, label %49

26:                                               ; preds = %23, %19
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = call i32 @__bswap_32(i32 noundef %27)
  store i32 %28, ptr %4, align 4, !tbaa !9
  %29 = load i32, ptr %4, align 4, !tbaa !9
  %30 = icmp sgt i32 %29, 4096
  br i1 %30, label %34, label %31

31:                                               ; preds = %26
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = icmp slt i32 %32, -4096
  br i1 %33, label %34, label %48

34:                                               ; preds = %31, %26
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = call i32 @llvm.abs.i32(i32 %35, i1 true)
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = call i32 @__bswap_32(i32 noundef %37)
  %39 = call i32 @llvm.abs.i32(i32 %38, i1 true)
  %40 = icmp slt i32 %36, %39
  br i1 %40, label %41, label %43

41:                                               ; preds = %34
  %42 = load i32, ptr %4, align 4, !tbaa !9
  br label %46

43:                                               ; preds = %34
  %44 = load i32, ptr %4, align 4, !tbaa !9
  %45 = call i32 @__bswap_32(i32 noundef %44)
  br label %46

46:                                               ; preds = %43, %41
  %47 = phi i32 [ %42, %41 ], [ %45, %43 ]
  call void (i32, ptr, ...) @errx(i32 noundef 1, ptr noundef @.str.6, i32 noundef 4096, i32 noundef %47) #6
  unreachable

48:                                               ; preds = %31
  br label %49

49:                                               ; preds = %48, %23
  %50 = load i32, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret i32 %50
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @__bswap_32(i32 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #4

attributes #0 = { noreturn "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 = { 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 = { inlinehint 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { noreturn }

!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"}


; 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.6 = external hidden unnamed_addr constant [37 x i8], align 1

; Function Attrs: noreturn
declare void @errx(i32 noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -4096, -2147483648) i32 @getwm(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %.sroa.0.0.copyload = load i32, ptr %0, align 1, !tbaa !5
  %2 = add i32 %.sroa.0.0.copyload, -4097
  %or.cond = icmp ult i32 %2, -8193
  br i1 %or.cond, label %3, label %15

3:                                                ; preds = %1
  %4 = tail call i32 @__bswap_32(i32 noundef %.sroa.0.0.copyload)
  %5 = add i32 %4, -4097
  %or.cond3 = icmp ult i32 %5, -8193
  br i1 %or.cond3, label %6, label %15

6:                                                ; preds = %3
  %7 = tail call i32 @llvm.abs.i32(i32 %4, i1 true)
  %8 = tail call i32 @__bswap_32(i32 noundef %4)
  %9 = tail call i32 @llvm.abs.i32(i32 %8, i1 true)
  %10 = icmp ult i32 %7, %9
  br i1 %10, label %13, label %11

11:                                               ; preds = %6
  %12 = tail call i32 @__bswap_32(i32 noundef %4)
  br label %13

13:                                               ; preds = %6, %11
  %14 = phi i32 [ %12, %11 ], [ %4, %6 ]
  tail call void (i32, ptr, ...) @errx(i32 noundef 1, ptr noundef nonnull @.str.6, i32 noundef 4096, i32 noundef %14) #4
  unreachable

15:                                               ; preds = %3, %1
  %.1 = phi i32 [ %4, %3 ], [ %.sroa.0.0.copyload, %1 ]
  ret i32 %.1
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @__bswap_32(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #3

attributes #0 = { noreturn "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 = { 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 = { inlinehint 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass