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

; 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_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 i64 @_dwt_otpprogword32(i64 noundef %0, i16 noundef zeroext %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i16, align 2
  %6 = alloca [1 x i8], align 1
  %7 = alloca [4 x i8], align 1
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  %10 = getelementptr inbounds [1 x i8], ptr %6, i64 0, i64 0
  call void @dwt_readfromdevice(i16 noundef zeroext 45, i16 noundef zeroext 8, i64 noundef 1, ptr noundef %10)
  %11 = getelementptr inbounds [1 x i8], ptr %6, i64 0, i64 0
  %12 = load i8, ptr %11, align 1, !tbaa !11
  %13 = zext i8 %12 to i32
  %14 = and i32 %13, 2
  %15 = icmp ne i32 %14, 2
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  store i64 -1, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %68

17:                                               ; preds = %2
  %18 = load i64, ptr %4, align 8, !tbaa !5
  %19 = lshr i64 %18, 24
  %20 = and i64 %19, 255
  %21 = trunc i64 %20 to i8
  %22 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 3
  store i8 %21, ptr %22, align 1, !tbaa !11
  %23 = load i64, ptr %4, align 8, !tbaa !5
  %24 = lshr i64 %23, 16
  %25 = and i64 %24, 255
  %26 = trunc i64 %25 to i8
  %27 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 2
  store i8 %26, ptr %27, align 1, !tbaa !11
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = lshr i64 %28, 8
  %30 = and i64 %29, 255
  %31 = trunc i64 %30 to i8
  %32 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 1
  store i8 %31, ptr %32, align 1, !tbaa !11
  %33 = load i64, ptr %4, align 8, !tbaa !5
  %34 = and i64 %33, 255
  %35 = trunc i64 %34 to i8
  %36 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  store i8 %35, ptr %36, align 1, !tbaa !11
  %37 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  call void @dwt_writetodevice(i16 noundef zeroext 45, i16 noundef zeroext 0, i64 noundef 4, ptr noundef %37)
  %38 = load i16, ptr %5, align 2, !tbaa !9
  %39 = zext i16 %38 to i32
  %40 = ashr i32 %39, 8
  %41 = and i32 %40, 7
  %42 = trunc i32 %41 to i8
  %43 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 1
  store i8 %42, ptr %43, align 1, !tbaa !11
  %44 = load i16, ptr %5, align 2, !tbaa !9
  %45 = zext i16 %44 to i32
  %46 = and i32 %45, 255
  %47 = trunc i32 %46 to i8
  %48 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  store i8 %47, ptr %48, align 1, !tbaa !11
  %49 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  call void @dwt_writetodevice(i16 noundef zeroext 45, i16 noundef zeroext 4, i64 noundef 2, ptr noundef %49)
  %50 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  store i8 64, ptr %50, align 1, !tbaa !11
  %51 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  call void @dwt_writetodevice(i16 noundef zeroext 45, i16 noundef zeroext 6, i64 noundef 1, ptr noundef %51)
  %52 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  store i8 0, ptr %52, align 1, !tbaa !11
  %53 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  call void @dwt_writetodevice(i16 noundef zeroext 45, i16 noundef zeroext 6, i64 noundef 1, ptr noundef %53)
  store i8 0, ptr %8, align 1, !tbaa !11
  br label %54

54:                                               ; preds = %66, %17
  %55 = load i8, ptr %8, align 1, !tbaa !11
  %56 = zext i8 %55 to i32
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %58, label %67

58:                                               ; preds = %54
  call void @deca_sleep(i32 noundef 1)
  %59 = getelementptr inbounds [1 x i8], ptr %6, i64 0, i64 0
  call void @dwt_readfromdevice(i16 noundef zeroext 45, i16 noundef zeroext 8, i64 noundef 1, ptr noundef %59)
  %60 = getelementptr inbounds [1 x i8], ptr %6, i64 0, i64 0
  %61 = load i8, ptr %60, align 1, !tbaa !11
  %62 = zext i8 %61 to i32
  %63 = and i32 %62, 1
  %64 = icmp eq i32 %63, 1
  br i1 %64, label %65, label %66

65:                                               ; preds = %58
  store i8 1, ptr %8, align 1, !tbaa !11
  br label %66

66:                                               ; preds = %65, %58
  br label %54, !llvm.loop !12

67:                                               ; preds = %54
  store i64 0, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %68

68:                                               ; preds = %67, %16
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  %69 = load i64, ptr %3, align 8
  ret i64 %69
}

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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !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_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 range(i64 -1, 1) i64 @_dwt_otpprogword32(i64 noundef %0, i16 noundef zeroext %1) local_unnamed_addr #1 {
  %3 = alloca [1 x i8], align 1
  %4 = alloca [4 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  call void @dwt_readfromdevice(i16 noundef zeroext 45, i16 noundef zeroext 8, i64 noundef 1, ptr noundef nonnull %3)
  %5 = load i8, ptr %3, align 1, !tbaa !5
  %6 = and i8 %5, 2
  %.not.not = icmp eq i8 %6, 0
  br i1 %.not.not, label %.loopexit, label %.critedge

.critedge:                                        ; preds = %2
  %7 = lshr i64 %0, 24
  %8 = trunc i64 %7 to i8
  %9 = getelementptr inbounds i8, ptr %4, i64 3
  store i8 %8, ptr %9, align 1, !tbaa !5
  %10 = lshr i64 %0, 16
  %11 = trunc i64 %10 to i8
  %12 = getelementptr inbounds i8, ptr %4, i64 2
  store i8 %11, ptr %12, align 1, !tbaa !5
  %13 = lshr i64 %0, 8
  %14 = trunc i64 %13 to i8
  %15 = getelementptr inbounds i8, ptr %4, i64 1
  store i8 %14, ptr %15, align 1, !tbaa !5
  %16 = trunc i64 %0 to i8
  store i8 %16, ptr %4, align 1, !tbaa !5
  call void @dwt_writetodevice(i16 noundef zeroext 45, i16 noundef zeroext 0, i64 noundef 4, ptr noundef nonnull %4)
  %17 = lshr i16 %1, 8
  %18 = trunc nuw i16 %17 to i8
  %19 = and i8 %18, 7
  store i8 %19, ptr %15, align 1, !tbaa !5
  %20 = trunc i16 %1 to i8
  store i8 %20, ptr %4, align 1, !tbaa !5
  call void @dwt_writetodevice(i16 noundef zeroext 45, i16 noundef zeroext 4, i64 noundef 2, ptr noundef nonnull %4)
  store i8 64, ptr %4, align 1, !tbaa !5
  call void @dwt_writetodevice(i16 noundef zeroext 45, i16 noundef zeroext 6, i64 noundef 1, ptr noundef nonnull %4)
  store i8 0, ptr %4, align 1, !tbaa !5
  call void @dwt_writetodevice(i16 noundef zeroext 45, i16 noundef zeroext 6, i64 noundef 1, ptr noundef nonnull %4)
  br label %select.unfold

select.unfold:                                    ; preds = %.critedge, %select.unfold
  call void @deca_sleep(i32 noundef 1) #3
  call void @dwt_readfromdevice(i16 noundef zeroext 45, i16 noundef zeroext 8, i64 noundef 1, ptr noundef nonnull %3)
  %21 = load i8, ptr %3, align 1, !tbaa !5
  %22 = and i8 %21, 1
  %.not = icmp eq i8 %22, 0
  br i1 %.not, label %select.unfold, label %.loopexit

.loopexit:                                        ; preds = %select.unfold, %2
  %.08 = phi i64 [ -1, %2 ], [ 0, %select.unfold ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  ret i64 %.08
}

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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass