; LLVM IR from sca-secure-library-sca25519/sca25519 :: libopencm3/lib/usb (usb_msc)

; 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._usbd_mass_storage = type { ptr, i8, i8, i8, i8, ptr, ptr, ptr, i32, ptr, ptr, ptr, ptr, %struct.usb_msc_trans, %struct.sbc_sense_info }
%struct.usb_msc_trans = type { i8, %union.anon, i32, i32, i32, i32, i32, i32, [512 x i8], i8, i8, %union.anon.0 }
%union.anon = type { %struct.usb_msc_cbw }
%struct.usb_msc_cbw = type <{ i32, i32, i32, i8, i8, i8, [16 x i8] }>
%union.anon.0 = type { %struct.usb_msc_csw }
%struct.usb_msc_csw = type <{ i32, i32, i32, i8 }>
%struct.sbc_sense_info = type { i8, i8, i8 }

@_mass_storage = external hidden global %struct._usbd_mass_storage, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @usb_msc_init(ptr noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext %3, i8 noundef zeroext %4, ptr noundef %5, ptr noundef %6, ptr noundef %7, i32 noundef %8, ptr noundef %9, ptr noundef %10) #0 {
  %12 = alloca ptr, align 8
  %13 = alloca i8, align 1
  %14 = alloca i8, align 1
  %15 = alloca i8, align 1
  %16 = alloca i8, align 1
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  %21 = alloca ptr, align 8
  %22 = alloca ptr, align 8
  store ptr %0, ptr %12, align 8, !tbaa !5
  store i8 %1, ptr %13, align 1, !tbaa !9
  store i8 %2, ptr %14, align 1, !tbaa !9
  store i8 %3, ptr %15, align 1, !tbaa !9
  store i8 %4, ptr %16, align 1, !tbaa !9
  store ptr %5, ptr %17, align 8, !tbaa !5
  store ptr %6, ptr %18, align 8, !tbaa !5
  store ptr %7, ptr %19, align 8, !tbaa !5
  store i32 %8, ptr %20, align 4, !tbaa !10
  store ptr %9, ptr %21, align 8, !tbaa !5
  store ptr %10, ptr %22, align 8, !tbaa !5
  %23 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %23, ptr @_mass_storage, align 8, !tbaa !12
  %24 = load i8, ptr %13, align 1, !tbaa !9
  store i8 %24, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 1), align 8, !tbaa !17
  %25 = load i8, ptr %14, align 1, !tbaa !9
  store i8 %25, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 2), align 1, !tbaa !18
  %26 = load i8, ptr %15, align 1, !tbaa !9
  store i8 %26, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 3), align 2, !tbaa !19
  %27 = load i8, ptr %16, align 1, !tbaa !9
  store i8 %27, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 4), align 1, !tbaa !20
  %28 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %28, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 5), align 8, !tbaa !21
  %29 = load ptr, ptr %18, align 8, !tbaa !5
  store ptr %29, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 6), align 8, !tbaa !22
  %30 = load ptr, ptr %19, align 8, !tbaa !5
  store ptr %30, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 7), align 8, !tbaa !23
  %31 = load i32, ptr %20, align 4, !tbaa !10
  %32 = sub i32 %31, 1
  store i32 %32, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 8), align 8, !tbaa !24
  %33 = load ptr, ptr %21, align 8, !tbaa !5
  store ptr %33, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 9), align 8, !tbaa !25
  %34 = load ptr, ptr %22, align 8, !tbaa !5
  store ptr %34, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 10), align 8, !tbaa !26
  store ptr null, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 11), align 8, !tbaa !27
  store ptr null, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 12), align 8, !tbaa !28
  store i32 -1, ptr getelementptr inbounds (%struct.usb_msc_trans, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 13), i32 0, i32 5), align 4, !tbaa !29
  store i32 0, ptr getelementptr inbounds (%struct.usb_msc_trans, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 13), i32 0, i32 6), align 8, !tbaa !30
  store i32 0, ptr getelementptr inbounds (%struct.usb_msc_trans, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 13), i32 0, i32 7), align 4, !tbaa !31
  store i8 0, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 13), align 8, !tbaa !32
  store i32 0, ptr getelementptr inbounds (%struct.usb_msc_trans, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 13), i32 0, i32 2), align 8, !tbaa !33
  store i32 0, ptr getelementptr inbounds (%struct.usb_msc_trans, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 13), i32 0, i32 3), align 4, !tbaa !34
  store i32 0, ptr getelementptr inbounds (%struct.usb_msc_trans, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 13), i32 0, i32 4), align 8, !tbaa !35
  store i8 0, ptr getelementptr inbounds (%struct.usb_msc_trans, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 13), i32 0, i32 9), align 8, !tbaa !36
  store i8 0, ptr getelementptr inbounds (%struct.usb_msc_trans, ptr getelementptr inbounds (%struct._usbd_mass_storage, ptr @_mass_storage, i32 0, i32 13), i32 0, i32 10), align 1, !tbaa !37
  call void @set_sbc_status_good(ptr noundef @_mass_storage)
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = call i32 @usbd_register_set_config_callback(ptr noundef %35, ptr noundef @msc_set_config)
  ret ptr @_mass_storage
}

; Function Attrs: nounwind uwtable
declare hidden void @set_sbc_status_good(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
declare hidden void @msc_set_config(ptr noundef, i16 noundef zeroext) #0

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 = { "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, !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, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"_usbd_mass_storage", !6, i64 0, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !14, i64 80, !16, i64 664}
!14 = !{!"usb_msc_trans", !7, i64 0, !7, i64 1, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !7, i64 56, !15, i64 568, !7, i64 569, !7, i64 570}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!"sbc_sense_info", !7, i64 0, !7, i64 1, !7, i64 2}
!17 = !{!13, !7, i64 8}
!18 = !{!13, !7, i64 9}
!19 = !{!13, !7, i64 10}
!20 = !{!13, !7, i64 11}
!21 = !{!13, !6, i64 16}
!22 = !{!13, !6, i64 24}
!23 = !{!13, !6, i64 32}
!24 = !{!13, !11, i64 40}
!25 = !{!13, !6, i64 48}
!26 = !{!13, !6, i64 56}
!27 = !{!13, !6, i64 64}
!28 = !{!13, !6, i64 72}
!29 = !{!13, !11, i64 124}
!30 = !{!13, !11, i64 128}
!31 = !{!13, !11, i64 132}
!32 = !{!13, !7, i64 80}
!33 = !{!13, !11, i64 112}
!34 = !{!13, !11, i64 116}
!35 = !{!13, !11, i64 120}
!36 = !{!13, !15, i64 648}
!37 = !{!13, !7, i64 649}


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

%struct._usbd_mass_storage = type { ptr, i8, i8, i8, i8, ptr, ptr, ptr, i32, ptr, ptr, ptr, ptr, %struct.usb_msc_trans, %struct.sbc_sense_info }
%struct.usb_msc_trans = type { i8, %union.anon, i32, i32, i32, i32, i32, i32, [512 x i8], i8, i8, %union.anon.0 }
%union.anon = type { %struct.usb_msc_cbw }
%struct.usb_msc_cbw = type <{ i32, i32, i32, i8, i8, i8, [16 x i8] }>
%union.anon.0 = type { %struct.usb_msc_csw }
%struct.usb_msc_csw = type <{ i32, i32, i32, i8 }>
%struct.sbc_sense_info = type { i8, i8, i8 }

@_mass_storage = external hidden global %struct._usbd_mass_storage, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef nonnull ptr @usb_msc_init(ptr noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2, i8 noundef zeroext %3, i8 noundef zeroext %4, ptr noundef %5, ptr noundef %6, ptr noundef %7, i32 noundef %8, ptr noundef %9, ptr noundef %10) local_unnamed_addr #0 {
  store ptr %0, ptr @_mass_storage, align 8, !tbaa !5
  store i8 %1, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 8), align 8, !tbaa !14
  store i8 %2, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 9), align 1, !tbaa !15
  store i8 %3, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 10), align 2, !tbaa !16
  store i8 %4, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 11), align 1, !tbaa !17
  store ptr %5, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 16), align 8, !tbaa !18
  store ptr %6, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 24), align 8, !tbaa !19
  store ptr %7, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 32), align 8, !tbaa !20
  %12 = add i32 %8, -1
  store i32 %12, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 40), align 8, !tbaa !21
  store ptr %9, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 48), align 8, !tbaa !22
  store ptr %10, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 56), align 8, !tbaa !23
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) getelementptr inbounds (i8, ptr @_mass_storage, i64 64), i8 0, i64 16, i1 false)
  store i32 -1, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 124), align 4, !tbaa !24
  store i32 0, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 128), align 8, !tbaa !25
  store i32 0, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 132), align 4, !tbaa !26
  store i8 0, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 80), align 8, !tbaa !27
  store i32 0, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 112), align 8, !tbaa !28
  store i32 0, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 116), align 4, !tbaa !29
  store i32 0, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 120), align 8, !tbaa !30
  store i8 0, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 648), align 8, !tbaa !31
  store i8 0, ptr getelementptr inbounds (i8, ptr @_mass_storage, i64 649), align 1, !tbaa !32
  tail call void @set_sbc_status_good(ptr noundef nonnull @_mass_storage)
  %13 = tail call i32 @usbd_register_set_config_callback(ptr noundef %0, ptr noundef nonnull @msc_set_config) #3
  ret ptr @_mass_storage
}

; Function Attrs: nounwind uwtable
declare hidden void @set_sbc_status_good(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare hidden void @msc_set_config(ptr noundef, i16 noundef zeroext) #0

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

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 = { "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 = { 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, !7, i64 0}
!6 = !{!"_usbd_mass_storage", !7, i64 0, !8, i64 8, !8, i64 9, !8, i64 10, !8, i64 11, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !11, i64 80, !13, i64 664}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"usb_msc_trans", !8, i64 0, !8, i64 1, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !8, i64 56, !12, i64 568, !8, i64 569, !8, i64 570}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!"sbc_sense_info", !8, i64 0, !8, i64 1, !8, i64 2}
!14 = !{!6, !8, i64 8}
!15 = !{!6, !8, i64 9}
!16 = !{!6, !8, i64 10}
!17 = !{!6, !8, i64 11}
!18 = !{!6, !7, i64 16}
!19 = !{!6, !7, i64 24}
!20 = !{!6, !7, i64 32}
!21 = !{!6, !10, i64 40}
!22 = !{!6, !7, i64 48}
!23 = !{!6, !7, i64 56}
!24 = !{!6, !10, i64 124}
!25 = !{!6, !10, i64 128}
!26 = !{!6, !10, i64 132}
!27 = !{!6, !8, i64 80}
!28 = !{!6, !10, i64 112}
!29 = !{!6, !10, i64 116}
!30 = !{!6, !10, i64 120}
!31 = !{!6, !12, i64 648}
!32 = !{!6, !8, i64 649}


; Effective O3 passes: GlobalOptPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass