; LLVM IR from cvra/robot-software :: uwb-beacon-firmware/src/decadriver (deca_device)

; 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: nounwind uwtable
declare dso_local void @_dwt_enableclocks(i32 noundef) #1

; 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
declare dso_local void @dwt_writetodevice(i16 noundef zeroext, i16 noundef zeroext, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @dwt_readfromdevice(i16 noundef zeroext, i16 noundef zeroext, i64 noundef, ptr noundef) #1

declare void @deca_sleep(i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i16 @dwt_readtempvbat(i8 noundef zeroext %0) #1 {
  %2 = alloca i8, align 1
  %3 = alloca [2 x i8], align 1
  %4 = alloca i8, align 1
  %5 = alloca i8, align 1
  store i8 %0, ptr %2, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  %6 = getelementptr inbounds [2 x i8], ptr %3, i64 0, i64 0
  store i8 -128, ptr %6, align 1, !tbaa !5
  %7 = getelementptr inbounds [2 x i8], ptr %3, i64 0, i64 0
  call void @dwt_writetodevice(i16 noundef zeroext 40, i16 noundef zeroext 17, i64 noundef 1, ptr noundef %7)
  %8 = getelementptr inbounds [2 x i8], ptr %3, i64 0, i64 0
  store i8 10, ptr %8, align 1, !tbaa !5
  %9 = getelementptr inbounds [2 x i8], ptr %3, i64 0, i64 0
  call void @dwt_writetodevice(i16 noundef zeroext 40, i16 noundef zeroext 18, i64 noundef 1, ptr noundef %9)
  %10 = getelementptr inbounds [2 x i8], ptr %3, i64 0, i64 0
  store i8 15, ptr %10, align 1, !tbaa !5
  %11 = getelementptr inbounds [2 x i8], ptr %3, i64 0, i64 0
  call void @dwt_writetodevice(i16 noundef zeroext 40, i16 noundef zeroext 18, i64 noundef 1, ptr noundef %11)
  %12 = getelementptr inbounds [2 x i8], ptr %3, i64 0, i64 0
  store i8 0, ptr %12, align 1, !tbaa !5
  %13 = getelementptr inbounds [2 x i8], ptr %3, i64 0, i64 0
  call void @dwt_writetodevice(i16 noundef zeroext 42, i16 noundef zeroext 0, i64 noundef 1, ptr noundef %13)
  %14 = getelementptr inbounds [2 x i8], ptr %3, i64 0, i64 0
  store i8 1, ptr %14, align 1, !tbaa !5
  %15 = getelementptr inbounds [2 x i8], ptr %3, i64 0, i64 0
  call void @dwt_writetodevice(i16 noundef zeroext 42, i16 noundef zeroext 0, i64 noundef 1, ptr noundef %15)
  %16 = load i8, ptr %2, align 1, !tbaa !5
  %17 = zext i8 %16 to i32
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %19, label %21

19:                                               ; preds = %1
  call void @deca_sleep(i32 noundef 1)
  %20 = getelementptr inbounds [2 x i8], ptr %3, i64 0, i64 0
  call void @dwt_readfromdevice(i16 noundef zeroext 42, i16 noundef zeroext 3, i64 noundef 2, ptr noundef %20)
  br label %23

21:                                               ; preds = %1
  call void @_dwt_enableclocks(i32 noundef 0)
  %22 = getelementptr inbounds [2 x i8], ptr %3, i64 0, i64 0
  call void @dwt_readfromdevice(i16 noundef zeroext 42, i16 noundef zeroext 3, i64 noundef 2, ptr noundef %22)
  call void @_dwt_enableclocks(i32 noundef 1)
  br label %23

23:                                               ; preds = %21, %19
  %24 = getelementptr inbounds [2 x i8], ptr %3, i64 0, i64 0
  %25 = load i8, ptr %24, align 1, !tbaa !5
  store i8 %25, ptr %4, align 1, !tbaa !5
  %26 = getelementptr inbounds [2 x i8], ptr %3, i64 0, i64 1
  %27 = load i8, ptr %26, align 1, !tbaa !5
  store i8 %27, ptr %5, align 1, !tbaa !5
  %28 = getelementptr inbounds [2 x i8], ptr %3, i64 0, i64 0
  store i8 0, ptr %28, align 1, !tbaa !5
  %29 = getelementptr inbounds [2 x i8], ptr %3, i64 0, i64 0
  call void @dwt_writetodevice(i16 noundef zeroext 42, i16 noundef zeroext 0, i64 noundef 1, ptr noundef %29)
  %30 = load i8, ptr %5, align 1, !tbaa !5
  %31 = zext i8 %30 to i32
  %32 = shl i32 %31, 8
  %33 = load i8, ptr %4, align 1, !tbaa !5
  %34 = zext i8 %33 to i32
  %35 = or i32 %32, %34
  %36 = trunc i32 %35 to i16
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #3
  ret i16 %36
}

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 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local void @_dwt_enableclocks(i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @dwt_writetodevice(i16 noundef zeroext, i16 noundef zeroext, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @dwt_readfromdevice(i16 noundef zeroext, i16 noundef zeroext, i64 noundef, ptr noundef) local_unnamed_addr #1

declare void @deca_sleep(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i16 @dwt_readtempvbat(i8 noundef zeroext %0) local_unnamed_addr #1 {
  %2 = alloca [2 x i8], align 2
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %2) #3
  store i8 -128, ptr %2, align 2, !tbaa !5
  call void @dwt_writetodevice(i16 noundef zeroext 40, i16 noundef zeroext 17, i64 noundef 1, ptr noundef nonnull %2)
  store i8 10, ptr %2, align 2, !tbaa !5
  call void @dwt_writetodevice(i16 noundef zeroext 40, i16 noundef zeroext 18, i64 noundef 1, ptr noundef nonnull %2)
  store i8 15, ptr %2, align 2, !tbaa !5
  call void @dwt_writetodevice(i16 noundef zeroext 40, i16 noundef zeroext 18, i64 noundef 1, ptr noundef nonnull %2)
  store i8 0, ptr %2, align 2, !tbaa !5
  call void @dwt_writetodevice(i16 noundef zeroext 42, i16 noundef zeroext 0, i64 noundef 1, ptr noundef nonnull %2)
  store i8 1, ptr %2, align 2, !tbaa !5
  call void @dwt_writetodevice(i16 noundef zeroext 42, i16 noundef zeroext 0, i64 noundef 1, ptr noundef nonnull %2)
  %3 = icmp eq i8 %0, 1
  br i1 %3, label %4, label %5

4:                                                ; preds = %1
  call void @deca_sleep(i32 noundef 1) #3
  call void @dwt_readfromdevice(i16 noundef zeroext 42, i16 noundef zeroext 3, i64 noundef 2, ptr noundef nonnull %2)
  br label %6

5:                                                ; preds = %1
  call void @_dwt_enableclocks(i32 noundef 0)
  call void @dwt_readfromdevice(i16 noundef zeroext 42, i16 noundef zeroext 3, i64 noundef 2, ptr noundef nonnull %2)
  call void @_dwt_enableclocks(i32 noundef 1)
  br label %6

6:                                                ; preds = %5, %4
  %7 = load i16, ptr %2, align 2
  store i8 0, ptr %2, align 2, !tbaa !5
  call void @dwt_writetodevice(i16 noundef zeroext 42, i16 noundef zeroext 0, i64 noundef 1, ptr noundef nonnull %2)
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %2) #3
  ret i16 %7
}

attributes #0 = { mustprogress 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 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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