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

%struct.dwt_local_data_t = type { i64, i64, i8, i8, i64, i8, i8, i64, i16, i8, %struct.dwt_cb_data_t, ptr, ptr, ptr, ptr }
%struct.dwt_cb_data_t = type { i64, i16, [2 x i8], i8 }

@pdw1000local = external hidden global ptr, align 8

; 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 zeroext i16 @dwt_read16bitoffsetreg(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) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @dwt_read32bitoffsetreg(i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @dwt_write32bitoffsetreg(i32 noundef, i32 noundef, i64 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @dwt_lowpowerlistenisr() #1 {
  %1 = alloca i64, align 8
  %2 = alloca i16, align 2
  %3 = alloca i16, align 2
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  %4 = call i64 @dwt_read32bitoffsetreg(i32 noundef 15, i32 noundef 0)
  %5 = load ptr, ptr @pdw1000local, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.dwt_local_data_t, ptr %5, i32 0, i32 10
  %7 = getelementptr inbounds %struct.dwt_cb_data_t, ptr %6, i32 0, i32 0
  store i64 %4, ptr %7, align 8, !tbaa !9
  store i64 %4, ptr %1, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 2, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 2, ptr %3) #2
  call void @dwt_setlowpowerlistening(i32 noundef 0)
  call void @dwt_write32bitoffsetreg(i32 noundef 15, i32 noundef 0, i64 noundef 28416)
  %8 = load ptr, ptr @pdw1000local, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.dwt_local_data_t, ptr %8, i32 0, i32 10
  %10 = getelementptr inbounds %struct.dwt_cb_data_t, ptr %9, i32 0, i32 3
  store i8 0, ptr %10, align 4, !tbaa !15
  %11 = call zeroext i16 @dwt_read16bitoffsetreg(i32 noundef 16, i32 noundef 0)
  store i16 %11, ptr %2, align 2, !tbaa !16
  %12 = load i16, ptr %2, align 2, !tbaa !16
  %13 = zext i16 %12 to i64
  %14 = and i64 %13, 1023
  %15 = trunc i64 %14 to i16
  store i16 %15, ptr %3, align 2, !tbaa !16
  %16 = load ptr, ptr @pdw1000local, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.dwt_local_data_t, ptr %16, i32 0, i32 2
  %18 = load i8, ptr %17, align 8, !tbaa !17
  %19 = zext i8 %18 to i32
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %26

21:                                               ; preds = %0
  %22 = load i16, ptr %3, align 2, !tbaa !16
  %23 = zext i16 %22 to i64
  %24 = and i64 %23, 127
  %25 = trunc i64 %24 to i16
  store i16 %25, ptr %3, align 2, !tbaa !16
  br label %26

26:                                               ; preds = %21, %0
  %27 = load i16, ptr %3, align 2, !tbaa !16
  %28 = load ptr, ptr @pdw1000local, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.dwt_local_data_t, ptr %28, i32 0, i32 10
  %30 = getelementptr inbounds %struct.dwt_cb_data_t, ptr %29, i32 0, i32 1
  store i16 %27, ptr %30, align 8, !tbaa !18
  %31 = load i16, ptr %2, align 2, !tbaa !16
  %32 = zext i16 %31 to i64
  %33 = and i64 %32, 32768
  %34 = icmp ne i64 %33, 0
  br i1 %34, label %35, label %43

35:                                               ; preds = %26
  %36 = load ptr, ptr @pdw1000local, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.dwt_local_data_t, ptr %36, i32 0, i32 10
  %38 = getelementptr inbounds %struct.dwt_cb_data_t, ptr %37, i32 0, i32 3
  %39 = load i8, ptr %38, align 4, !tbaa !15
  %40 = zext i8 %39 to i32
  %41 = or i32 %40, 1
  %42 = trunc i32 %41 to i8
  store i8 %42, ptr %38, align 4, !tbaa !15
  br label %43

43:                                               ; preds = %35, %26
  %44 = load ptr, ptr @pdw1000local, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.dwt_local_data_t, ptr %44, i32 0, i32 10
  %46 = getelementptr inbounds %struct.dwt_cb_data_t, ptr %45, i32 0, i32 2
  %47 = getelementptr inbounds [2 x i8], ptr %46, i64 0, i64 0
  call void @dwt_readfromdevice(i16 noundef zeroext 17, i16 noundef zeroext 0, i64 noundef 2, ptr noundef %47)
  %48 = load i64, ptr %1, align 8, !tbaa !14
  %49 = and i64 %48, 8
  %50 = icmp ne i64 %49, 0
  br i1 %50, label %51, label %68

51:                                               ; preds = %43
  %52 = load ptr, ptr @pdw1000local, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.dwt_local_data_t, ptr %52, i32 0, i32 10
  %54 = getelementptr inbounds %struct.dwt_cb_data_t, ptr %53, i32 0, i32 2
  %55 = getelementptr inbounds [2 x i8], ptr %54, i64 0, i64 0
  %56 = load i8, ptr %55, align 2, !tbaa !19
  %57 = zext i8 %56 to i32
  %58 = and i32 %57, 32
  %59 = icmp eq i32 %58, 0
  br i1 %59, label %60, label %68

60:                                               ; preds = %51
  call void @dwt_write32bitoffsetreg(i32 noundef 15, i32 noundef 0, i64 noundef 8)
  %61 = load ptr, ptr @pdw1000local, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.dwt_local_data_t, ptr %61, i32 0, i32 10
  %63 = getelementptr inbounds %struct.dwt_cb_data_t, ptr %62, i32 0, i32 0
  %64 = load i64, ptr %63, align 8, !tbaa !9
  %65 = and i64 %64, -9
  store i64 %65, ptr %63, align 8, !tbaa !9
  %66 = load ptr, ptr @pdw1000local, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.dwt_local_data_t, ptr %66, i32 0, i32 9
  store i8 0, ptr %67, align 2, !tbaa !20
  br label %68

68:                                               ; preds = %60, %51, %43
  %69 = load ptr, ptr @pdw1000local, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.dwt_local_data_t, ptr %69, i32 0, i32 12
  %71 = load ptr, ptr %70, align 8, !tbaa !21
  %72 = icmp ne ptr %71, null
  br i1 %72, label %73, label %79

73:                                               ; preds = %68
  %74 = load ptr, ptr @pdw1000local, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.dwt_local_data_t, ptr %74, i32 0, i32 12
  %76 = load ptr, ptr %75, align 8, !tbaa !21
  %77 = load ptr, ptr @pdw1000local, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.dwt_local_data_t, ptr %77, i32 0, i32 10
  call void %76(ptr noundef %78)
  br label %79

79:                                               ; preds = %73, %68
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret void
}

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

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 = { 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, !11, i64 56}
!10 = !{!"", !11, i64 0, !11, i64 8, !7, i64 16, !7, i64 17, !11, i64 24, !7, i64 32, !7, i64 33, !11, i64 40, !12, i64 48, !7, i64 50, !13, i64 56, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!11 = !{!"long", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!"", !11, i64 0, !12, i64 8, !7, i64 10, !7, i64 12}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !7, i64 68}
!16 = !{!12, !12, i64 0}
!17 = !{!10, !7, i64 16}
!18 = !{!10, !12, i64 64}
!19 = !{!7, !7, i64 0}
!20 = !{!10, !7, i64 50}
!21 = !{!10, !6, i64 80}


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

@pdw1000local = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local zeroext i16 @dwt_read16bitoffsetreg(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @dwt_read32bitoffsetreg(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @dwt_write32bitoffsetreg(i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @dwt_lowpowerlistenisr() local_unnamed_addr #0 {
  %1 = tail call i64 @dwt_read32bitoffsetreg(i32 noundef 15, i32 noundef 0)
  %2 = load ptr, ptr @pdw1000local, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 56
  store i64 %1, ptr %3, align 8, !tbaa !9
  tail call void @dwt_setlowpowerlistening(i32 noundef 0)
  tail call void @dwt_write32bitoffsetreg(i32 noundef 15, i32 noundef 0, i64 noundef 28416)
  %4 = load ptr, ptr @pdw1000local, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 68
  store i8 0, ptr %5, align 4, !tbaa !14
  %6 = tail call zeroext i16 @dwt_read16bitoffsetreg(i32 noundef 16, i32 noundef 0)
  %7 = load ptr, ptr @pdw1000local, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  %9 = load i8, ptr %8, align 8, !tbaa !15
  %10 = icmp eq i8 %9, 0
  %spec.select.v = select i1 %10, i16 127, i16 1023
  %spec.select = and i16 %spec.select.v, %6
  %11 = getelementptr inbounds i8, ptr %7, i64 64
  store i16 %spec.select, ptr %11, align 8, !tbaa !16
  %.not = icmp sgt i16 %6, -1
  br i1 %.not, label %16, label %12

12:                                               ; preds = %0
  %13 = getelementptr inbounds i8, ptr %7, i64 68
  %14 = load i8, ptr %13, align 4, !tbaa !14
  %15 = or i8 %14, 1
  store i8 %15, ptr %13, align 4, !tbaa !14
  br label %16

16:                                               ; preds = %12, %0
  %17 = getelementptr inbounds i8, ptr %7, i64 66
  tail call void @dwt_readfromdevice(i16 noundef zeroext 17, i16 noundef zeroext 0, i64 noundef 2, ptr noundef nonnull %17)
  %18 = and i64 %1, 8
  %.not6 = icmp eq i64 %18, 0
  %.pre = load ptr, ptr @pdw1000local, align 8, !tbaa !5
  br i1 %.not6, label %30, label %19

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %.pre, i64 66
  %21 = load i8, ptr %20, align 2, !tbaa !17
  %22 = and i8 %21, 32
  %23 = icmp eq i8 %22, 0
  br i1 %23, label %24, label %30

24:                                               ; preds = %19
  tail call void @dwt_write32bitoffsetreg(i32 noundef 15, i32 noundef 0, i64 noundef 8)
  %25 = load ptr, ptr @pdw1000local, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 56
  %27 = load i64, ptr %26, align 8, !tbaa !9
  %28 = and i64 %27, -9
  store i64 %28, ptr %26, align 8, !tbaa !9
  %29 = getelementptr inbounds i8, ptr %25, i64 50
  store i8 0, ptr %29, align 2, !tbaa !18
  br label %30

30:                                               ; preds = %24, %19, %16
  %31 = phi ptr [ %25, %24 ], [ %.pre, %19 ], [ %.pre, %16 ]
  %32 = getelementptr inbounds i8, ptr %31, i64 80
  %33 = load ptr, ptr %32, align 8, !tbaa !19
  %.not7 = icmp eq ptr %33, null
  br i1 %.not7, label %36, label %34

34:                                               ; preds = %30
  %35 = getelementptr inbounds i8, ptr %31, i64 56
  tail call void %33(ptr noundef nonnull %35) #1
  br label %36

36:                                               ; preds = %34, %30
  ret void
}

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

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 56}
!10 = !{!"", !11, i64 0, !11, i64 8, !7, i64 16, !7, i64 17, !11, i64 24, !7, i64 32, !7, i64 33, !11, i64 40, !12, i64 48, !7, i64 50, !13, i64 56, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!11 = !{!"long", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!"", !11, i64 0, !12, i64 8, !7, i64 10, !7, i64 12}
!14 = !{!10, !7, i64 68}
!15 = !{!10, !7, i64 16}
!16 = !{!10, !12, i64 64}
!17 = !{!7, !7, i64 0}
!18 = !{!10, !7, i64 50}
!19 = !{!10, !6, i64 80}


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