; LLVM IR from sca-secure-library-sca25519/sca25519 :: libopencm3/lib/lpc43xx (ssp)

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

8:                                                ; preds = %2
  store i32 1074278400, ptr %5, align 4, !tbaa !5
  br label %10

9:                                                ; preds = %2
  store i32 1074548736, ptr %5, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %9, %8
  br label %11

11:                                               ; preds = %19, %10
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = add i32 %12, 12
  %14 = zext i32 %13 to i64
  %15 = inttoptr i64 %14 to ptr
  %16 = load volatile i32, ptr %15, align 4, !tbaa !5
  %17 = and i32 %16, 2
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %11
  br label %11, !llvm.loop !11

20:                                               ; preds = %11
  %21 = load i16, ptr %4, align 2, !tbaa !9
  %22 = zext i16 %21 to i32
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = add i32 %23, 8
  %25 = zext i32 %24 to i64
  %26 = inttoptr i64 %25 to ptr
  store volatile i32 %22, ptr %26, align 4, !tbaa !5
  %27 = load i32, ptr %3, align 4, !tbaa !5
  call void @ssp_wait_until_not_busy(i32 noundef %27)
  br label %28

28:                                               ; preds = %36, %20
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = add i32 %29, 12
  %31 = zext i32 %30 to i64
  %32 = inttoptr i64 %31 to ptr
  %33 = load volatile i32, ptr %32, align 4, !tbaa !5
  %34 = and i32 %33, 4
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %28
  br label %28, !llvm.loop !13

37:                                               ; preds = %28
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = add i32 %38, 8
  %40 = zext i32 %39 to i64
  %41 = inttoptr i64 %40 to ptr
  %42 = load volatile i32, ptr %41, align 4, !tbaa !5
  %43 = trunc i32 %42 to i16
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i16 %43
}

; Function Attrs: nounwind uwtable
declare hidden void @ssp_wait_until_not_busy(i32 noundef) #1

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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 zeroext i16 @ssp_transfer(i32 noundef %0, i16 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = icmp eq i32 %0, 0
  %. = select i1 %3, i32 1074278400, i32 1074548736
  %4 = or disjoint i32 %., 12
  %5 = zext nneg i32 %4 to i64
  %6 = inttoptr i64 %5 to ptr
  br label %7

7:                                                ; preds = %7, %2
  %8 = load volatile i32, ptr %6, align 4, !tbaa !5
  %9 = and i32 %8, 2
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %7, label %11, !llvm.loop !9

11:                                               ; preds = %7
  %12 = zext i16 %1 to i32
  %13 = or disjoint i32 %., 8
  %14 = zext nneg i32 %13 to i64
  %15 = inttoptr i64 %14 to ptr
  store volatile i32 %12, ptr %15, align 8, !tbaa !5
  tail call void @ssp_wait_until_not_busy(i32 noundef %0)
  br label %16

16:                                               ; preds = %16, %11
  %17 = load volatile i32, ptr %6, align 4, !tbaa !5
  %18 = and i32 %17, 4
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %16, label %20, !llvm.loop !11

20:                                               ; preds = %16
  %21 = load volatile i32, ptr %15, align 8, !tbaa !5
  %22 = trunc i32 %21 to i16
  ret i16 %22
}

; Function Attrs: nounwind uwtable
declare hidden void @ssp_wait_until_not_busy(i32 noundef) local_unnamed_addr #0

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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,SROAPass,SimplifyCFGPass,TailCallElimPass