; LLVM IR from cyberbotics/webots_ros2 :: webots_ros2_driver/webots/src/stb/tests (c_lexer_test)

; 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.stb_lexer = type { ptr, ptr, ptr, ptr, i32, ptr, ptr, i64, double, i64, ptr, i32 }
%struct.stb_lex_location = type { i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @stb_c_lexer_get_location(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
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.stb_lexer, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %12, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 1, ptr %8, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !14
  br label %13

13:                                               ; preds = %57, %3
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = load i8, ptr %14, align 1, !tbaa !15
  %16 = sext i8 %15 to i32
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %22

18:                                               ; preds = %13
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = icmp ult ptr %19, %20
  br label %22

22:                                               ; preds = %18, %13
  %23 = phi i1 [ false, %13 ], [ %21, %18 ]
  br i1 %23, label %24, label %58

24:                                               ; preds = %22
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load i8, ptr %25, align 1, !tbaa !15
  %27 = sext i8 %26 to i32
  %28 = icmp eq i32 %27, 10
  br i1 %28, label %34, label %29

29:                                               ; preds = %24
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load i8, ptr %30, align 1, !tbaa !15
  %32 = sext i8 %31 to i32
  %33 = icmp eq i32 %32, 13
  br i1 %33, label %34, label %52

34:                                               ; preds = %29, %24
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 0
  %37 = load i8, ptr %36, align 1, !tbaa !15
  %38 = sext i8 %37 to i32
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 1
  %41 = load i8, ptr %40, align 1, !tbaa !15
  %42 = sext i8 %41 to i32
  %43 = add nsw i32 %38, %42
  %44 = icmp eq i32 %43, 23
  %45 = zext i1 %44 to i64
  %46 = select i1 %44, i32 2, i32 1
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = sext i32 %46 to i64
  %49 = getelementptr inbounds i8, ptr %47, i64 %48
  store ptr %49, ptr %7, align 8, !tbaa !5
  %50 = load i32, ptr %8, align 4, !tbaa !14
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %8, align 4, !tbaa !14
  store i32 0, ptr %9, align 4, !tbaa !14
  br label %57

52:                                               ; preds = %29
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %53, i32 1
  store ptr %54, ptr %7, align 8, !tbaa !5
  %55 = load i32, ptr %9, align 4, !tbaa !14
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %9, align 4, !tbaa !14
  br label %57

57:                                               ; preds = %52, %34
  br label %13, !llvm.loop !16

58:                                               ; preds = %22
  %59 = load i32, ptr %8, align 4, !tbaa !14
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.stb_lex_location, ptr %60, i32 0, i32 0
  store i32 %59, ptr %61, align 4, !tbaa !18
  %62 = load i32, ptr %9, align 4, !tbaa !14
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.stb_lex_location, ptr %63, i32 0, i32 1
  store i32 %62, ptr %64, align 4, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

; 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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!10 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !6, i64 40, !6, i64 48, !12, i64 56, !13, i64 64, !12, i64 72, !6, i64 80, !11, i64 88}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !11, i64 0}
!19 = !{!"", !11, i64 0, !11, i64 4}
!20 = !{!19, !11, i64 4}


; 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: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @stb_c_lexer_get_location(ptr nocapture noundef readonly %0, ptr noundef readnone %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = load i8, ptr %4, align 1, !tbaa !13
  %6 = icmp ne i8 %5, 0
  %7 = icmp ult ptr %4, %1
  %8 = and i1 %7, %6
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %23
  %9 = phi i8 [ %24, %23 ], [ %5, %3 ]
  %.022 = phi i32 [ %.1, %23 ], [ 0, %3 ]
  %.01521 = phi i32 [ %.116, %23 ], [ 1, %3 ]
  %.01720 = phi ptr [ %.118, %23 ], [ %4, %3 ]
  switch i8 %9, label %20 [
    i8 10, label %10
    i8 13, label %10
  ]

10:                                               ; preds = %.lr.ph, %.lr.ph
  %11 = zext nneg i8 %9 to i32
  %12 = getelementptr inbounds i8, ptr %.01720, i64 1
  %13 = load i8, ptr %12, align 1, !tbaa !13
  %14 = sext i8 %13 to i32
  %15 = add nsw i32 %14, %11
  %16 = icmp eq i32 %15, 23
  %17 = select i1 %16, i64 2, i64 1
  %18 = getelementptr inbounds i8, ptr %.01720, i64 %17
  %19 = add nsw i32 %.01521, 1
  br label %23

20:                                               ; preds = %.lr.ph
  %21 = getelementptr inbounds i8, ptr %.01720, i64 1
  %22 = add nsw i32 %.022, 1
  br label %23

23:                                               ; preds = %20, %10
  %.118 = phi ptr [ %18, %10 ], [ %21, %20 ]
  %.116 = phi i32 [ %19, %10 ], [ %.01521, %20 ]
  %.1 = phi i32 [ 0, %10 ], [ %22, %20 ]
  %24 = load i8, ptr %.118, align 1, !tbaa !13
  %25 = icmp ne i8 %24, 0
  %26 = icmp ult ptr %.118, %1
  %27 = and i1 %26, %25
  br i1 %27, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %23, %3
  %.015.lcssa = phi i32 [ 1, %3 ], [ %.116, %23 ]
  %.0.lcssa = phi i32 [ 0, %3 ], [ %.1, %23 ]
  store i32 %.015.lcssa, ptr %2, align 4, !tbaa !16
  %28 = getelementptr inbounds i8, ptr %2, i64 4
  store i32 %.0.lcssa, ptr %28, align 4, !tbaa !18
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !7, i64 40, !7, i64 48, !11, i64 56, !12, i64 64, !11, i64 72, !7, i64 80, !10, i64 88}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"double", !8, i64 0}
!13 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !10, i64 0}
!17 = !{!"", !10, i64 0, !10, i64 4}
!18 = !{!17, !10, i64 4}


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