; LLVM IR from sca-secure-library-sca25519/sca25519 :: STM32F407-ephemeral/crypto/numerics (bigint)

; 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
define dso_local void @shiftRightOne(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds [8 x i32], ptr %6, i64 0, i64 0
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = lshr i32 %8, 1
  store i32 %9, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds [8 x i32], ptr %10, i64 0, i64 7
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = and i32 %12, -2147483648
  store i32 %13, ptr %5, align 4, !tbaa !10
  store i32 0, ptr %4, align 4, !tbaa !10
  br label %14

14:                                               ; preds = %40, %1
  %15 = load i32, ptr %4, align 4, !tbaa !10
  %16 = icmp slt i32 %15, 7
  br i1 %16, label %17, label %43

17:                                               ; preds = %14
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = load i32, ptr %4, align 4, !tbaa !10
  %20 = add nsw i32 %19, 1
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [8 x i32], ptr %18, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = and i32 %23, 1
  store i32 %24, ptr %3, align 4, !tbaa !10
  %25 = load i32, ptr %3, align 4, !tbaa !10
  %26 = shl i32 %25, 31
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !10
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [8 x i32], ptr %27, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = add i32 %31, %26
  store i32 %32, ptr %30, align 4, !tbaa !9
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !10
  %35 = add nsw i32 %34, 1
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [8 x i32], ptr %33, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = lshr i32 %38, 1
  store i32 %39, ptr %37, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %17
  %41 = load i32, ptr %4, align 4, !tbaa !10
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %4, align 4, !tbaa !10
  br label %14, !llvm.loop !12

43:                                               ; preds = %14
  %44 = load i32, ptr %5, align 4, !tbaa !10
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds [8 x i32], ptr %45, i64 0, i64 7
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = or i32 %47, %44
  store i32 %48, ptr %46, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

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 }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !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 nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @shiftRightOne(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 28
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load <4 x i32>, ptr %5, align 4, !tbaa !5
  %8 = insertelement <4 x i32> poison, i32 %2, i64 0
  %9 = shufflevector <4 x i32> %8, <4 x i32> %7, <4 x i32> <i32 0, i32 4, i32 5, i32 6>
  %10 = tail call <4 x i32> @llvm.fshl.v4i32(<4 x i32> %7, <4 x i32> %9, <4 x i32> <i32 31, i32 31, i32 31, i32 31>)
  store <4 x i32> %10, ptr %0, align 4, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 20
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = extractelement <4 x i32> %7, i64 3
  %14 = tail call i32 @llvm.fshl.i32(i32 %12, i32 %13, i32 31)
  store i32 %14, ptr %6, align 4, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = tail call i32 @llvm.fshl.i32(i32 %16, i32 %12, i32 31)
  store i32 %17, ptr %11, align 4, !tbaa !5
  %18 = tail call i32 @llvm.fshl.i32(i32 %4, i32 %16, i32 31)
  store i32 %18, ptr %15, align 4, !tbaa !5
  %19 = lshr i32 %4, 1
  %20 = and i32 %4, -2147483648
  %21 = or disjoint i32 %19, %20
  store i32 %21, ptr %3, align 4, !tbaa !5
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.fshl.i32(i32, i32, i32) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i32> @llvm.fshl.v4i32(<4 x i32>, <4 x i32>, <4 x i32>) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 speculatable willreturn memory(none) }

!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: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass