; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/Drivers/STM32H7xx_HAL_Driver/Src (usb)

; 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.USB_OTG_EPTypeDef = type { i8, i8, i8, i8, i8, i8, i16, i32, ptr, i32, i32, i32 }
%struct.USB_OTG_DeviceTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [15 x i32], i32 }
%struct.USB_OTG_INEndpointTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.USB_OTG_OUTEndpointTypeDef = type { i32, i32, i32, i32, i32, i32, [2 x 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

; Function Attrs: nounwind uwtable
define dso_local i32 @USB_DeactivateEndpoint(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  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) #2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = ptrtoint ptr %7 to i32
  store i32 %8, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %9, i32 0, i32 0
  %11 = load i8, ptr %10, align 8, !tbaa !11
  %12 = zext i8 %11 to i32
  store i32 %12, ptr %6, align 4, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %13, i32 0, i32 1
  %15 = load i8, ptr %14, align 1, !tbaa !14
  %16 = zext i8 %15 to i32
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %18, label %72

18:                                               ; preds = %2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %19, i32 0, i32 0
  %21 = load i8, ptr %20, align 8, !tbaa !11
  %22 = zext i8 %21 to i32
  %23 = and i32 %22, 15
  %24 = zext i32 %23 to i64
  %25 = shl i64 1, %24
  %26 = trunc i64 %25 to i32
  %27 = zext i32 %26 to i64
  %28 = and i64 65535, %27
  %29 = xor i64 %28, -1
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  %32 = add i64 %31, 2048
  %33 = inttoptr i64 %32 to ptr
  %34 = getelementptr inbounds %struct.USB_OTG_DeviceTypeDef, ptr %33, i32 0, i32 15
  %35 = load volatile i32, ptr %34, align 4, !tbaa !15
  %36 = zext i32 %35 to i64
  %37 = and i64 %36, %29
  %38 = trunc i64 %37 to i32
  store volatile i32 %38, ptr %34, align 4, !tbaa !15
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %39, i32 0, i32 0
  %41 = load i8, ptr %40, align 8, !tbaa !11
  %42 = zext i8 %41 to i32
  %43 = and i32 %42, 15
  %44 = zext i32 %43 to i64
  %45 = shl i64 1, %44
  %46 = trunc i64 %45 to i32
  %47 = zext i32 %46 to i64
  %48 = and i64 65535, %47
  %49 = xor i64 %48, -1
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = zext i32 %50 to i64
  %52 = add i64 %51, 2048
  %53 = inttoptr i64 %52 to ptr
  %54 = getelementptr inbounds %struct.USB_OTG_DeviceTypeDef, ptr %53, i32 0, i32 7
  %55 = load volatile i32, ptr %54, align 4, !tbaa !17
  %56 = zext i32 %55 to i64
  %57 = and i64 %56, %49
  %58 = trunc i64 %57 to i32
  store volatile i32 %58, ptr %54, align 4, !tbaa !17
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = zext i32 %59 to i64
  %61 = add i64 %60, 2304
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = zext i32 %62 to i64
  %64 = mul i64 %63, 32
  %65 = add i64 %61, %64
  %66 = inttoptr i64 %65 to ptr
  %67 = getelementptr inbounds %struct.USB_OTG_INEndpointTypeDef, ptr %66, i32 0, i32 0
  %68 = load volatile i32, ptr %67, align 4, !tbaa !18
  %69 = zext i32 %68 to i64
  %70 = and i64 %69, -332171264
  %71 = trunc i64 %70 to i32
  store volatile i32 %71, ptr %67, align 4, !tbaa !18
  br label %128

72:                                               ; preds = %2
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %73, i32 0, i32 0
  %75 = load i8, ptr %74, align 8, !tbaa !11
  %76 = zext i8 %75 to i32
  %77 = and i32 %76, 15
  %78 = zext i32 %77 to i64
  %79 = shl i64 1, %78
  %80 = trunc i64 %79 to i32
  %81 = shl i32 %80, 16
  %82 = zext i32 %81 to i64
  %83 = and i64 4294901760, %82
  %84 = xor i64 %83, -1
  %85 = load i32, ptr %5, align 4, !tbaa !9
  %86 = zext i32 %85 to i64
  %87 = add i64 %86, 2048
  %88 = inttoptr i64 %87 to ptr
  %89 = getelementptr inbounds %struct.USB_OTG_DeviceTypeDef, ptr %88, i32 0, i32 15
  %90 = load volatile i32, ptr %89, align 4, !tbaa !15
  %91 = zext i32 %90 to i64
  %92 = and i64 %91, %84
  %93 = trunc i64 %92 to i32
  store volatile i32 %93, ptr %89, align 4, !tbaa !15
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %94, i32 0, i32 0
  %96 = load i8, ptr %95, align 8, !tbaa !11
  %97 = zext i8 %96 to i32
  %98 = and i32 %97, 15
  %99 = zext i32 %98 to i64
  %100 = shl i64 1, %99
  %101 = trunc i64 %100 to i32
  %102 = shl i32 %101, 16
  %103 = zext i32 %102 to i64
  %104 = and i64 4294901760, %103
  %105 = xor i64 %104, -1
  %106 = load i32, ptr %5, align 4, !tbaa !9
  %107 = zext i32 %106 to i64
  %108 = add i64 %107, 2048
  %109 = inttoptr i64 %108 to ptr
  %110 = getelementptr inbounds %struct.USB_OTG_DeviceTypeDef, ptr %109, i32 0, i32 7
  %111 = load volatile i32, ptr %110, align 4, !tbaa !17
  %112 = zext i32 %111 to i64
  %113 = and i64 %112, %105
  %114 = trunc i64 %113 to i32
  store volatile i32 %114, ptr %110, align 4, !tbaa !17
  %115 = load i32, ptr %5, align 4, !tbaa !9
  %116 = zext i32 %115 to i64
  %117 = add i64 %116, 2816
  %118 = load i32, ptr %6, align 4, !tbaa !9
  %119 = zext i32 %118 to i64
  %120 = mul i64 %119, 32
  %121 = add i64 %117, %120
  %122 = inttoptr i64 %121 to ptr
  %123 = getelementptr inbounds %struct.USB_OTG_OUTEndpointTypeDef, ptr %122, i32 0, i32 0
  %124 = load volatile i32, ptr %123, align 4, !tbaa !20
  %125 = zext i32 %124 to i64
  %126 = and i64 %125, -269256704
  %127 = trunc i64 %126 to i32
  store volatile i32 %127, ptr %123, align 4, !tbaa !20
  br label %128

128:                                              ; preds = %72, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 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 = !{!"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 = !{!12, !7, i64 0}
!12 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !13, i64 6, !10, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !7, i64 1}
!15 = !{!16, !10, i64 60}
!16 = !{!"", !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, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !7, i64 72, !10, i64 132}
!17 = !{!16, !10, i64 28}
!18 = !{!19, !10, i64 0}
!19 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!20 = !{!21, !10, i64 0}
!21 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !7, i64 24}


; 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: nofree norecurse nounwind uwtable
define dso_local noundef i32 @USB_DeactivateEndpoint(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = ptrtoint ptr %0 to i64
  %4 = load i8, ptr %1, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 1
  %6 = load i8, ptr %5, align 1, !tbaa !12
  %7 = icmp eq i8 %6, 1
  %8 = and i8 %4, 15
  %9 = zext nneg i8 %8 to i32
  %10 = and i64 %3, 4294967295
  %11 = add nuw nsw i64 %10, 2048
  %12 = inttoptr i64 %11 to ptr
  %13 = getelementptr inbounds i8, ptr %12, i64 60
  %14 = load volatile i32, ptr %13, align 4, !tbaa !13
  %15 = and i8 %4, 15
  %16 = zext nneg i8 %15 to i32
  %17 = getelementptr inbounds i8, ptr %12, i64 28
  %18 = zext i8 %4 to i64
  %19 = shl nuw nsw i64 %18, 5
  %. = select i1 %7, i32 1, i32 65536
  %.24 = select i1 %7, i64 2304, i64 2816
  %.25 = select i1 %7, i32 -332171264, i32 -269256704
  %20 = shl nuw i32 %., %9
  %21 = xor i32 %20, -1
  %22 = and i32 %14, %21
  store volatile i32 %22, ptr %13, align 4, !tbaa !13
  %23 = shl nuw i32 %., %16
  %24 = xor i32 %23, -1
  %25 = load volatile i32, ptr %17, align 4, !tbaa !15
  %26 = and i32 %25, %24
  store volatile i32 %26, ptr %17, align 4, !tbaa !15
  %27 = add nuw nsw i64 %10, %.24
  %28 = add nuw nsw i64 %27, %19
  %29 = inttoptr i64 %28 to ptr
  %30 = load volatile i32, ptr %29, align 4, !tbaa !16
  %31 = and i32 %30, %.25
  store volatile i32 %31, ptr %29, align 4, !tbaa !16
  ret i32 0
}

attributes #0 = { nofree norecurse 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" }

!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 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !9, i64 6, !10, i64 8, !11, i64 16, !10, i64 24, !10, i64 28, !10, i64 32}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!6, !7, i64 1}
!13 = !{!14, !10, i64 60}
!14 = !{!"", !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, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !7, i64 72, !10, i64 132}
!15 = !{!14, !10, i64 28}
!16 = !{!10, !10, i64 0}


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