; LLVM IR from cvra/robot-software :: lib/parameter/parameter.ll (parameter_find_w_id_len)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @id_split(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden ptr @get_subnamespace(ptr noundef, ptr noundef, i64 noundef) #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 ptr @_parameter_find_w_id_len(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %12, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %13

13:                                               ; preds = %58, %3
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %59

16:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load i32, ptr %9, align 4, !tbaa !11
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %17, i64 %19
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = load i32, ptr %9, align 4, !tbaa !11
  %23 = zext i32 %22 to i64
  %24 = sub i64 %21, %23
  %25 = trunc i64 %24 to i32
  %26 = call i32 @id_split(ptr noundef %20, i32 noundef %25)
  store i32 %26, ptr %10, align 4, !tbaa !11
  %27 = load i32, ptr %10, align 4, !tbaa !11
  %28 = load i32, ptr %9, align 4, !tbaa !11
  %29 = add i32 %27, %28
  %30 = zext i32 %29 to i64
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = icmp ult i64 %30, %31
  br i1 %32, label %33, label %42

33:                                               ; preds = %16
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load i32, ptr %9, align 4, !tbaa !11
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds i8, ptr %35, i64 %37
  %39 = load i32, ptr %10, align 4, !tbaa !11
  %40 = sext i32 %39 to i64
  %41 = call ptr @get_subnamespace(ptr noundef %34, ptr noundef %38, i64 noundef %40)
  store ptr %41, ptr %8, align 8, !tbaa !5
  br label %51

42:                                               ; preds = %16
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load i32, ptr %9, align 4, !tbaa !11
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %44, i64 %46
  %48 = load i32, ptr %10, align 4, !tbaa !11
  %49 = sext i32 %48 to i64
  %50 = call ptr @get_parameter(ptr noundef %43, ptr noundef %47, i64 noundef %49)
  store ptr %50, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %56

51:                                               ; preds = %33
  %52 = load i32, ptr %10, align 4, !tbaa !11
  %53 = add nsw i32 %52, 1
  %54 = load i32, ptr %9, align 4, !tbaa !11
  %55 = add i32 %54, %53
  store i32 %55, ptr %9, align 4, !tbaa !11
  store i32 0, ptr %11, align 4
  br label %56

56:                                               ; preds = %51, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %57 = load i32, ptr %11, align 4
  switch i32 %57, label %60 [
    i32 0, label %58
  ]

58:                                               ; preds = %56
  br label %13, !llvm.loop !13

59:                                               ; preds = %13
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %60

60:                                               ; preds = %59, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %61 = load ptr, ptr %4, align 8
  ret ptr %61
}

; Function Attrs: nounwind uwtable
declare hidden ptr @get_parameter(ptr noundef, ptr noundef, i64 noundef) #1

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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

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

; Function Attrs: nounwind uwtable
declare hidden ptr @get_subnamespace(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @_parameter_find_w_id_len(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %.not30 = icmp eq ptr %0, null
  br i1 %.not30, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %4 = trunc i64 %2 to i32
  br label %5

5:                                                ; preds = %.lr.ph, %15
  %.02132 = phi i32 [ 0, %.lr.ph ], [ %18, %15 ]
  %.02331 = phi ptr [ %0, %.lr.ph ], [ %16, %15 ]
  %6 = zext i32 %.02132 to i64
  %7 = getelementptr inbounds i8, ptr %1, i64 %6
  %8 = sub i32 %4, %.02132
  %9 = tail call i32 @id_split(ptr noundef %7, i32 noundef %8)
  %10 = add i32 %9, %.02132
  %11 = zext i32 %10 to i64
  %12 = icmp ult i64 %11, %2
  %13 = sext i32 %9 to i64
  br i1 %12, label %15, label %.thread

.thread:                                          ; preds = %5
  %14 = tail call ptr @get_parameter(ptr noundef nonnull %.02331, ptr noundef %7, i64 noundef %13)
  br label %.loopexit

15:                                               ; preds = %5
  %16 = tail call ptr @get_subnamespace(ptr noundef nonnull %.02331, ptr noundef %7, i64 noundef %13)
  %17 = add i32 %.02132, 1
  %18 = add i32 %17, %9
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %.loopexit, label %5

.loopexit:                                        ; preds = %15, %3, %.thread
  %.2 = phi ptr [ %14, %.thread ], [ null, %3 ], [ null, %15 ]
  ret ptr %.2
}

; Function Attrs: nounwind uwtable
declare hidden ptr @get_parameter(ptr noundef, ptr noundef, i64 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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass