; LLVM IR from trustwallet/wallet-core :: trezor-crypto/crypto (address)

; 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: nounwind uwtable
define dso_local void @address_write_prefix_bytes(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = icmp ugt i32 %5, 16777215
  br i1 %6, label %7, label %13

7:                                                ; preds = %2
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = lshr i32 %8, 24
  %10 = trunc i32 %9 to i8
  %11 = load ptr, ptr %4, align 8, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %11, i32 1
  store ptr %12, ptr %4, align 8, !tbaa !9
  store i8 %10, ptr %11, align 1, !tbaa !11
  br label %13

13:                                               ; preds = %7, %2
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = icmp ugt i32 %14, 65535
  br i1 %15, label %16, label %23

16:                                               ; preds = %13
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = lshr i32 %17, 16
  %19 = and i32 %18, 255
  %20 = trunc i32 %19 to i8
  %21 = load ptr, ptr %4, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %21, i32 1
  store ptr %22, ptr %4, align 8, !tbaa !9
  store i8 %20, ptr %21, align 1, !tbaa !11
  br label %23

23:                                               ; preds = %16, %13
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = icmp ugt i32 %24, 255
  br i1 %25, label %26, label %33

26:                                               ; preds = %23
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = lshr i32 %27, 8
  %29 = and i32 %28, 255
  %30 = trunc i32 %29 to i8
  %31 = load ptr, ptr %4, align 8, !tbaa !9
  %32 = getelementptr inbounds i8, ptr %31, i32 1
  store ptr %32, ptr %4, align 8, !tbaa !9
  store i8 %30, ptr %31, align 1, !tbaa !11
  br label %33

33:                                               ; preds = %26, %23
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = and i32 %34, 255
  %36 = trunc i32 %35 to i8
  %37 = load ptr, ptr %4, align 8, !tbaa !9
  %38 = getelementptr inbounds i8, ptr %37, i32 1
  store ptr %38, ptr %4, align 8, !tbaa !9
  store i8 %36, ptr %37, align 1, !tbaa !11
  ret void
}

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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}


; 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 norecurse nosync nounwind willreturn memory(write, inaccessiblemem: none) uwtable
define dso_local void @address_write_prefix_bytes(i32 noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = icmp ugt i32 %0, 16777215
  br i1 %3, label %.thread, label %7

.thread:                                          ; preds = %2
  %4 = lshr i32 %0, 24
  %5 = trunc nuw i32 %4 to i8
  %6 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 %5, ptr %1, align 1, !tbaa !5
  br label %.thread15

7:                                                ; preds = %2
  %8 = icmp ugt i32 %0, 65535
  br i1 %8, label %.thread15, label %12

.thread15:                                        ; preds = %7, %.thread
  %.014 = phi ptr [ %6, %.thread ], [ %1, %7 ]
  %9 = lshr i32 %0, 16
  %10 = trunc i32 %9 to i8
  %11 = getelementptr inbounds i8, ptr %.014, i64 1
  store i8 %10, ptr %.014, align 1, !tbaa !5
  br label %14

12:                                               ; preds = %7
  %13 = icmp ugt i32 %0, 255
  br i1 %13, label %14, label %18

14:                                               ; preds = %.thread15, %12
  %.117 = phi ptr [ %11, %.thread15 ], [ %1, %12 ]
  %15 = lshr i32 %0, 8
  %16 = trunc i32 %15 to i8
  %17 = getelementptr inbounds i8, ptr %.117, i64 1
  store i8 %16, ptr %.117, align 1, !tbaa !5
  br label %18

18:                                               ; preds = %14, %12
  %.2 = phi ptr [ %17, %14 ], [ %1, %12 ]
  %19 = trunc i32 %0 to i8
  store i8 %19, ptr %.2, align 1, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass