; LLVM IR from FrancesoM/Bisc8FX :: sdk_projects/bisc8_platform/ps7_cortexa9_0/standalone_domain/bsp/ps7_cortexa9_0_ (ConvertStringToHexLE)

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @Xil_ConvertCharToNibble(i8 noundef zeroext, ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @Xil_ConvertStringToHexLE(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  store i8 0, ptr %8, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  store i8 0, ptr %9, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 1, ptr %11, align 4, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp eq ptr null, %12
  br i1 %13, label %17, label %14

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = icmp eq ptr null, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %14, %3
  store i32 15, ptr %11, align 4, !tbaa !9
  br label %85

18:                                               ; preds = %14
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %25, label %21

21:                                               ; preds = %18
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = urem i32 %22, 8
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %21, %18
  store i32 15, ptr %11, align 4, !tbaa !9
  br label %85

26:                                               ; preds = %21
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = zext i32 %27 to i64
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = call i64 @strlen(ptr noundef %29) #4
  %31 = mul i64 %30, 4
  %32 = icmp ne i64 %28, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %26
  store i32 15, ptr %11, align 4, !tbaa !9
  br label %85

34:                                               ; preds = %26
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = udiv i32 %35, 8
  %37 = sub i32 %36, 1
  store i32 %37, ptr %10, align 4, !tbaa !9
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %81, %34
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = udiv i32 %40, 4
  %42 = icmp ult i32 %39, %41
  br i1 %42, label %43, label %84

43:                                               ; preds = %38
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %44, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !11
  %49 = call i32 @Xil_ConvertCharToNibble(i8 noundef zeroext %48, ptr noundef %9)
  store i32 %49, ptr %11, align 4, !tbaa !9
  %50 = load i32, ptr %11, align 4, !tbaa !9
  %51 = zext i32 %50 to i64
  %52 = icmp eq i64 0, %51
  br i1 %52, label %53, label %80

53:                                               ; preds = %43
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = add i32 %55, 1
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds i8, ptr %54, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !11
  %60 = call i32 @Xil_ConvertCharToNibble(i8 noundef zeroext %59, ptr noundef %8)
  store i32 %60, ptr %11, align 4, !tbaa !9
  %61 = load i32, ptr %11, align 4, !tbaa !9
  %62 = zext i32 %61 to i64
  %63 = icmp eq i64 0, %62
  br i1 %63, label %64, label %78

64:                                               ; preds = %53
  %65 = load i8, ptr %9, align 1, !tbaa !11
  %66 = zext i8 %65 to i32
  %67 = shl i32 %66, 4
  %68 = load i8, ptr %8, align 1, !tbaa !11
  %69 = zext i8 %68 to i32
  %70 = or i32 %67, %69
  %71 = trunc i32 %70 to i8
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = load i32, ptr %10, align 4, !tbaa !9
  %74 = zext i32 %73 to i64
  %75 = getelementptr inbounds i8, ptr %72, i64 %74
  store i8 %71, ptr %75, align 1, !tbaa !11
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = sub i32 %76, 1
  store i32 %77, ptr %10, align 4, !tbaa !9
  br label %79

78:                                               ; preds = %53
  store i32 15, ptr %11, align 4, !tbaa !9
  br label %85

79:                                               ; preds = %64
  br label %81

80:                                               ; preds = %43
  store i32 15, ptr %11, align 4, !tbaa !9
  br label %85

81:                                               ; preds = %79
  %82 = load i32, ptr %7, align 4, !tbaa !9
  %83 = add i32 %82, 2
  store i32 %83, ptr %7, align 4, !tbaa !9
  br label %38, !llvm.loop !12

84:                                               ; preds = %38
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %85

85:                                               ; preds = %84, %80, %78, %33, %25, %17
  %86 = load i32, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 %86
}

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


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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @Xil_ConvertCharToNibble(i8 noundef zeroext, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 16) i32 @Xil_ConvertStringToHexLE(ptr noundef readonly %0, ptr noundef writeonly %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca i8, align 1
  %5 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #3
  store i8 0, ptr %4, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %5) #3
  store i8 0, ptr %5, align 1, !tbaa !5
  %6 = icmp eq ptr %0, null
  %7 = icmp eq ptr %1, null
  %or.cond = or i1 %6, %7
  br i1 %or.cond, label %.loopexit, label %8

8:                                                ; preds = %3
  %9 = icmp ne i32 %2, 0
  %10 = and i32 %2, 7
  %.not = icmp eq i32 %10, 0
  %or.cond26 = and i1 %9, %.not
  br i1 %or.cond26, label %11, label %.loopexit

11:                                               ; preds = %8
  %12 = zext i32 %2 to i64
  %13 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #4
  %14 = shl i64 %13, 2
  %.not25 = icmp eq i64 %14, %12
  br i1 %.not25, label %15, label %.loopexit

15:                                               ; preds = %11
  %16 = lshr exact i32 %2, 3
  %17 = lshr exact i32 %2, 2
  %18 = zext nneg i32 %17 to i64
  br label %19

19:                                               ; preds = %15, %30
  %indvars.iv = phi i64 [ 0, %15 ], [ %indvars.iv.next, %30 ]
  %.02029.in = phi i32 [ %16, %15 ], [ %.02029, %30 ]
  %.02029 = add nsw i32 %.02029.in, -1
  %20 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %22 = call i32 @Xil_ConvertCharToNibble(i8 noundef zeroext %21, ptr noundef nonnull %5)
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %.loopexit

24:                                               ; preds = %19
  %25 = or disjoint i64 %indvars.iv, 1
  %26 = getelementptr inbounds i8, ptr %0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !5
  %28 = call i32 @Xil_ConvertCharToNibble(i8 noundef zeroext %27, ptr noundef nonnull %4)
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %.loopexit

30:                                               ; preds = %24
  %31 = load i8, ptr %5, align 1, !tbaa !5
  %32 = shl i8 %31, 4
  %33 = load i8, ptr %4, align 1, !tbaa !5
  %34 = or i8 %32, %33
  %35 = zext i32 %.02029 to i64
  %36 = getelementptr inbounds i8, ptr %1, i64 %35
  store i8 %34, ptr %36, align 1, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
  %37 = icmp ult i64 %indvars.iv.next, %18
  br i1 %37, label %19, label %.loopexit, !llvm.loop !8

.loopexit:                                        ; preds = %30, %19, %24, %11, %8, %3
  %.0 = phi i32 [ 15, %3 ], [ 15, %8 ], [ 15, %11 ], [ 0, %30 ], [ 15, %19 ], [ 15, %24 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #3
  ret i32 %.0
}

attributes #0 = { mustprogress 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 = { 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 #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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass