; 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: 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_readfromdevice(i16 noundef zeroext, i16 noundef zeroext, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @dwt_readcarrierintegrator() #1 {
  %1 = alloca i64, align 8
  %2 = alloca i32, align 4
  %3 = alloca [3 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  store i64 0, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.start.p0(i64 3, ptr %3) #2
  %4 = getelementptr inbounds [3 x i8], ptr %3, i64 0, i64 0
  call void @dwt_readfromdevice(i16 noundef zeroext 39, i16 noundef zeroext 40, i64 noundef 3, ptr noundef %4)
  store i32 2, ptr %2, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %17, %0
  %6 = load i32, ptr %2, align 4, !tbaa !9
  %7 = icmp sge i32 %6, 0
  br i1 %7, label %8, label %20

8:                                                ; preds = %5
  %9 = load i64, ptr %1, align 8, !tbaa !5
  %10 = shl i64 %9, 8
  %11 = load i32, ptr %2, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [3 x i8], ptr %3, i64 0, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !11
  %15 = zext i8 %14 to i64
  %16 = add i64 %10, %15
  store i64 %16, ptr %1, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %8
  %18 = load i32, ptr %2, align 4, !tbaa !9
  %19 = add nsw i32 %18, -1
  store i32 %19, ptr %2, align 4, !tbaa !9
  br label %5, !llvm.loop !12

20:                                               ; preds = %5
  %21 = load i64, ptr %1, align 8, !tbaa !5
  %22 = and i64 %21, 1048576
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %24, label %27

24:                                               ; preds = %20
  %25 = load i64, ptr %1, align 8, !tbaa !5
  %26 = or i64 %25, 4293918720
  store i64 %26, ptr %1, align 8, !tbaa !5
  br label %30

27:                                               ; preds = %20
  %28 = load i64, ptr %1, align 8, !tbaa !5
  %29 = and i64 %28, 2097151
  store i64 %29, ptr %1, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %27, %24
  %31 = load i64, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 3, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret i64 %31
}

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 = !{!"long", !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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

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

; 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_readfromdevice(i16 noundef zeroext, i16 noundef zeroext, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i64 4293918720, 2097152) i64 @dwt_readcarrierintegrator() local_unnamed_addr #1 {
  %1 = alloca [3 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 3, ptr nonnull %1) #2
  call void @dwt_readfromdevice(i16 noundef zeroext 39, i16 noundef zeroext 40, i64 noundef 3, ptr noundef nonnull %1)
  %2 = getelementptr inbounds i8, ptr %1, i64 2
  %3 = load i8, ptr %2, align 1, !tbaa !5
  %4 = zext i8 %3 to i64
  %5 = getelementptr inbounds i8, ptr %1, i64 1
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = zext i8 %6 to i64
  %8 = shl nuw nsw i64 %4, 16
  %9 = shl nuw nsw i64 %7, 8
  %10 = or disjoint i64 %8, %9
  %11 = load i8, ptr %1, align 1, !tbaa !5
  %12 = zext i8 %11 to i64
  %13 = or disjoint i64 %10, %12
  %14 = and i64 %4, 16
  %.not = icmp eq i64 %14, 0
  %15 = or i64 %13, 4293918720
  %16 = and i64 %13, 1048575
  %.1 = select i1 %.not, i64 %16, i64 %15
  call void @llvm.lifetime.end.p0(i64 3, ptr nonnull %1) #2
  ret i64 %.1
}

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 = { 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: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass