; LLVM IR from holzschu/ios_system :: text_cmds/look (look)

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

; Function Attrs: nounwind uwtable
define dso_local ptr @linear_search(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %34, %3
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = load ptr, ptr %7, align 8, !tbaa !5
  %11 = icmp ult ptr %9, %10
  br i1 %11, label %12, label %35

12:                                               ; preds = %8
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = call i32 @compare(ptr noundef %13, ptr noundef %14, ptr noundef %15)
  switch i32 %16, label %20 [
    i32 0, label %17
    i32 -1, label %19
    i32 1, label %20
  ]

17:                                               ; preds = %12
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %18, ptr %4, align 8
  br label %36

19:                                               ; preds = %12
  store ptr null, ptr %4, align 8
  br label %36

20:                                               ; preds = %12, %12
  br label %21

21:                                               ; preds = %33, %20
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = icmp ult ptr %22, %23
  br i1 %24, label %25, label %31

25:                                               ; preds = %21
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i32 1
  store ptr %27, ptr %6, align 8, !tbaa !5
  %28 = load i8, ptr %26, align 1, !tbaa !9
  %29 = sext i8 %28 to i32
  %30 = icmp ne i32 %29, 10
  br label %31

31:                                               ; preds = %25, %21
  %32 = phi i1 [ false, %21 ], [ %30, %25 ]
  br i1 %32, label %33, label %34

33:                                               ; preds = %31
  br label %21, !llvm.loop !10

34:                                               ; preds = %31
  br label %8, !llvm.loop !12

35:                                               ; preds = %8
  store ptr null, ptr %4, align 8
  br label %36

36:                                               ; preds = %35, %19, %17
  %37 = load ptr, ptr %4, align 8
  ret ptr %37
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @compare(ptr noundef, ptr noundef, ptr noundef) #0

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

!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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @linear_search(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = icmp ult ptr %1, %2
  br i1 %4, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %3, %.critedge
  %.01012 = phi ptr [ %.2, %.critedge ], [ %1, %3 ]
  %5 = tail call i32 @compare(ptr noundef %0, ptr noundef %.01012, ptr noundef nonnull %2)
  switch i32 %5, label %.preheader [
    i32 0, label %.loopexit.loopexit
    i32 -1, label %.loopexit
  ]

.preheader:                                       ; preds = %.lr.ph, %7
  %.1 = phi ptr [ %8, %7 ], [ %.01012, %.lr.ph ]
  %6 = icmp ult ptr %.1, %2
  br i1 %6, label %7, label %.critedge

7:                                                ; preds = %.preheader
  %8 = getelementptr inbounds i8, ptr %.1, i64 1
  %9 = load i8, ptr %.1, align 1, !tbaa !5
  %.not = icmp eq i8 %9, 10
  br i1 %.not, label %.critedge, label %.preheader, !llvm.loop !8

.critedge:                                        ; preds = %.preheader, %7
  %.2 = phi ptr [ %8, %7 ], [ %.1, %.preheader ]
  %10 = icmp ult ptr %.2, %2
  br i1 %10, label %.lr.ph, label %.loopexit, !llvm.loop !10

.loopexit.loopexit:                               ; preds = %.lr.ph
  br label %.loopexit

.loopexit:                                        ; preds = %.critedge, %.lr.ph, %.loopexit.loopexit, %3
  %.0 = phi ptr [ null, %3 ], [ %.01012, %.loopexit.loopexit ], [ null, %.lr.ph ], [ null, %.critedge ]
  ret ptr %.0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @compare(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

!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"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


; Effective O3 passes: GVNPass,GlobalOptPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass