; LLVM IR from PetoiCamp/OpenCatEsp32 :: src/icm42670 (inv_imu_driver)

; 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.inv_imu_interrupt_parameter_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

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

declare i32 @inv_imu_read_reg(ptr noundef, i32 noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @inv_imu_get_config_int1(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = 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 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = call i32 @inv_imu_read_reg(ptr noundef %7, i32 noundef 65579, i32 noundef 1, ptr noundef %6)
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = or i32 %9, %8
  store i32 %10, ptr %5, align 4, !tbaa !9
  %11 = load i8, ptr %6, align 1, !tbaa !11
  %12 = zext i8 %11 to i32
  %13 = and i32 %12, 64
  %14 = ashr i32 %13, 6
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.inv_imu_interrupt_parameter_t, ptr %15, i32 0, i32 0
  store i32 %14, ptr %16, align 4, !tbaa !12
  %17 = load i8, ptr %6, align 1, !tbaa !11
  %18 = zext i8 %17 to i32
  %19 = and i32 %18, 8
  %20 = ashr i32 %19, 3
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.inv_imu_interrupt_parameter_t, ptr %21, i32 0, i32 1
  store i32 %20, ptr %22, align 4, !tbaa !14
  %23 = load i8, ptr %6, align 1, !tbaa !11
  %24 = zext i8 %23 to i32
  %25 = and i32 %24, 4
  %26 = ashr i32 %25, 2
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.inv_imu_interrupt_parameter_t, ptr %27, i32 0, i32 2
  store i32 %26, ptr %28, align 4, !tbaa !15
  %29 = load i8, ptr %6, align 1, !tbaa !11
  %30 = zext i8 %29 to i32
  %31 = and i32 %30, 2
  %32 = ashr i32 %31, 1
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.inv_imu_interrupt_parameter_t, ptr %33, i32 0, i32 3
  store i32 %32, ptr %34, align 4, !tbaa !16
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = call i32 @inv_imu_read_reg(ptr noundef %35, i32 noundef 65580, i32 noundef 1, ptr noundef %6)
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = or i32 %37, %36
  store i32 %38, ptr %5, align 4, !tbaa !9
  %39 = load i8, ptr %6, align 1, !tbaa !11
  %40 = zext i8 %39 to i32
  %41 = and i32 %40, 8
  %42 = ashr i32 %41, 3
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.inv_imu_interrupt_parameter_t, ptr %43, i32 0, i32 4
  store i32 %42, ptr %44, align 4, !tbaa !17
  %45 = load i8, ptr %6, align 1, !tbaa !11
  %46 = zext i8 %45 to i32
  %47 = and i32 %46, 1
  %48 = ashr i32 %47, 0
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.inv_imu_interrupt_parameter_t, ptr %49, i32 0, i32 5
  store i32 %48, ptr %50, align 4, !tbaa !18
  %51 = load i8, ptr %6, align 1, !tbaa !11
  %52 = zext i8 %51 to i32
  %53 = and i32 %52, 2
  %54 = ashr i32 %53, 1
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.inv_imu_interrupt_parameter_t, ptr %55, i32 0, i32 6
  store i32 %54, ptr %56, align 4, !tbaa !19
  %57 = load i8, ptr %6, align 1, !tbaa !11
  %58 = zext i8 %57 to i32
  %59 = and i32 %58, 4
  %60 = ashr i32 %59, 2
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.inv_imu_interrupt_parameter_t, ptr %61, i32 0, i32 7
  store i32 %60, ptr %62, align 4, !tbaa !20
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = call i32 @inv_imu_read_reg(ptr noundef %63, i32 noundef 47, i32 noundef 1, ptr noundef %6)
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = or i32 %65, %64
  store i32 %66, ptr %5, align 4, !tbaa !9
  %67 = load i8, ptr %6, align 1, !tbaa !11
  %68 = zext i8 %67 to i32
  %69 = and i32 %68, 128
  %70 = ashr i32 %69, 7
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.inv_imu_interrupt_parameter_t, ptr %71, i32 0, i32 8
  store i32 %70, ptr %72, align 4, !tbaa !21
  %73 = load i8, ptr %6, align 1, !tbaa !11
  %74 = zext i8 %73 to i32
  %75 = and i32 %74, 64
  %76 = ashr i32 %75, 6
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.inv_imu_interrupt_parameter_t, ptr %77, i32 0, i32 9
  store i32 %76, ptr %78, align 4, !tbaa !22
  %79 = load i8, ptr %6, align 1, !tbaa !11
  %80 = zext i8 %79 to i32
  %81 = and i32 %80, 32
  %82 = ashr i32 %81, 5
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.inv_imu_interrupt_parameter_t, ptr %83, i32 0, i32 10
  store i32 %82, ptr %84, align 4, !tbaa !23
  %85 = load i8, ptr %6, align 1, !tbaa !11
  %86 = zext i8 %85 to i32
  %87 = and i32 %86, 16
  %88 = ashr i32 %87, 4
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.inv_imu_interrupt_parameter_t, ptr %89, i32 0, i32 11
  store i32 %88, ptr %90, align 4, !tbaa !24
  %91 = load i8, ptr %6, align 1, !tbaa !11
  %92 = zext i8 %91 to i32
  %93 = and i32 %92, 8
  %94 = ashr i32 %93, 3
  %95 = load ptr, ptr %4, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.inv_imu_interrupt_parameter_t, ptr %95, i32 0, i32 12
  store i32 %94, ptr %96, align 4, !tbaa !25
  %97 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %97
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 0}
!13 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48}
!14 = !{!13, !10, i64 4}
!15 = !{!13, !10, i64 8}
!16 = !{!13, !10, i64 12}
!17 = !{!13, !10, i64 16}
!18 = !{!13, !10, i64 20}
!19 = !{!13, !10, i64 24}
!20 = !{!13, !10, i64 28}
!21 = !{!13, !10, i64 32}
!22 = !{!13, !10, i64 36}
!23 = !{!13, !10, i64 40}
!24 = !{!13, !10, i64 44}
!25 = !{!13, !10, i64 48}


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

declare i32 @inv_imu_read_reg(ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @inv_imu_get_config_int1(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #2 {
  %3 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #3
  %4 = call i32 @inv_imu_read_reg(ptr noundef %0, i32 noundef 65579, i32 noundef 1, ptr noundef nonnull %3) #3
  %5 = load i8, ptr %3, align 1, !tbaa !5
  %6 = lshr i8 %5, 6
  %7 = and i8 %6, 1
  %8 = zext nneg i8 %7 to i32
  store i32 %8, ptr %1, align 4, !tbaa !8
  %9 = lshr i8 %5, 3
  %10 = and i8 %9, 1
  %11 = zext nneg i8 %10 to i32
  %12 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 %11, ptr %12, align 4, !tbaa !11
  %13 = lshr i8 %5, 2
  %14 = and i8 %13, 1
  %15 = zext nneg i8 %14 to i32
  %16 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 %15, ptr %16, align 4, !tbaa !12
  %17 = lshr i8 %5, 1
  %18 = and i8 %17, 1
  %19 = zext nneg i8 %18 to i32
  %20 = getelementptr inbounds i8, ptr %1, i64 12
  store i32 %19, ptr %20, align 4, !tbaa !13
  %21 = call i32 @inv_imu_read_reg(ptr noundef %0, i32 noundef 65580, i32 noundef 1, ptr noundef nonnull %3) #3
  %22 = or i32 %21, %4
  %23 = load i8, ptr %3, align 1, !tbaa !5
  %24 = lshr i8 %23, 3
  %25 = getelementptr inbounds i8, ptr %1, i64 16
  %26 = lshr i8 %23, 1
  %27 = lshr i8 %23, 2
  %28 = insertelement <4 x i8> poison, i8 %24, i64 0
  %29 = insertelement <4 x i8> %28, i8 %23, i64 1
  %30 = insertelement <4 x i8> %29, i8 %26, i64 2
  %31 = insertelement <4 x i8> %30, i8 %27, i64 3
  %.mask = and <4 x i8> %31, <i8 1, i8 1, i8 1, i8 1>
  %32 = zext nneg <4 x i8> %.mask to <4 x i32>
  store <4 x i32> %32, ptr %25, align 4, !tbaa !14
  %33 = call i32 @inv_imu_read_reg(ptr noundef %0, i32 noundef 47, i32 noundef 1, ptr noundef nonnull %3) #3
  %34 = or i32 %22, %33
  %35 = load i8, ptr %3, align 1, !tbaa !5
  %36 = lshr i8 %35, 7
  %37 = zext nneg i8 %36 to i32
  %38 = getelementptr inbounds i8, ptr %1, i64 32
  store i32 %37, ptr %38, align 4, !tbaa !15
  %39 = lshr i8 %35, 6
  %40 = and i8 %39, 1
  %41 = zext nneg i8 %40 to i32
  %42 = getelementptr inbounds i8, ptr %1, i64 36
  store i32 %41, ptr %42, align 4, !tbaa !16
  %43 = lshr i8 %35, 5
  %44 = and i8 %43, 1
  %45 = zext nneg i8 %44 to i32
  %46 = getelementptr inbounds i8, ptr %1, i64 40
  store i32 %45, ptr %46, align 4, !tbaa !17
  %47 = lshr i8 %35, 4
  %48 = and i8 %47, 1
  %49 = zext nneg i8 %48 to i32
  %50 = getelementptr inbounds i8, ptr %1, i64 44
  store i32 %49, ptr %50, align 4, !tbaa !18
  %51 = lshr i8 %35, 3
  %52 = and i8 %51, 1
  %53 = zext nneg i8 %52 to i32
  %54 = getelementptr inbounds i8, ptr %1, i64 48
  store i32 %53, ptr %54, align 4, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  ret i32 %34
}

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass