; LLVM IR from sca-secure-library-sca25519/sca25519 :: libopencm3/lib/swm050 (syscon)

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

11:                                               ; preds = %2
  %12 = load volatile i32, ptr inttoptr (i64 1073741952 to ptr), align 4, !tbaa !11
  %13 = and i32 %12, -4
  store i32 %13, ptr %5, align 4, !tbaa !11
  %14 = load i32, ptr %5, align 4, !tbaa !11
  %15 = load i8, ptr %4, align 1, !tbaa !9, !range !13, !noundef !14
  %16 = trunc i8 %15 to i1
  %17 = zext i1 %16 to i64
  %18 = select i1 %16, i32 1, i32 0
  %19 = or i32 %14, %18
  store volatile i32 %19, ptr inttoptr (i64 1073741952 to ptr), align 4, !tbaa !11
  br label %20

20:                                               ; preds = %11, %2
  %21 = load i16, ptr %3, align 2, !tbaa !5
  %22 = zext i16 %21 to i32
  %23 = and i32 %22, 2
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %34

25:                                               ; preds = %20
  %26 = load volatile i32, ptr inttoptr (i64 1073741952 to ptr), align 4, !tbaa !11
  %27 = and i32 %26, -13
  store i32 %27, ptr %5, align 4, !tbaa !11
  %28 = load i32, ptr %5, align 4, !tbaa !11
  %29 = load i8, ptr %4, align 1, !tbaa !9, !range !13, !noundef !14
  %30 = trunc i8 %29 to i1
  %31 = zext i1 %30 to i64
  %32 = select i1 %30, i32 4, i32 0
  %33 = or i32 %28, %32
  store volatile i32 %33, ptr inttoptr (i64 1073741952 to ptr), align 4, !tbaa !11
  br label %34

34:                                               ; preds = %25, %20
  %35 = load i16, ptr %3, align 2, !tbaa !5
  %36 = zext i16 %35 to i32
  %37 = and i32 %36, 4
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %48

39:                                               ; preds = %34
  %40 = load volatile i32, ptr inttoptr (i64 1073741952 to ptr), align 4, !tbaa !11
  %41 = and i32 %40, -49
  store i32 %41, ptr %5, align 4, !tbaa !11
  %42 = load i32, ptr %5, align 4, !tbaa !11
  %43 = load i8, ptr %4, align 1, !tbaa !9, !range !13, !noundef !14
  %44 = trunc i8 %43 to i1
  %45 = zext i1 %44 to i64
  %46 = select i1 %44, i32 16, i32 0
  %47 = or i32 %42, %46
  store volatile i32 %47, ptr inttoptr (i64 1073741952 to ptr), align 4, !tbaa !11
  br label %48

48:                                               ; preds = %39, %34
  %49 = load i16, ptr %3, align 2, !tbaa !5
  %50 = zext i16 %49 to i32
  %51 = and i32 %50, 128
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %62

53:                                               ; preds = %48
  %54 = load volatile i32, ptr inttoptr (i64 1073741952 to ptr), align 4, !tbaa !11
  %55 = and i32 %54, -49153
  store i32 %55, ptr %5, align 4, !tbaa !11
  %56 = load i32, ptr %5, align 4, !tbaa !11
  %57 = load i8, ptr %4, align 1, !tbaa !9, !range !13, !noundef !14
  %58 = trunc i8 %57 to i1
  %59 = zext i1 %58 to i64
  %60 = select i1 %58, i32 16384, i32 0
  %61 = or i32 %56, %60
  store volatile i32 %61, ptr inttoptr (i64 1073741952 to ptr), align 4, !tbaa !11
  br label %62

62:                                               ; preds = %53, %48
  call void @llvm.lifetime.end.p0(i64 4, 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: 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}


; 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: nofree norecurse nounwind uwtable
define dso_local void @syscon_sel_af(i16 noundef zeroext %0, i1 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = zext i16 %0 to i32
  %4 = and i32 %3, 1
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %10, label %5

5:                                                ; preds = %2
  %6 = load volatile i32, ptr inttoptr (i64 1073741952 to ptr), align 128, !tbaa !5
  %7 = and i32 %6, -4
  %8 = zext i1 %1 to i32
  %9 = or disjoint i32 %7, %8
  store volatile i32 %9, ptr inttoptr (i64 1073741952 to ptr), align 128, !tbaa !5
  br label %10

10:                                               ; preds = %5, %2
  %11 = and i32 %3, 2
  %.not12 = icmp eq i32 %11, 0
  br i1 %.not12, label %17, label %12

12:                                               ; preds = %10
  %13 = load volatile i32, ptr inttoptr (i64 1073741952 to ptr), align 128, !tbaa !5
  %14 = and i32 %13, -13
  %15 = select i1 %1, i32 4, i32 0
  %16 = or disjoint i32 %14, %15
  store volatile i32 %16, ptr inttoptr (i64 1073741952 to ptr), align 128, !tbaa !5
  br label %17

17:                                               ; preds = %12, %10
  %18 = and i32 %3, 4
  %.not13 = icmp eq i32 %18, 0
  br i1 %.not13, label %24, label %19

19:                                               ; preds = %17
  %20 = load volatile i32, ptr inttoptr (i64 1073741952 to ptr), align 128, !tbaa !5
  %21 = and i32 %20, -49
  %22 = select i1 %1, i32 16, i32 0
  %23 = or disjoint i32 %21, %22
  store volatile i32 %23, ptr inttoptr (i64 1073741952 to ptr), align 128, !tbaa !5
  br label %24

24:                                               ; preds = %19, %17
  %25 = and i32 %3, 128
  %.not14 = icmp eq i32 %25, 0
  br i1 %.not14, label %31, label %26

26:                                               ; preds = %24
  %27 = load volatile i32, ptr inttoptr (i64 1073741952 to ptr), align 128, !tbaa !5
  %28 = and i32 %27, -49153
  %29 = select i1 %1, i32 16384, i32 0
  %30 = or disjoint i32 %28, %29
  store volatile i32 %30, ptr inttoptr (i64 1073741952 to ptr), align 128, !tbaa !5
  br label %31

31:                                               ; preds = %26, %24
  ret void
}

attributes #0 = { nofree norecurse 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"}


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