; LLVM IR from sca-secure-library-sca25519/sca25519 :: libopencm3/lib/usb (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._usbd_driver = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i8, i16 }
%struct._usbd_device = type { ptr, ptr, ptr, i32, ptr, i16, i8, i8, i16, ptr, ptr, ptr, ptr, %struct.usb_control_state, [4 x %struct.user_control_callback], [8 x [3 x ptr]], [4 x ptr], ptr, ptr, i16, i16, [4 x i8], [4 x i32], i16 }
%struct.usb_control_state = type { i32, %struct.usb_setup_data, ptr, i16, ptr, i8 }
%struct.usb_setup_data = type { i8, i8, i16, i16, i16 }
%struct.user_control_callback = type { ptr, i8, i8 }

; Function Attrs: nounwind uwtable
define dso_local ptr @usbd_init(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4, ptr noundef %5, i16 noundef zeroext %6) #0 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i16, align 2
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store i32 %4, ptr %12, align 4, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !5
  store i16 %6, ptr %14, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._usbd_driver, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = call ptr %19()
  store ptr %20, ptr %15, align 8, !tbaa !5
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = load ptr, ptr %15, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._usbd_device, ptr %22, i32 0, i32 18
  store ptr %21, ptr %23, align 8, !tbaa !16
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = load ptr, ptr %15, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._usbd_device, ptr %25, i32 0, i32 0
  store ptr %24, ptr %26, align 8, !tbaa !20
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = load ptr, ptr %15, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._usbd_device, ptr %28, i32 0, i32 1
  store ptr %27, ptr %29, align 8, !tbaa !21
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = load ptr, ptr %15, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._usbd_device, ptr %31, i32 0, i32 2
  store ptr %30, ptr %32, align 8, !tbaa !22
  %33 = load i32, ptr %12, align 4, !tbaa !9
  %34 = load ptr, ptr %15, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._usbd_device, ptr %34, i32 0, i32 3
  store i32 %33, ptr %35, align 8, !tbaa !23
  %36 = load ptr, ptr %13, align 8, !tbaa !5
  %37 = load ptr, ptr %15, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._usbd_device, ptr %37, i32 0, i32 4
  store ptr %36, ptr %38, align 8, !tbaa !24
  %39 = load i16, ptr %14, align 2, !tbaa !11
  %40 = load ptr, ptr %15, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._usbd_device, ptr %40, i32 0, i32 5
  store i16 %39, ptr %41, align 8, !tbaa !25
  %42 = load ptr, ptr %15, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._usbd_device, ptr %42, i32 0, i32 15
  %44 = getelementptr inbounds [8 x [3 x ptr]], ptr %43, i64 0, i64 0
  %45 = getelementptr inbounds [3 x ptr], ptr %44, i64 0, i64 2
  store ptr @_usbd_control_setup, ptr %45, align 8, !tbaa !5
  %46 = load ptr, ptr %15, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._usbd_device, ptr %46, i32 0, i32 15
  %48 = getelementptr inbounds [8 x [3 x ptr]], ptr %47, i64 0, i64 0
  %49 = getelementptr inbounds [3 x ptr], ptr %48, i64 0, i64 1
  store ptr @_usbd_control_out, ptr %49, align 8, !tbaa !5
  %50 = load ptr, ptr %15, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._usbd_device, ptr %50, i32 0, i32 15
  %52 = getelementptr inbounds [8 x [3 x ptr]], ptr %51, i64 0, i64 0
  %53 = getelementptr inbounds [3 x ptr], ptr %52, i64 0, i64 0
  store ptr @_usbd_control_in, ptr %53, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %63, %7
  %55 = load i32, ptr %16, align 4, !tbaa !9
  %56 = icmp slt i32 %55, 4
  br i1 %56, label %57, label %66

57:                                               ; preds = %54
  %58 = load ptr, ptr %15, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._usbd_device, ptr %58, i32 0, i32 16
  %60 = load i32, ptr %16, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [4 x ptr], ptr %59, i64 0, i64 %61
  store ptr null, ptr %62, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %57
  %64 = load i32, ptr %16, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %16, align 4, !tbaa !9
  br label %54, !llvm.loop !26

66:                                               ; preds = %54
  %67 = load ptr, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  ret ptr %67
}

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

declare void @_usbd_control_setup(ptr noundef, i8 noundef zeroext) #2

declare void @_usbd_control_out(ptr noundef, i8 noundef zeroext) #2

declare void @_usbd_control_in(ptr noundef, i8 noundef zeroext) #2

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_usbd_driver", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !10, i64 88, !15, i64 92, !12, i64 94}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!17, !6, i64 424}
!17 = !{!"_usbd_device", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !6, i64 32, !12, i64 40, !7, i64 42, !7, i64 43, !12, i64 44, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !18, i64 80, !7, i64 128, !7, i64 192, !7, i64 384, !6, i64 416, !6, i64 424, !12, i64 432, !12, i64 434, !7, i64 436, !7, i64 440, !12, i64 456}
!18 = !{!"usb_control_state", !10, i64 0, !19, i64 4, !6, i64 16, !12, i64 24, !6, i64 32, !15, i64 40}
!19 = !{!"usb_setup_data", !7, i64 0, !7, i64 1, !12, i64 2, !12, i64 4, !12, i64 6}
!20 = !{!17, !6, i64 0}
!21 = !{!17, !6, i64 8}
!22 = !{!17, !6, i64 16}
!23 = !{!17, !10, i64 24}
!24 = !{!17, !6, i64 32}
!25 = !{!17, !12, i64 40}
!26 = distinct !{!26, !27}
!27 = !{!"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: nounwind uwtable
define dso_local noundef ptr @usbd_init(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4, ptr noundef %5, i16 noundef zeroext %6) local_unnamed_addr #0 {
  %8 = load ptr, ptr %0, align 8, !tbaa !5
  %9 = tail call ptr %8() #3
  %10 = getelementptr inbounds i8, ptr %9, i64 424
  store ptr %0, ptr %10, align 8, !tbaa !13
  store ptr %1, ptr %9, align 8, !tbaa !17
  %11 = getelementptr inbounds i8, ptr %9, i64 8
  store ptr %2, ptr %11, align 8, !tbaa !18
  %12 = getelementptr inbounds i8, ptr %9, i64 16
  store ptr %3, ptr %12, align 8, !tbaa !19
  %13 = getelementptr inbounds i8, ptr %9, i64 24
  store i32 %4, ptr %13, align 8, !tbaa !20
  %14 = getelementptr inbounds i8, ptr %9, i64 32
  store ptr %5, ptr %14, align 8, !tbaa !21
  %15 = getelementptr inbounds i8, ptr %9, i64 40
  store i16 %6, ptr %15, align 8, !tbaa !22
  %16 = getelementptr inbounds i8, ptr %9, i64 192
  %17 = getelementptr inbounds i8, ptr %9, i64 208
  store ptr @_usbd_control_setup, ptr %17, align 8, !tbaa !23
  %18 = getelementptr inbounds i8, ptr %9, i64 200
  store ptr @_usbd_control_out, ptr %18, align 8, !tbaa !23
  store ptr @_usbd_control_in, ptr %16, align 8, !tbaa !23
  %19 = getelementptr inbounds i8, ptr %9, i64 384
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %19, i8 0, i64 32, i1 false), !tbaa !23
  ret ptr %9
}

declare void @_usbd_control_setup(ptr noundef, i8 noundef zeroext) #1

declare void @_usbd_control_out(ptr noundef, i8 noundef zeroext) #1

declare void @_usbd_control_in(ptr noundef, i8 noundef zeroext) #1

; 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_driver", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !10, i64 88, !11, i64 92, !12, i64 94}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!14, !7, i64 424}
!14 = !{!"_usbd_device", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !7, i64 32, !12, i64 40, !8, i64 42, !8, i64 43, !12, i64 44, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !15, i64 80, !8, i64 128, !8, i64 192, !8, i64 384, !7, i64 416, !7, i64 424, !12, i64 432, !12, i64 434, !8, i64 436, !8, i64 440, !12, i64 456}
!15 = !{!"usb_control_state", !10, i64 0, !16, i64 4, !7, i64 16, !12, i64 24, !7, i64 32, !11, i64 40}
!16 = !{!"usb_setup_data", !8, i64 0, !8, i64 1, !12, i64 2, !12, i64 4, !12, i64 6}
!17 = !{!14, !7, i64 0}
!18 = !{!14, !7, i64 8}
!19 = !{!14, !7, i64 16}
!20 = !{!14, !10, i64 24}
!21 = !{!14, !7, i64 32}
!22 = !{!14, !12, i64 40}
!23 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass