; LLVM IR from trustwallet/wallet-core :: trezor-crypto/crypto/chacha20poly1305 (poly1305-donna)

; 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.poly1305_state_internal_t = type { [5 x i64], [5 x i64], [4 x i64], i64, [16 x i8], i8 }

; Function Attrs: nounwind uwtable
define dso_local void @poly1305_init(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %6, ptr %5, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 0
  %9 = call i64 @U8TO32(ptr noundef %8)
  %10 = and i64 %9, 67108863
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.poly1305_state_internal_t, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds [5 x i64], ptr %12, i64 0, i64 0
  store i64 %10, ptr %13, align 8, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 3
  %16 = call i64 @U8TO32(ptr noundef %15)
  %17 = lshr i64 %16, 2
  %18 = and i64 %17, 67108611
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.poly1305_state_internal_t, ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds [5 x i64], ptr %20, i64 0, i64 1
  store i64 %18, ptr %21, align 8, !tbaa !9
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 6
  %24 = call i64 @U8TO32(ptr noundef %23)
  %25 = lshr i64 %24, 4
  %26 = and i64 %25, 67092735
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.poly1305_state_internal_t, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds [5 x i64], ptr %28, i64 0, i64 2
  store i64 %26, ptr %29, align 8, !tbaa !9
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 9
  %32 = call i64 @U8TO32(ptr noundef %31)
  %33 = lshr i64 %32, 6
  %34 = and i64 %33, 66076671
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.poly1305_state_internal_t, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds [5 x i64], ptr %36, i64 0, i64 3
  store i64 %34, ptr %37, align 8, !tbaa !9
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i64 12
  %40 = call i64 @U8TO32(ptr noundef %39)
  %41 = lshr i64 %40, 8
  %42 = and i64 %41, 1048575
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.poly1305_state_internal_t, ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds [5 x i64], ptr %44, i64 0, i64 4
  store i64 %42, ptr %45, align 8, !tbaa !9
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.poly1305_state_internal_t, ptr %46, i32 0, i32 1
  %48 = getelementptr inbounds [5 x i64], ptr %47, i64 0, i64 0
  store i64 0, ptr %48, align 8, !tbaa !9
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.poly1305_state_internal_t, ptr %49, i32 0, i32 1
  %51 = getelementptr inbounds [5 x i64], ptr %50, i64 0, i64 1
  store i64 0, ptr %51, align 8, !tbaa !9
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.poly1305_state_internal_t, ptr %52, i32 0, i32 1
  %54 = getelementptr inbounds [5 x i64], ptr %53, i64 0, i64 2
  store i64 0, ptr %54, align 8, !tbaa !9
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.poly1305_state_internal_t, ptr %55, i32 0, i32 1
  %57 = getelementptr inbounds [5 x i64], ptr %56, i64 0, i64 3
  store i64 0, ptr %57, align 8, !tbaa !9
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.poly1305_state_internal_t, ptr %58, i32 0, i32 1
  %60 = getelementptr inbounds [5 x i64], ptr %59, i64 0, i64 4
  store i64 0, ptr %60, align 8, !tbaa !9
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i64 16
  %63 = call i64 @U8TO32(ptr noundef %62)
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.poly1305_state_internal_t, ptr %64, i32 0, i32 2
  %66 = getelementptr inbounds [4 x i64], ptr %65, i64 0, i64 0
  store i64 %63, ptr %66, align 8, !tbaa !9
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds i8, ptr %67, i64 20
  %69 = call i64 @U8TO32(ptr noundef %68)
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.poly1305_state_internal_t, ptr %70, i32 0, i32 2
  %72 = getelementptr inbounds [4 x i64], ptr %71, i64 0, i64 1
  store i64 %69, ptr %72, align 8, !tbaa !9
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %73, i64 24
  %75 = call i64 @U8TO32(ptr noundef %74)
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.poly1305_state_internal_t, ptr %76, i32 0, i32 2
  %78 = getelementptr inbounds [4 x i64], ptr %77, i64 0, i64 2
  store i64 %75, ptr %78, align 8, !tbaa !9
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds i8, ptr %79, i64 28
  %81 = call i64 @U8TO32(ptr noundef %80)
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.poly1305_state_internal_t, ptr %82, i32 0, i32 2
  %84 = getelementptr inbounds [4 x i64], ptr %83, i64 0, i64 3
  store i64 %81, ptr %84, align 8, !tbaa !9
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.poly1305_state_internal_t, ptr %85, i32 0, i32 3
  store i64 0, ptr %86, align 8, !tbaa !11
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.poly1305_state_internal_t, ptr %87, i32 0, i32 5
  store i8 0, ptr %88, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #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: nounwind uwtable
declare hidden i64 @U8TO32(ptr noundef) #0

; 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 112}
!12 = !{!"poly1305_state_internal_t", !7, i64 0, !7, i64 40, !7, i64 80, !10, i64 112, !7, i64 120, !7, i64 136}
!13 = !{!12, !7, i64 136}


; 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: nounwind uwtable
define dso_local void @poly1305_init(ptr nocapture noundef writeonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call i64 @U8TO32(ptr noundef %1)
  %4 = and i64 %3, 67108863
  store i64 %4, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 3
  %6 = tail call i64 @U8TO32(ptr noundef nonnull %5)
  %7 = lshr i64 %6, 2
  %8 = and i64 %7, 67108611
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %8, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %1, i64 6
  %11 = tail call i64 @U8TO32(ptr noundef nonnull %10)
  %12 = lshr i64 %11, 4
  %13 = and i64 %12, 67092735
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %13, ptr %14, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %1, i64 9
  %16 = tail call i64 @U8TO32(ptr noundef nonnull %15)
  %17 = lshr i64 %16, 6
  %18 = and i64 %17, 66076671
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %18, ptr %19, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %1, i64 12
  %21 = tail call i64 @U8TO32(ptr noundef nonnull %20)
  %22 = lshr i64 %21, 8
  %23 = and i64 %22, 1048575
  %24 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 %23, ptr %24, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %0, i64 40
  %26 = getelementptr inbounds i8, ptr %1, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %25, i8 0, i64 40, i1 false)
  %27 = tail call i64 @U8TO32(ptr noundef nonnull %26)
  %28 = getelementptr inbounds i8, ptr %0, i64 80
  store i64 %27, ptr %28, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %1, i64 20
  %30 = tail call i64 @U8TO32(ptr noundef nonnull %29)
  %31 = getelementptr inbounds i8, ptr %0, i64 88
  store i64 %30, ptr %31, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %1, i64 24
  %33 = tail call i64 @U8TO32(ptr noundef nonnull %32)
  %34 = getelementptr inbounds i8, ptr %0, i64 96
  store i64 %33, ptr %34, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %1, i64 28
  %36 = tail call i64 @U8TO32(ptr noundef nonnull %35)
  %37 = getelementptr inbounds i8, ptr %0, i64 104
  store i64 %36, ptr %37, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %0, i64 112
  store i64 0, ptr %38, align 8, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %0, i64 136
  store i8 0, ptr %39, align 8, !tbaa !11
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden i64 @U8TO32(ptr noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 112}
!10 = !{!"poly1305_state_internal_t", !7, i64 0, !7, i64 40, !7, i64 80, !6, i64 112, !7, i64 120, !7, i64 136}
!11 = !{!10, !7, i64 136}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass