; 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: nounwind uwtable
declare dso_local void @dwt_write32bitoffsetreg(i32 noundef, i32 noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @dwt_setdblrxbuffmode(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp ne i32 %3, 0
  br i1 %4, label %5, label %12

5:                                                ; preds = %1
  %6 = load ptr, ptr @pdw1000local, align 8, !tbaa !9
  %7 = getelementptr inbounds %struct.dwt_local_data_t, ptr %6, i32 0, i32 7
  %8 = load i64, ptr %7, align 8, !tbaa !11
  %9 = and i64 %8, -4097
  store i64 %9, ptr %7, align 8, !tbaa !11
  %10 = load ptr, ptr @pdw1000local, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.dwt_local_data_t, ptr %10, i32 0, i32 6
  store i8 1, ptr %11, align 1, !tbaa !16
  br label %19

12:                                               ; preds = %1
  %13 = load ptr, ptr @pdw1000local, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.dwt_local_data_t, ptr %13, i32 0, i32 7
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = or i64 %15, 4096
  store i64 %16, ptr %14, align 8, !tbaa !11
  %17 = load ptr, ptr @pdw1000local, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.dwt_local_data_t, ptr %17, i32 0, i32 6
  store i8 0, ptr %18, align 1, !tbaa !16
  br label %19

19:                                               ; preds = %12, %5
  %20 = load ptr, ptr @pdw1000local, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.dwt_local_data_t, ptr %20, i32 0, i32 7
  %22 = load i64, ptr %21, align 8, !tbaa !11
  call void @dwt_write32bitoffsetreg(i32 noundef 4, i32 noundef 0, i64 noundef %22)
  ret void
}

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

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


; 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 void @dwt_write32bitoffsetreg(i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @dwt_setdblrxbuffmode(i32 noundef %0) local_unnamed_addr #0 {
  %.not = icmp ne i32 %0, 0
  %2 = load ptr, ptr @pdw1000local, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 40
  %4 = load i64, ptr %3, align 8, !tbaa !9
  %5 = getelementptr inbounds i8, ptr %2, i64 33
  %6 = and i64 %4, -4097
  %masksel = select i1 %.not, i64 0, i64 4096
  %.sink1 = or disjoint i64 %6, %masksel
  %.sink = zext i1 %.not to i8
  store i64 %.sink1, ptr %3, align 8, !tbaa !9
  store i8 %.sink, ptr %5, align 1, !tbaa !14
  tail call void @dwt_write32bitoffsetreg(i32 noundef 4, i32 noundef 0, i64 noundef %.sink1)
  ret void
}

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

!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 40}
!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 33}


; Effective O3 passes: BDCEPass,GVNPass,GlobalOptPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass