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

; 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_read_fifo_data(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca [2 x i8], align 1
  %7 = 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 2, ptr %6) #3
  call void @llvm.memset.p0.i64(ptr align 1 %6, i8 0, i64 2, i1 false)
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  store i8 22, ptr %7, align 1, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %65

10:                                               ; preds = %2
  %11 = getelementptr inbounds [2 x i8], ptr %6, i64 0, i64 0
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call signext i8 @bmi3_get_regs(i8 noundef zeroext 54, ptr noundef %11, i16 noundef zeroext 2, ptr noundef %12)
  store i8 %13, ptr %5, align 1, !tbaa !9
  %14 = load i8, ptr %5, align 1, !tbaa !9
  %15 = sext i8 %14 to i32
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %64

17:                                               ; preds = %10
  %18 = getelementptr inbounds [2 x i8], ptr %6, i64 0, i64 0
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = zext i8 %19 to i32
  %21 = getelementptr inbounds [2 x i8], ptr %6, i64 0, i64 1
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = zext i8 %22 to i16
  %24 = zext i16 %23 to i32
  %25 = shl i32 %24, 8
  %26 = or i32 %20, %25
  %27 = and i32 %26, 3840
  %28 = trunc i32 %27 to i16
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.bmi3_fifo_frame, ptr %29, i32 0, i32 2
  store i16 %28, ptr %30, align 2, !tbaa !10
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.bmi3_fifo_frame, ptr %31, i32 0, i32 1
  %33 = load i16, ptr %32, align 8, !tbaa !13
  %34 = zext i16 %33 to i32
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %62

36:                                               ; preds = %17
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.bmi3_dev, ptr %37, i32 0, i32 3
  %39 = load i32, ptr %38, align 4, !tbaa !14
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %46

41:                                               ; preds = %36
  %42 = load i8, ptr %7, align 1, !tbaa !9
  %43 = zext i8 %42 to i32
  %44 = or i32 %43, 128
  %45 = trunc i32 %44 to i8
  store i8 %45, ptr %7, align 1, !tbaa !9
  br label %46

46:                                               ; preds = %41, %36
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.bmi3_dev, ptr %47, i32 0, i32 8
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  %50 = load i8, ptr %7, align 1, !tbaa !9
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.bmi3_fifo_frame, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !18
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.bmi3_fifo_frame, ptr %54, i32 0, i32 1
  %56 = load i16, ptr %55, align 8, !tbaa !13
  %57 = zext i16 %56 to i32
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.bmi3_dev, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !19
  %61 = call signext i8 %49(i8 noundef zeroext %50, ptr noundef %53, i32 noundef %57, ptr noundef %60)
  store i8 %61, ptr %5, align 1, !tbaa !9
  br label %63

62:                                               ; preds = %17
  store i8 -2, ptr %5, align 1, !tbaa !9
  br label %63

63:                                               ; preds = %62, %46
  br label %64

64:                                               ; preds = %63, %10
  br label %66

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

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

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, !12, i64 10}
!11 = !{!"bmi3_fifo_frame", !6, i64 0, !12, i64 8, !12, i64 10, !12, i64 12, !12, i64 14, !12, i64 16, !7, i64 18, !12, i64 20, !12, i64 22}
!12 = !{!"short", !7, i64 0}
!13 = !{!11, !12, i64 8}
!14 = !{!15, !16, i64 20}
!15 = !{!"bmi3_dev", !7, i64 0, !6, i64 8, !7, i64 16, !16, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !12, i64 28, !6, i64 32, !6, i64 40, !6, i64 48, !12, i64 56}
!16 = !{!"int", !7, i64 0}
!17 = !{!15, !6, i64 32}
!18 = !{!11, !6, i64 0}
!19 = !{!15, !6, 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: nounwind uwtable
declare dso_local signext i8 @bmi3_get_regs(i8 noundef zeroext, ptr noundef, i16 noundef zeroext, ptr noundef) local_unnamed_addr #1

; 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_read_fifo_data(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca [2 x i8], align 2
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %3) #2
  store i16 0, ptr %3, align 2
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %27, label %4

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

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %3, i64 1
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = zext i8 %9 to i16
  %11 = shl nuw i16 %10, 8
  %12 = and i16 %11, 3840
  %13 = getelementptr inbounds i8, ptr %0, i64 10
  store i16 %12, ptr %13, align 2, !tbaa !8
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load i16, ptr %14, align 8, !tbaa !12
  %.not14 = icmp eq i16 %15, 0
  br i1 %.not14, label %27, label %16

16:                                               ; preds = %7
  %17 = getelementptr inbounds i8, ptr %1, i64 20
  %18 = load i32, ptr %17, align 4, !tbaa !13
  %19 = icmp eq i32 %18, 0
  %spec.select = select i1 %19, i8 -106, i8 22
  %20 = getelementptr inbounds i8, ptr %1, i64 32
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = load ptr, ptr %0, align 8, !tbaa !17
  %23 = zext i16 %15 to i32
  %24 = getelementptr inbounds i8, ptr %1, i64 8
  %25 = load ptr, ptr %24, align 8, !tbaa !18
  %26 = call signext i8 %21(i8 noundef zeroext %spec.select, ptr noundef %22, i32 noundef %23, ptr noundef %25) #2
  br label %27

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

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"}
!8 = !{!9, !11, i64 10}
!9 = !{!"bmi3_fifo_frame", !10, i64 0, !11, i64 8, !11, i64 10, !11, i64 12, !11, i64 14, !11, i64 16, !6, i64 18, !11, i64 20, !11, i64 22}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"short", !6, i64 0}
!12 = !{!9, !11, i64 8}
!13 = !{!14, !15, i64 20}
!14 = !{!"bmi3_dev", !6, i64 0, !10, i64 8, !6, i64 16, !15, i64 20, !6, i64 24, !6, i64 25, !6, i64 26, !11, i64 28, !10, i64 32, !10, i64 40, !10, i64 48, !11, i64 56}
!15 = !{!"int", !6, i64 0}
!16 = !{!14, !10, i64 32}
!17 = !{!9, !10, i64 0}
!18 = !{!14, !10, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass