; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
define dso_local signext i8 @bmi3_get_regs(i8 noundef zeroext %0, ptr noundef %1, i16 noundef zeroext %2, ptr noundef %3) #1 {
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca [128 x i8], align 16
  %11 = alloca i16, align 2
  store i8 %0, ptr %5, align 1, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !8
  store i16 %2, ptr %7, align 2, !tbaa !10
  store ptr %3, ptr %8, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 128, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #2
  store i16 0, ptr %11, align 2, !tbaa !10
  %12 = load ptr, ptr %8, align 8, !tbaa !8
  %13 = call signext i8 @null_ptr_check(ptr noundef %12)
  store i8 %13, ptr %9, align 1, !tbaa !5
  %14 = load i8, ptr %9, align 1, !tbaa !5
  %15 = sext i8 %14 to i32
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %87

17:                                               ; preds = %4
  %18 = load ptr, ptr %6, align 8, !tbaa !8
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %87

20:                                               ; preds = %17
  %21 = load ptr, ptr %8, align 8, !tbaa !8
  %22 = getelementptr inbounds %struct.bmi3_dev, ptr %21, i32 0, i32 3
  %23 = load i32, ptr %22, align 4, !tbaa !12
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %30

25:                                               ; preds = %20
  %26 = load i8, ptr %5, align 1, !tbaa !5
  %27 = zext i8 %26 to i32
  %28 = or i32 %27, 128
  %29 = trunc i32 %28 to i8
  store i8 %29, ptr %5, align 1, !tbaa !5
  br label %30

30:                                               ; preds = %25, %20
  %31 = load ptr, ptr %8, align 8, !tbaa !8
  %32 = getelementptr inbounds %struct.bmi3_dev, ptr %31, i32 0, i32 8
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = load i8, ptr %5, align 1, !tbaa !5
  %35 = getelementptr inbounds [128 x i8], ptr %10, i64 0, i64 0
  %36 = load i16, ptr %7, align 2, !tbaa !10
  %37 = zext i16 %36 to i32
  %38 = load ptr, ptr %8, align 8, !tbaa !8
  %39 = getelementptr inbounds %struct.bmi3_dev, ptr %38, i32 0, i32 5
  %40 = load i8, ptr %39, align 1, !tbaa !16
  %41 = zext i8 %40 to i32
  %42 = add nsw i32 %37, %41
  %43 = load ptr, ptr %8, align 8, !tbaa !8
  %44 = getelementptr inbounds %struct.bmi3_dev, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  %46 = call signext i8 %33(i8 noundef zeroext %34, ptr noundef %35, i32 noundef %42, ptr noundef %45)
  %47 = load ptr, ptr %8, align 8, !tbaa !8
  %48 = getelementptr inbounds %struct.bmi3_dev, ptr %47, i32 0, i32 4
  store i8 %46, ptr %48, align 8, !tbaa !18
  %49 = load ptr, ptr %8, align 8, !tbaa !8
  %50 = getelementptr inbounds %struct.bmi3_dev, ptr %49, i32 0, i32 10
  %51 = load ptr, ptr %50, align 8, !tbaa !19
  %52 = load ptr, ptr %8, align 8, !tbaa !8
  %53 = getelementptr inbounds %struct.bmi3_dev, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !17
  call void %51(i32 noundef 2, ptr noundef %54)
  %55 = load ptr, ptr %8, align 8, !tbaa !8
  %56 = getelementptr inbounds %struct.bmi3_dev, ptr %55, i32 0, i32 4
  %57 = load i8, ptr %56, align 8, !tbaa !18
  %58 = sext i8 %57 to i32
  %59 = icmp eq i32 %58, 0
  br i1 %59, label %60, label %85

60:                                               ; preds = %30
  br label %61

61:                                               ; preds = %67, %60
  %62 = load i16, ptr %11, align 2, !tbaa !10
  %63 = zext i16 %62 to i32
  %64 = load i16, ptr %7, align 2, !tbaa !10
  %65 = zext i16 %64 to i32
  %66 = icmp slt i32 %63, %65
  br i1 %66, label %67, label %84

67:                                               ; preds = %61
  %68 = load i16, ptr %11, align 2, !tbaa !10
  %69 = zext i16 %68 to i32
  %70 = load ptr, ptr %8, align 8, !tbaa !8
  %71 = getelementptr inbounds %struct.bmi3_dev, ptr %70, i32 0, i32 5
  %72 = load i8, ptr %71, align 1, !tbaa !16
  %73 = zext i8 %72 to i32
  %74 = add nsw i32 %69, %73
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [128 x i8], ptr %10, i64 0, i64 %75
  %77 = load i8, ptr %76, align 1, !tbaa !5
  %78 = load ptr, ptr %6, align 8, !tbaa !8
  %79 = load i16, ptr %11, align 2, !tbaa !10
  %80 = zext i16 %79 to i64
  %81 = getelementptr inbounds i8, ptr %78, i64 %80
  store i8 %77, ptr %81, align 1, !tbaa !5
  %82 = load i16, ptr %11, align 2, !tbaa !10
  %83 = add i16 %82, 1
  store i16 %83, ptr %11, align 2, !tbaa !10
  br label %61, !llvm.loop !20

84:                                               ; preds = %61
  br label %86

85:                                               ; preds = %30
  store i8 -2, ptr %9, align 1, !tbaa !5
  br label %86

86:                                               ; preds = %85, %84
  br label %88

87:                                               ; preds = %17, %4
  store i8 -1, ptr %9, align 1, !tbaa !5
  br label %88

88:                                               ; preds = %87, %86
  %89 = load i8, ptr %9, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 128, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #2
  ret i8 %89
}

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef signext i8 @bmi3_get_regs(i8 noundef zeroext %0, ptr noundef writeonly %1, i16 noundef zeroext %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = alloca [128 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %5) #2
  %6 = tail call signext i8 @null_ptr_check(ptr noundef %3)
  %7 = icmp eq i8 %6, 0
  %8 = icmp ne ptr %1, null
  %or.cond = and i1 %8, %7
  br i1 %or.cond, label %9, label %.loopexit

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %3, i64 20
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 0
  %13 = or i8 %0, -128
  %spec.select = select i1 %12, i8 %13, i8 %0
  %14 = getelementptr inbounds i8, ptr %3, i64 32
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = zext i16 %2 to i32
  %17 = getelementptr inbounds i8, ptr %3, i64 25
  %18 = load i8, ptr %17, align 1, !tbaa !13
  %19 = zext i8 %18 to i32
  %20 = add nuw nsw i32 %19, %16
  %21 = getelementptr inbounds i8, ptr %3, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  %23 = call signext i8 %15(i8 noundef zeroext %spec.select, ptr noundef nonnull %5, i32 noundef %20, ptr noundef %22) #2
  %24 = getelementptr inbounds i8, ptr %3, i64 24
  store i8 %23, ptr %24, align 8, !tbaa !15
  %25 = getelementptr inbounds i8, ptr %3, i64 48
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = load ptr, ptr %21, align 8, !tbaa !14
  call void %26(i32 noundef 2, ptr noundef %27) #2
  %28 = load i8, ptr %24, align 8, !tbaa !15
  %29 = icmp eq i8 %28, 0
  br i1 %29, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %9
  %.not = icmp eq i16 %2, 0
  br i1 %.not, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext i16 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %30 = icmp ult i16 %2, 4
  br i1 %30, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 65532
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %31 = load i8, ptr %17, align 1, !tbaa !13
  %32 = zext i8 %31 to i64
  %33 = add nuw nsw i64 %indvars.iv, %32
  %34 = getelementptr inbounds [128 x i8], ptr %5, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !17
  %36 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  store i8 %35, ptr %36, align 1, !tbaa !17
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %37 = load i8, ptr %17, align 1, !tbaa !13
  %38 = zext i8 %37 to i64
  %39 = add nuw nsw i64 %indvars.iv.next, %38
  %40 = getelementptr inbounds [128 x i8], ptr %5, i64 0, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !17
  %42 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next
  store i8 %41, ptr %42, align 1, !tbaa !17
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %43 = load i8, ptr %17, align 1, !tbaa !13
  %44 = zext i8 %43 to i64
  %45 = add nuw nsw i64 %indvars.iv.next.1, %44
  %46 = getelementptr inbounds [128 x i8], ptr %5, i64 0, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !17
  %48 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next.1
  store i8 %47, ptr %48, align 1, !tbaa !17
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %49 = load i8, ptr %17, align 1, !tbaa !13
  %50 = zext i8 %49 to i64
  %51 = add nuw nsw i64 %indvars.iv.next.2, %50
  %52 = getelementptr inbounds [128 x i8], ptr %5, i64 0, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !17
  %54 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next.2
  store i8 %53, ptr %54, align 1, !tbaa !17
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !18

.loopexit.loopexit.unr-lcssa:                     ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %55 = load i8, ptr %17, align 1, !tbaa !13
  %56 = zext i8 %55 to i64
  %57 = add nuw nsw i64 %indvars.iv.epil, %56
  %58 = getelementptr inbounds [128 x i8], ptr %5, i64 0, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !17
  %60 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.epil
  store i8 %59, ptr %60, align 1, !tbaa !17
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.loopexit, label %.lr.ph.epil, !llvm.loop !20

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph.epil, %.preheader, %4, %9
  %.022 = phi i8 [ -2, %9 ], [ -1, %4 ], [ 0, %.preheader ], [ 0, %.lr.ph.epil ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %5) #2
  ret i8 %.022
}

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

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, !10, i64 20}
!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, !9, i64 32}
!13 = !{!6, !7, i64 25}
!14 = !{!6, !9, i64 8}
!15 = !{!6, !7, i64 24}
!16 = !{!6, !9, i64 48}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.unroll.disable"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass