; LLVM IR from af-jk/rtos :: src (usart)

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

%struct.USART_t = type { i32, i32, i32, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @USART_init(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @RCC_Enable_USART2_Clk()
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 2, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 3, ptr %6, align 4, !tbaa !9
  %7 = load i32, ptr %5, align 4, !tbaa !9
  call void @GPIO_SetMode(ptr noundef inttoptr (i64 1073872896 to ptr), i32 noundef %7, i32 noundef 2)
  %8 = load i32, ptr %5, align 4, !tbaa !9
  call void @GPIO_SetAF(ptr noundef inttoptr (i64 1073872896 to ptr), i32 noundef %8, i32 noundef 7)
  %9 = load i32, ptr %6, align 4, !tbaa !9
  call void @GPIO_SetMode(ptr noundef inttoptr (i64 1073872896 to ptr), i32 noundef %9, i32 noundef 2)
  %10 = load i32, ptr %6, align 4, !tbaa !9
  call void @GPIO_SetAF(ptr noundef inttoptr (i64 1073872896 to ptr), i32 noundef %10, i32 noundef 7)
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = mul i32 4, %11
  %13 = zext i32 %12 to i64
  %14 = udiv i64 400000000, %13
  %15 = udiv i64 %14, 100
  %16 = shl i64 %15, 4
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = mul i32 4, %17
  %19 = zext i32 %18 to i64
  %20 = udiv i64 400000000, %19
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = mul i32 4, %21
  %23 = zext i32 %22 to i64
  %24 = udiv i64 400000000, %23
  %25 = udiv i64 %24, 100
  %26 = mul i64 %25, 100
  %27 = sub i64 %20, %26
  %28 = mul i64 %27, 16
  %29 = add i64 %28, 50
  %30 = udiv i64 %29, 100
  %31 = and i64 %30, 240
  %32 = add i64 %16, %31
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = mul i32 4, %33
  %35 = zext i32 %34 to i64
  %36 = udiv i64 400000000, %35
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = mul i32 4, %37
  %39 = zext i32 %38 to i64
  %40 = udiv i64 400000000, %39
  %41 = udiv i64 %40, 100
  %42 = mul i64 %41, 100
  %43 = sub i64 %36, %42
  %44 = mul i64 %43, 16
  %45 = add i64 %44, 50
  %46 = udiv i64 %45, 100
  %47 = and i64 %46, 15
  %48 = add i64 %32, %47
  %49 = trunc i64 %48 to i32
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.USART_t, ptr %50, i32 0, i32 2
  store volatile i32 %49, ptr %51, align 4, !tbaa !11
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.USART_t, ptr %52, i32 0, i32 3
  %54 = load volatile i32, ptr %53, align 4, !tbaa !13
  %55 = zext i32 %54 to i64
  %56 = or i64 %55, 8204
  %57 = trunc i64 %56 to i32
  store volatile i32 %57, ptr %53, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

declare void @RCC_Enable_USART2_Clk() #1

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

declare void @GPIO_SetMode(ptr noundef, i32 noundef, i32 noundef) #1

declare void @GPIO_SetAF(ptr noundef, i32 noundef, i32 noundef) #1

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24}
!13 = !{!12, !10, i64 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 void @USART_init(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  tail call void @RCC_Enable_USART2_Clk() #2
  tail call void @GPIO_SetMode(ptr noundef nonnull inttoptr (i64 1073872896 to ptr), i32 noundef 2, i32 noundef 2) #2
  tail call void @GPIO_SetAF(ptr noundef nonnull inttoptr (i64 1073872896 to ptr), i32 noundef 2, i32 noundef 7) #2
  tail call void @GPIO_SetMode(ptr noundef nonnull inttoptr (i64 1073872896 to ptr), i32 noundef 3, i32 noundef 2) #2
  tail call void @GPIO_SetAF(ptr noundef nonnull inttoptr (i64 1073872896 to ptr), i32 noundef 3, i32 noundef 7) #2
  %3 = shl i32 %1, 2
  %4 = udiv i32 400000000, %3
  %5 = zext nneg i32 %4 to i64
  %6 = udiv i32 %4, 100
  %.zext = zext nneg i32 %6 to i64
  %7 = shl nuw nsw i64 %.zext, 4
  %.neg = mul nsw i64 %.zext, -100
  %8 = add nsw i64 %.neg, %5
  %9 = shl nsw i64 %8, 4
  %10 = add nsw i64 %9, 50
  %11 = udiv i64 %10, 100
  %12 = and i64 %11, 240
  %13 = add nuw nsw i64 %12, %7
  %14 = and i64 %11, 15
  %15 = or disjoint i64 %13, %14
  %16 = trunc nuw nsw i64 %15 to i32
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  store volatile i32 %16, ptr %17, align 4, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 12
  %19 = load volatile i32, ptr %18, align 4, !tbaa !10
  %20 = or i32 %19, 8204
  store volatile i32 %20, ptr %18, align 4, !tbaa !10
  ret void
}

declare void @RCC_Enable_USART2_Clk() local_unnamed_addr #1

declare void @GPIO_SetMode(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @GPIO_SetAF(ptr noundef, i32 noundef, i32 noundef) 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, !7, i64 8}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 12}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,TailCallElimPass