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

; 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"

@clk_speed.first_run = external hidden global i8, align 1

; Function Attrs: nounwind uwtable
define dso_local void @clk_speed(i32 noundef %0, i16 noundef zeroext %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i16, align 2
  %5 = alloca i16, align 2
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i16 %1, ptr %4, align 2, !tbaa !9
  %7 = load i8, ptr @clk_speed.first_run, align 1, !tbaa !11, !range !13, !noundef !14
  %8 = trunc i8 %7 to i1
  br i1 %8, label %9, label %36

9:                                                ; preds = %2
  store i8 0, ptr @clk_speed.first_run, align 1, !tbaa !11
  call void @clk_speed(i32 noundef 0, i16 noundef zeroext 1)
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #2
  store i16 0, ptr %5, align 2, !tbaa !9
  br label %10

10:                                               ; preds = %16, %9
  %11 = load i16, ptr %5, align 2, !tbaa !9
  %12 = zext i16 %11 to i32
  %13 = icmp slt i32 %12, 10000
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #2
  br label %19

15:                                               ; preds = %10
  call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"() #2, !srcloc !15
  br label %16

16:                                               ; preds = %15
  %17 = load i16, ptr %5, align 2, !tbaa !9
  %18 = add i16 %17, 1
  store i16 %18, ptr %5, align 2, !tbaa !9
  br label %10, !llvm.loop !16

19:                                               ; preds = %14
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %27

22:                                               ; preds = %19
  %23 = load i16, ptr %4, align 2, !tbaa !9
  %24 = zext i16 %23 to i32
  %25 = icmp sle i32 %24, 1
  br i1 %25, label %26, label %27

26:                                               ; preds = %22
  br label %60

27:                                               ; preds = %22, %19
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %35

30:                                               ; preds = %27
  %31 = load i16, ptr %4, align 2, !tbaa !9
  %32 = zext i16 %31 to i32
  %33 = icmp eq i32 %32, 2
  br i1 %33, label %34, label %35

34:                                               ; preds = %30
  br label %60

35:                                               ; preds = %30, %27
  br label %36

36:                                               ; preds = %35, %2
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = icmp eq i32 %37, 1
  br i1 %38, label %39, label %42

39:                                               ; preds = %36
  %40 = load volatile i32, ptr inttoptr (i64 1074724872 to ptr), align 4, !tbaa !5
  %41 = or i32 %40, 1
  store volatile i32 %41, ptr inttoptr (i64 1074724872 to ptr), align 4, !tbaa !5
  br label %45

42:                                               ; preds = %36
  %43 = load volatile i32, ptr inttoptr (i64 1074724872 to ptr), align 4, !tbaa !5
  %44 = and i32 %43, -2
  store volatile i32 %44, ptr inttoptr (i64 1074724872 to ptr), align 4, !tbaa !5
  br label %45

45:                                               ; preds = %42, %39
  %46 = load i16, ptr %4, align 2, !tbaa !9
  %47 = zext i16 %46 to i32
  %48 = icmp sle i32 %47, 1
  br i1 %48, label %49, label %52

49:                                               ; preds = %45
  %50 = load volatile i32, ptr inttoptr (i64 1074724864 to ptr), align 4, !tbaa !5
  %51 = or i32 %50, 1
  store volatile i32 %51, ptr inttoptr (i64 1074724864 to ptr), align 4, !tbaa !5
  br label %60

52:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %53 = load volatile i32, ptr inttoptr (i64 1074724864 to ptr), align 4, !tbaa !5
  %54 = and i32 %53, -1024
  store i32 %54, ptr %6, align 4, !tbaa !5
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = load i16, ptr %4, align 2, !tbaa !9
  %57 = zext i16 %56 to i32
  %58 = and i32 %57, 1022
  %59 = or i32 %55, %58
  store volatile i32 %59, ptr inttoptr (i64 1074724864 to ptr), align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %60

60:                                               ; preds = %52, %49, %34, %26
  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 = !{!"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 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{i64 2337}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@clk_speed.first_run = external hidden local_unnamed_addr global i8, align 1

; Function Attrs: nounwind uwtable
define dso_local void @clk_speed(i32 noundef %0, i16 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = load i8, ptr @clk_speed.first_run, align 1, !tbaa !5, !range !9, !noundef !10
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %5, label %14

5:                                                ; preds = %2
  store i8 0, ptr @clk_speed.first_run, align 1, !tbaa !5
  tail call void @clk_speed(i32 noundef 0, i16 noundef zeroext 1)
  br label %9

6:                                                ; preds = %9
  %7 = icmp eq i32 %0, 0
  %8 = icmp ult i16 %1, 2
  %or.cond = and i1 %7, %8
  br i1 %or.cond, label %27, label %11

9:                                                ; preds = %5, %9
  %.016 = phi i16 [ 0, %5 ], [ %10, %9 ]
  tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"() #1, !srcloc !11
  %10 = add nuw nsw i16 %.016, 1
  %exitcond.not = icmp eq i16 %10, 10000
  br i1 %exitcond.not, label %6, label %9, !llvm.loop !12

11:                                               ; preds = %6
  %12 = icmp eq i32 %0, 1
  %13 = icmp eq i16 %1, 2
  %or.cond5 = and i1 %12, %13
  br i1 %or.cond5, label %27, label %14

14:                                               ; preds = %11, %2
  %15 = icmp eq i32 %0, 1
  %16 = load volatile i32, ptr inttoptr (i64 1074724872 to ptr), align 8, !tbaa !14
  %17 = and i32 %16, -2
  %masksel = zext i1 %15 to i32
  %.sink = or disjoint i32 %17, %masksel
  store volatile i32 %.sink, ptr inttoptr (i64 1074724872 to ptr), align 8, !tbaa !14
  %18 = icmp ult i16 %1, 2
  %19 = load volatile i32, ptr inttoptr (i64 1074724864 to ptr), align 65536, !tbaa !14
  br i1 %18, label %20, label %22

20:                                               ; preds = %14
  %21 = or i32 %19, 1
  br label %.sink.split

22:                                               ; preds = %14
  %23 = and i32 %19, -1024
  %24 = and i16 %1, 1022
  %25 = zext nneg i16 %24 to i32
  %26 = or disjoint i32 %23, %25
  br label %.sink.split

.sink.split:                                      ; preds = %20, %22
  %.sink17 = phi i32 [ %26, %22 ], [ %21, %20 ]
  store volatile i32 %.sink17, ptr inttoptr (i64 1074724864 to ptr), align 65536, !tbaa !14
  br label %27

27:                                               ; preds = %.sink.split, %11, %6
  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" }
attributes #1 = { 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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{i64 2337}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass