; LLVM IR from IOsonata/IOsonata :: ARM/Nordic/nRF52/nRF52840/exemples/BoschAppBoard/src (bmi3)

; 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.bmi3_dev = type { i8, ptr, i8, i32, i8, i8, i8, i16, ptr, ptr, ptr, i16 }
%struct.bmi3_acc_dp_gain_offset = type { i16, i16, i16, i8, i8, i8 }

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @bmi3_get_regs(i8 noundef zeroext, ptr noundef, i16 noundef zeroext, ptr noundef) #2

; 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
define dso_local signext i8 @bmi3_get_acc_dp_off_dgain(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca [12 x i8], align 1
  %7 = alloca i16, align 2
  %8 = alloca i16, align 2
  %9 = alloca i16, align 2
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  %12 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 12, ptr %6) #3
  call void @llvm.memset.p0.i64(ptr align 1 %6, i8 0, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #3
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %108

15:                                               ; preds = %2
  %16 = getelementptr inbounds [12 x i8], ptr %6, i64 0, i64 0
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call signext i8 @bmi3_get_regs(i8 noundef zeroext 96, ptr noundef %16, i16 noundef zeroext 12, ptr noundef %17)
  store i8 %18, ptr %5, align 1, !tbaa !9
  %19 = load i8, ptr %5, align 1, !tbaa !9
  %20 = sext i8 %19 to i32
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %107

22:                                               ; preds = %15
  %23 = getelementptr inbounds [12 x i8], ptr %6, i64 0, i64 1
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = zext i8 %24 to i16
  %26 = zext i16 %25 to i32
  %27 = shl i32 %26, 8
  %28 = getelementptr inbounds [12 x i8], ptr %6, i64 0, i64 0
  %29 = load i8, ptr %28, align 1, !tbaa !9
  %30 = zext i8 %29 to i32
  %31 = or i32 %27, %30
  %32 = trunc i32 %31 to i16
  store i16 %32, ptr %7, align 2, !tbaa !10
  %33 = getelementptr inbounds [12 x i8], ptr %6, i64 0, i64 2
  %34 = load i8, ptr %33, align 1, !tbaa !9
  store i8 %34, ptr %10, align 1, !tbaa !9
  %35 = getelementptr inbounds [12 x i8], ptr %6, i64 0, i64 5
  %36 = load i8, ptr %35, align 1, !tbaa !9
  %37 = zext i8 %36 to i16
  %38 = zext i16 %37 to i32
  %39 = shl i32 %38, 8
  %40 = getelementptr inbounds [12 x i8], ptr %6, i64 0, i64 4
  %41 = load i8, ptr %40, align 1, !tbaa !9
  %42 = zext i8 %41 to i32
  %43 = or i32 %39, %42
  %44 = trunc i32 %43 to i16
  store i16 %44, ptr %8, align 2, !tbaa !10
  %45 = getelementptr inbounds [12 x i8], ptr %6, i64 0, i64 6
  %46 = load i8, ptr %45, align 1, !tbaa !9
  store i8 %46, ptr %11, align 1, !tbaa !9
  %47 = getelementptr inbounds [12 x i8], ptr %6, i64 0, i64 9
  %48 = load i8, ptr %47, align 1, !tbaa !9
  %49 = zext i8 %48 to i16
  %50 = zext i16 %49 to i32
  %51 = shl i32 %50, 8
  %52 = getelementptr inbounds [12 x i8], ptr %6, i64 0, i64 8
  %53 = load i8, ptr %52, align 1, !tbaa !9
  %54 = zext i8 %53 to i32
  %55 = or i32 %51, %54
  %56 = trunc i32 %55 to i16
  store i16 %56, ptr %9, align 2, !tbaa !10
  %57 = getelementptr inbounds [12 x i8], ptr %6, i64 0, i64 10
  %58 = load i8, ptr %57, align 1, !tbaa !9
  store i8 %58, ptr %12, align 1, !tbaa !9
  %59 = load i16, ptr %7, align 2, !tbaa !10
  %60 = zext i16 %59 to i32
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.bmi3_dev, ptr %61, i32 0, i32 11
  %63 = load i16, ptr %62, align 8, !tbaa !12
  %64 = zext i16 %63 to i32
  %65 = and i32 %60, %64
  %66 = trunc i32 %65 to i16
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.bmi3_acc_dp_gain_offset, ptr %67, i32 0, i32 0
  store i16 %66, ptr %68, align 2, !tbaa !15
  %69 = load i8, ptr %10, align 1, !tbaa !9
  %70 = zext i8 %69 to i32
  %71 = and i32 %70, 255
  %72 = trunc i32 %71 to i8
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.bmi3_acc_dp_gain_offset, ptr %73, i32 0, i32 3
  store i8 %72, ptr %74, align 2, !tbaa !17
  %75 = load i16, ptr %8, align 2, !tbaa !10
  %76 = zext i16 %75 to i32
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.bmi3_dev, ptr %77, i32 0, i32 11
  %79 = load i16, ptr %78, align 8, !tbaa !12
  %80 = zext i16 %79 to i32
  %81 = and i32 %76, %80
  %82 = trunc i32 %81 to i16
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.bmi3_acc_dp_gain_offset, ptr %83, i32 0, i32 1
  store i16 %82, ptr %84, align 2, !tbaa !18
  %85 = load i8, ptr %11, align 1, !tbaa !9
  %86 = zext i8 %85 to i32
  %87 = and i32 %86, 255
  %88 = trunc i32 %87 to i8
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.bmi3_acc_dp_gain_offset, ptr %89, i32 0, i32 4
  store i8 %88, ptr %90, align 1, !tbaa !19
  %91 = load i16, ptr %9, align 2, !tbaa !10
  %92 = zext i16 %91 to i32
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.bmi3_dev, ptr %93, i32 0, i32 11
  %95 = load i16, ptr %94, align 8, !tbaa !12
  %96 = zext i16 %95 to i32
  %97 = and i32 %92, %96
  %98 = trunc i32 %97 to i16
  %99 = load ptr, ptr %3, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.bmi3_acc_dp_gain_offset, ptr %99, i32 0, i32 2
  store i16 %98, ptr %100, align 2, !tbaa !20
  %101 = load i8, ptr %12, align 1, !tbaa !9
  %102 = zext i8 %101 to i32
  %103 = and i32 %102, 255
  %104 = trunc i32 %103 to i8
  %105 = load ptr, ptr %3, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.bmi3_acc_dp_gain_offset, ptr %105, i32 0, i32 5
  store i8 %104, ptr %106, align 2, !tbaa !21
  br label %107

107:                                              ; preds = %22, %15
  br label %109

108:                                              ; preds = %2
  store i8 -1, ptr %5, align 1, !tbaa !9
  br label %109

109:                                              ; preds = %108, %107
  %110 = load i8, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  ret i8 %110
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !11, i64 56}
!13 = !{!"bmi3_dev", !7, i64 0, !6, i64 8, !7, i64 16, !14, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !11, i64 28, !6, i64 32, !6, i64 40, !6, i64 48, !11, i64 56}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !11, i64 0}
!16 = !{!"bmi3_acc_dp_gain_offset", !11, i64 0, !11, i64 2, !11, i64 4, !7, i64 6, !7, i64 7, !7, i64 8}
!17 = !{!16, !7, i64 6}
!18 = !{!16, !11, i64 2}
!19 = !{!16, !7, i64 7}
!20 = !{!16, !11, i64 4}
!21 = !{!16, !7, i64 8}


; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @bmi3_get_regs(i8 noundef zeroext, ptr noundef, i16 noundef zeroext, ptr noundef) local_unnamed_addr #2

; 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
define dso_local signext i8 @bmi3_get_acc_dp_off_dgain(ptr noundef writeonly %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca [12 x i8], align 2
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %3) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(12) %3, i8 0, i64 12, i1 false)
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %29, label %4

4:                                                ; preds = %2
  %5 = call signext i8 @bmi3_get_regs(i8 noundef zeroext 96, ptr noundef nonnull %3, i16 noundef zeroext 12, ptr noundef %1)
  %6 = icmp eq i8 %5, 0
  br i1 %6, label %7, label %29

7:                                                ; preds = %4
  %8 = load i16, ptr %3, align 2
  %9 = getelementptr inbounds i8, ptr %3, i64 2
  %10 = load i8, ptr %9, align 2, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %3, i64 4
  %12 = load i16, ptr %11, align 2
  %13 = getelementptr inbounds i8, ptr %3, i64 6
  %14 = load i8, ptr %13, align 2, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %3, i64 8
  %16 = load i16, ptr %15, align 2
  %17 = getelementptr inbounds i8, ptr %3, i64 10
  %18 = load i8, ptr %17, align 2, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %1, i64 56
  %20 = load i16, ptr %19, align 8, !tbaa !8
  %21 = and i16 %20, %8
  store i16 %21, ptr %0, align 2, !tbaa !13
  %22 = getelementptr inbounds i8, ptr %0, i64 6
  store i8 %10, ptr %22, align 2, !tbaa !15
  %23 = and i16 %20, %12
  %24 = getelementptr inbounds i8, ptr %0, i64 2
  store i16 %23, ptr %24, align 2, !tbaa !16
  %25 = getelementptr inbounds i8, ptr %0, i64 7
  store i8 %14, ptr %25, align 1, !tbaa !17
  %26 = and i16 %20, %16
  %27 = getelementptr inbounds i8, ptr %0, i64 4
  store i16 %26, ptr %27, align 2, !tbaa !18
  %28 = getelementptr inbounds i8, ptr %0, i64 8
  store i8 %18, ptr %28, align 2, !tbaa !19
  br label %29

29:                                               ; preds = %2, %4, %7
  %.0 = phi i8 [ 0, %7 ], [ %5, %4 ], [ -1, %2 ]
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %3) #3
  ret i8 %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #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"}
!8 = !{!9, !12, i64 56}
!9 = !{!"bmi3_dev", !6, i64 0, !10, i64 8, !6, i64 16, !11, i64 20, !6, i64 24, !6, i64 25, !6, i64 26, !12, i64 28, !10, i64 32, !10, i64 40, !10, i64 48, !12, i64 56}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!"short", !6, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"bmi3_acc_dp_gain_offset", !12, i64 0, !12, i64 2, !12, i64 4, !6, i64 6, !6, i64 7, !6, i64 8}
!15 = !{!14, !6, i64 6}
!16 = !{!14, !12, i64 2}
!17 = !{!14, !6, i64 7}
!18 = !{!14, !12, i64 4}
!19 = !{!14, !6, i64 8}


; Effective O3 passes: AggressiveInstCombinePass,CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass