; LLVM IR from sca-secure-library-sca25519/sca25519 :: libopencm3/lib/lm4f (uart)

; 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 @uart_set_baudrate(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = add i32 %7, 4040
  %9 = zext i32 %8 to i64
  %10 = inttoptr i64 %9 to ptr
  %11 = load volatile i32, ptr %10, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 5
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  store i32 16000000, ptr %5, align 4, !tbaa !5
  br label %16

14:                                               ; preds = %2
  %15 = call i32 @rcc_get_system_clock_frequency()
  store i32 %15, ptr %5, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %14, %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = mul i32 %17, 8
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = udiv i32 %18, %19
  %21 = add i32 %20, 1
  %22 = udiv i32 %21, 2
  store i32 %22, ptr %6, align 4, !tbaa !5
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = udiv i32 %23, 64
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = add i32 %25, 36
  %27 = zext i32 %26 to i64
  %28 = inttoptr i64 %27 to ptr
  store volatile i32 %24, ptr %28, align 4, !tbaa !5
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = urem i32 %29, 64
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = add i32 %31, 40
  %33 = zext i32 %32 to i64
  %34 = inttoptr i64 %33 to ptr
  store volatile i32 %30, ptr %34, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare i32 @rcc_get_system_clock_frequency() #2

; 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 = { "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 #3 = { 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"}


; 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 @uart_set_baudrate(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = add i32 %0, 4040
  %4 = zext i32 %3 to i64
  %5 = inttoptr i64 %4 to ptr
  %6 = load volatile i32, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 5
  br i1 %7, label %11, label %8

8:                                                ; preds = %2
  %9 = tail call i32 @rcc_get_system_clock_frequency() #2
  %10 = shl i32 %9, 3
  br label %11

11:                                               ; preds = %2, %8
  %.0 = phi i32 [ %10, %8 ], [ 128000000, %2 ]
  %12 = udiv i32 %.0, %1
  %13 = add nuw i32 %12, 1
  %14 = lshr i32 %13, 1
  %15 = lshr i32 %13, 7
  %16 = add i32 %0, 36
  %17 = zext i32 %16 to i64
  %18 = inttoptr i64 %17 to ptr
  store volatile i32 %15, ptr %18, align 4, !tbaa !5
  %19 = and i32 %14, 63
  %20 = add i32 %0, 40
  %21 = zext i32 %20 to i64
  %22 = inttoptr i64 %21 to ptr
  store volatile i32 %19, ptr %22, align 4, !tbaa !5
  ret void
}

declare i32 @rcc_get_system_clock_frequency() local_unnamed_addr #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 = { "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"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass