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

; Function Attrs: nounwind uwtable
define dso_local signext i8 @bmi3_init(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca [2 x i8], align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %4) #3
  call void @llvm.memset.p0.i64(ptr align 1 %4, i8 0, i64 2, i1 false)
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call signext i8 @null_ptr_check(ptr noundef %5)
  store i8 %6, ptr %3, align 1, !tbaa !9
  %7 = load i8, ptr %3, align 1, !tbaa !9
  %8 = sext i8 %7 to i32
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %24

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.bmi3_dev, ptr %11, i32 0, i32 0
  store i8 0, ptr %12, align 8, !tbaa !10
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.bmi3_dev, ptr %13, i32 0, i32 3
  %15 = load i32, ptr %14, align 4, !tbaa !14
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %10
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.bmi3_dev, ptr %18, i32 0, i32 5
  store i8 1, ptr %19, align 1, !tbaa !15
  br label %23

20:                                               ; preds = %10
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.bmi3_dev, ptr %21, i32 0, i32 5
  store i8 2, ptr %22, align 1, !tbaa !15
  br label %23

23:                                               ; preds = %20, %17
  br label %24

24:                                               ; preds = %23, %1
  %25 = load i8, ptr %3, align 1, !tbaa !9
  %26 = sext i8 %25 to i32
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %48

28:                                               ; preds = %24
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = call signext i8 @bmi3_soft_reset(ptr noundef %29)
  store i8 %30, ptr %3, align 1, !tbaa !9
  %31 = load i8, ptr %3, align 1, !tbaa !9
  %32 = sext i8 %31 to i32
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %47

34:                                               ; preds = %28
  %35 = getelementptr inbounds [2 x i8], ptr %4, i64 0, i64 0
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = call signext i8 @bmi3_get_regs(i8 noundef zeroext 0, ptr noundef %35, i16 noundef zeroext 2, ptr noundef %36)
  store i8 %37, ptr %3, align 1, !tbaa !9
  %38 = load i8, ptr %3, align 1, !tbaa !9
  %39 = sext i8 %38 to i32
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %46

41:                                               ; preds = %34
  %42 = getelementptr inbounds [2 x i8], ptr %4, i64 0, i64 0
  %43 = load i8, ptr %42, align 1, !tbaa !9
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.bmi3_dev, ptr %44, i32 0, i32 0
  store i8 %43, ptr %45, align 8, !tbaa !10
  br label %46

46:                                               ; preds = %41, %34
  br label %47

47:                                               ; preds = %46, %28
  br label %48

48:                                               ; preds = %47, %24
  %49 = load i8, ptr %3, align 1, !tbaa !9
  %50 = sext i8 %49 to i32
  %51 = icmp eq i32 %50, 0
  br i1 %51, label %52, label %66

52:                                               ; preds = %48
  %53 = getelementptr inbounds [2 x i8], ptr %4, i64 0, i64 1
  %54 = load i8, ptr %53, align 1, !tbaa !9
  %55 = zext i8 %54 to i32
  %56 = and i32 %55, 240
  %57 = ashr i32 %56, 4
  %58 = icmp eq i32 %57, 1
  br i1 %58, label %59, label %62

59:                                               ; preds = %52
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.bmi3_dev, ptr %60, i32 0, i32 11
  store i16 16383, ptr %61, align 8, !tbaa !16
  br label %65

62:                                               ; preds = %52
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.bmi3_dev, ptr %63, i32 0, i32 11
  store i16 8191, ptr %64, align 8, !tbaa !16
  br label %65

65:                                               ; preds = %62, %59
  br label %66

66:                                               ; preds = %65, %48
  %67 = load i8, ptr %3, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 2, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  ret i8 %67
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare hidden signext i8 @null_ptr_check(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @bmi3_soft_reset(ptr noundef) #0

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

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

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


; 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: nounwind uwtable
define dso_local signext i8 @bmi3_init(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca [2 x i8], align 2
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %2) #2
  store i16 0, ptr %2, align 2
  %3 = tail call signext i8 @null_ptr_check(ptr noundef %0)
  %4 = icmp eq i8 %3, 0
  br i1 %4, label %5, label %.critedge.thread

5:                                                ; preds = %1
  store i8 0, ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 20
  %7 = load i32, ptr %6, align 4, !tbaa !12
  %8 = icmp eq i32 %7, 0
  %spec.select = select i1 %8, i8 1, i8 2
  %9 = getelementptr inbounds i8, ptr %0, i64 25
  store i8 %spec.select, ptr %9, align 1
  %10 = tail call signext i8 @bmi3_soft_reset(ptr noundef nonnull %0)
  %11 = icmp eq i8 %10, 0
  br i1 %11, label %12, label %.critedge.thread

12:                                               ; preds = %5
  %13 = call signext i8 @bmi3_get_regs(i8 noundef zeroext 0, ptr noundef nonnull %2, i16 noundef zeroext 2, ptr noundef nonnull %0)
  %14 = icmp eq i8 %13, 0
  br i1 %14, label %.critedge.thread.sink.split, label %.critedge.thread

.critedge.thread.sink.split:                      ; preds = %12
  %15 = load i8, ptr %2, align 2, !tbaa !13
  store i8 %15, ptr %0, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %2, i64 1
  %17 = load i8, ptr %16, align 1, !tbaa !13
  %.mask = and i8 %17, -16
  %18 = icmp eq i8 %.mask, 16
  %19 = getelementptr inbounds i8, ptr %0, i64 56
  %. = select i1 %18, i16 16383, i16 8191
  store i16 %., ptr %19, align 8, !tbaa !14
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %.critedge.thread.sink.split, %1, %5, %12
  %.016 = phi i8 [ %3, %1 ], [ %10, %5 ], [ %13, %12 ], [ 0, %.critedge.thread.sink.split ]
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %2) #2
  ret i8 %.016
}

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

; Function Attrs: nounwind uwtable
declare hidden signext i8 @null_ptr_check(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @bmi3_soft_reset(ptr noundef) local_unnamed_addr #0

; 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 #0

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

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,SROAPass,SimplifyCFGPass,TailCallElimPass