; LLVM IR from yettabaa/cub3D :: mlx-linux (mlx_int_str_to_wordtab)

; 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 willreturn memory(read)
declare i64 @strlen(ptr 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 i32 @mlx_int_str_str_cote(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = call i64 @strlen(ptr noundef %14) #4
  %16 = trunc i64 %15 to i32
  store i32 %16, ptr %8, align 4, !tbaa !9
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = icmp sgt i32 %17, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %68

21:                                               ; preds = %3
  store i32 0, ptr %12, align 4, !tbaa !9
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %62, %21
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  %27 = getelementptr inbounds i8, ptr %26, i64 -1
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = icmp ne i8 %28, 0
  br i1 %29, label %30, label %67

30:                                               ; preds = %22
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i8, ptr %31, align 1, !tbaa !11
  %33 = sext i8 %32 to i32
  %34 = icmp eq i32 %33, 34
  br i1 %34, label %35, label %38

35:                                               ; preds = %30
  %36 = load i32, ptr %12, align 4, !tbaa !9
  %37 = sub nsw i32 1, %36
  store i32 %37, ptr %12, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %35, %30
  %39 = load i32, ptr %12, align 4, !tbaa !9
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %62, label %41

41:                                               ; preds = %38
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %42, ptr %10, align 8, !tbaa !5
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %43, ptr %11, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %60, %41
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i32 1
  store ptr %46, ptr %11, align 8, !tbaa !5
  %47 = load i8, ptr %45, align 1, !tbaa !11
  %48 = sext i8 %47 to i32
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i32 1
  store ptr %50, ptr %10, align 8, !tbaa !5
  %51 = load i8, ptr %49, align 1, !tbaa !11
  %52 = sext i8 %51 to i32
  %53 = icmp eq i32 %48, %52
  br i1 %53, label %54, label %61

54:                                               ; preds = %44
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = load i8, ptr %55, align 1, !tbaa !11
  %57 = icmp ne i8 %56, 0
  br i1 %57, label %60, label %58

58:                                               ; preds = %54
  %59 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %59, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %68

60:                                               ; preds = %54
  br label %44, !llvm.loop !12

61:                                               ; preds = %44
  br label %62

62:                                               ; preds = %61, %38
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds i8, ptr %63, i32 1
  store ptr %64, ptr %5, align 8, !tbaa !5
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %9, align 4, !tbaa !9
  br label %22, !llvm.loop !14

67:                                               ; preds = %22
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %68

68:                                               ; preds = %67, %58, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %69 = load i32, ptr %4, align 4
  ret i32 %69
}

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


; 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: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local i32 @mlx_int_str_str_cote(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #2
  %5 = trunc i64 %4 to i32
  %6 = icmp sgt i32 %5, %2
  br i1 %6, label %.loopexit24, label %.preheader25

.preheader25:                                     ; preds = %3
  %sext = shl i64 %4, 32
  %7 = ashr exact i64 %sext, 32
  %8 = getelementptr inbounds i8, ptr %0, i64 %7
  %9 = getelementptr inbounds i8, ptr %8, i64 -1
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %.not28 = icmp eq i8 %10, 0
  br i1 %.not28, label %.loopexit24, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader25, %.loopexit
  %.031 = phi i32 [ %spec.select, %.loopexit ], [ 0, %.preheader25 ]
  %.01830 = phi i32 [ %22, %.loopexit ], [ 0, %.preheader25 ]
  %.02029 = phi ptr [ %21, %.loopexit ], [ %0, %.preheader25 ]
  %11 = load i8, ptr %.02029, align 1, !tbaa !5
  %12 = icmp eq i8 %11, 34
  %13 = sub nuw nsw i32 1, %.031
  %spec.select = select i1 %12, i32 %13, i32 %.031
  %.not22 = icmp eq i32 %spec.select, 0
  br i1 %.not22, label %.preheader.preheader, label %.loopexit

.preheader.preheader:                             ; preds = %.lr.ph
  %.pre = load i8, ptr %1, align 1, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %17
  %14 = phi i8 [ %20, %17 ], [ %.pre, %.preheader.preheader ]
  %.017 = phi ptr [ %18, %17 ], [ %.02029, %.preheader.preheader ]
  %.016 = phi ptr [ %19, %17 ], [ %1, %.preheader.preheader ]
  %15 = load i8, ptr %.017, align 1, !tbaa !5
  %16 = icmp eq i8 %14, %15
  br i1 %16, label %17, label %.loopexit

17:                                               ; preds = %.preheader
  %18 = getelementptr inbounds i8, ptr %.017, i64 1
  %19 = getelementptr inbounds i8, ptr %.016, i64 1
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %.not23 = icmp eq i8 %20, 0
  br i1 %.not23, label %.loopexit24, label %.preheader, !llvm.loop !8

.loopexit:                                        ; preds = %.preheader, %.lr.ph
  %21 = getelementptr inbounds i8, ptr %.02029, i64 1
  %22 = add nuw nsw i32 %.01830, 1
  %23 = getelementptr inbounds i8, ptr %21, i64 %7
  %24 = getelementptr inbounds i8, ptr %23, i64 -1
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %.not = icmp eq i8 %25, 0
  br i1 %.not, label %.loopexit24, label %.lr.ph, !llvm.loop !10

.loopexit24:                                      ; preds = %.loopexit, %17, %.preheader25, %3
  %.019 = phi i32 [ -1, %3 ], [ -1, %.preheader25 ], [ %.01830, %17 ], [ -1, %.loopexit ]
  ret i32 %.019
}

attributes #0 = { 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 #1 = { nofree nounwind memory(read, 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" }
attributes #2 = { 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 = !{!"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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass