; LLVM IR from yettabaa/FdF :: libft_fdf (ft_atoi)

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

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

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

; 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 @ft_atoi_hexa(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %79

12:                                               ; preds = %1
  store ptr @.str, ptr %7, align 8, !tbaa !5
  store i32 2, ptr %5, align 4, !tbaa !9
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %70, %12
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %14, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %19 = icmp ne i8 %18, 0
  br i1 %19, label %20, label %77

20:                                               ; preds = %13
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %21, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !11
  %26 = sext i8 %25 to i32
  %27 = call i32 @ft_isupper(i32 noundef %26)
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %39

29:                                               ; preds = %20
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %31, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !11
  %36 = sext i8 %35 to i32
  %37 = add nsw i32 %36, 32
  %38 = call i32 @ft_strchr_ind(ptr noundef %30, i32 noundef %37)
  store i32 %38, ptr %6, align 4, !tbaa !9
  br label %48

39:                                               ; preds = %20
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %41, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !11
  %46 = sext i8 %45 to i32
  %47 = call i32 @ft_strchr_ind(ptr noundef %40, i32 noundef %46)
  store i32 %47, ptr %6, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %39, %29
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i8, ptr %49, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !11
  %54 = sext i8 %53 to i32
  %55 = call i32 @ft_isupper(i32 noundef %54)
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %66, label %57

57:                                               ; preds = %48
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i8, ptr %58, i64 %60
  %62 = load i8, ptr %61, align 1, !tbaa !11
  %63 = sext i8 %62 to i32
  %64 = call i32 @ft_islower(i32 noundef %63)
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %70

66:                                               ; preds = %57, %48
  %67 = load i32, ptr %6, align 4, !tbaa !9
  %68 = icmp eq i32 %67, 0
  br i1 %68, label %69, label %70

69:                                               ; preds = %66
  br label %77

70:                                               ; preds = %66, %57
  %71 = load i32, ptr %4, align 4, !tbaa !9
  %72 = mul nsw i32 %71, 16
  %73 = load i32, ptr %6, align 4, !tbaa !9
  %74 = add nsw i32 %72, %73
  store i32 %74, ptr %4, align 4, !tbaa !9
  %75 = load i32, ptr %5, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %5, align 4, !tbaa !9
  br label %13, !llvm.loop !12

77:                                               ; preds = %69, %13
  %78 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %78, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %79

79:                                               ; preds = %77, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %80 = load i32, ptr %2, align 4
  ret i32 %80
}

declare i32 @ft_isupper(i32 noundef) #2

declare i32 @ft_strchr_ind(ptr noundef, i32 noundef) #2

declare i32 @ft_islower(i32 noundef) #2

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

!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 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @ft_atoi_hexa(ptr noundef readonly %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %1
  %2 = getelementptr inbounds i8, ptr %0, i64 2
  %3 = load i8, ptr %2, align 1, !tbaa !5
  %.not2730 = icmp eq i8 %3, 0
  br i1 %.not2730, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %22
  %indvars.iv = phi i64 [ %indvars.iv.next, %22 ], [ 2, %.preheader ]
  %4 = phi i8 [ %26, %22 ], [ %3, %.preheader ]
  %5 = phi ptr [ %25, %22 ], [ %2, %.preheader ]
  %.02431 = phi i32 [ %24, %22 ], [ 0, %.preheader ]
  %6 = sext i8 %4 to i32
  %7 = tail call i32 @ft_isupper(i32 noundef %6) #2
  %.not28 = icmp eq i32 %7, 0
  %8 = load i8, ptr %5, align 1, !tbaa !5
  %9 = sext i8 %8 to i32
  %10 = add nsw i32 %9, 32
  %.sink = select i1 %.not28, i32 %9, i32 %10
  %11 = tail call i32 @ft_strchr_ind(ptr noundef nonnull @.str, i32 noundef %.sink) #2
  %12 = load i8, ptr %5, align 1, !tbaa !5
  %13 = sext i8 %12 to i32
  %14 = tail call i32 @ft_isupper(i32 noundef %13) #2
  %.not29 = icmp eq i32 %14, 0
  br i1 %.not29, label %15, label %21

15:                                               ; preds = %.lr.ph
  %16 = load i8, ptr %5, align 1, !tbaa !5
  %17 = sext i8 %16 to i32
  %18 = tail call i32 @ft_islower(i32 noundef %17) #2
  %19 = icmp ne i32 %18, 0
  %20 = icmp eq i32 %11, 0
  %or.cond = select i1 %19, i1 %20, i1 false
  br i1 %or.cond, label %.loopexit, label %22

21:                                               ; preds = %.lr.ph
  %.old1 = icmp eq i32 %11, 0
  br i1 %.old1, label %.loopexit, label %22

22:                                               ; preds = %21, %15
  %23 = shl nsw i32 %.02431, 4
  %24 = add nsw i32 %11, %23
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %.not27 = icmp eq i8 %26, 0
  br i1 %.not27, label %.loopexit, label %.lr.ph, !llvm.loop !8

.loopexit:                                        ; preds = %21, %15, %22, %.preheader, %1
  %.0 = phi i32 [ 0, %1 ], [ 0, %.preheader ], [ %.02431, %21 ], [ %.02431, %15 ], [ %24, %22 ]
  ret i32 %.0
}

declare i32 @ft_isupper(i32 noundef) local_unnamed_addr #1

declare i32 @ft_strchr_ind(ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @ft_islower(i32 noundef) local_unnamed_addr #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 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass