; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Bus/Ufs (UfsInitCommandUpiu)

; 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.UTP_COMMAND_UPIU = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i16, i32, [16 x i8] }

@.str.10 = external hidden unnamed_addr constant [154 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [51 x i8], align 1

; 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 zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @SwapLittleEndianToBigEndian(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @UfsInitCommandUpiu(ptr noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2, ptr noundef %3, i8 noundef zeroext %4, i32 noundef %5, i32 noundef %6) #2 {
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca i8, align 1
  %11 = alloca ptr, align 8
  %12 = alloca i8, align 1
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i8, align 1
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i8 %1, ptr %9, align 1, !tbaa !9
  store i8 %2, ptr %10, align 1, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !5
  store i8 %4, ptr %12, align 1, !tbaa !9
  store i32 %5, ptr %13, align 4, !tbaa !10
  store i32 %6, ptr %14, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #3
  br label %16

16:                                               ; preds = %7
  %17 = call zeroext i8 @DebugAssertEnabled()
  %18 = icmp ne i8 %17, 0
  br i1 %18, label %19, label %27

19:                                               ; preds = %16
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %25

22:                                               ; preds = %19
  %23 = load ptr, ptr %11, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %26, label %25

25:                                               ; preds = %22, %19
  call void @DebugAssert(ptr noundef @.str.10, i64 noundef 283, ptr noundef @.str.25)
  br label %26

26:                                               ; preds = %25, %22
  br label %27

27:                                               ; preds = %26, %16
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %13, align 4, !tbaa !10
  %31 = icmp eq i32 %30, 2
  br i1 %31, label %32, label %33

32:                                               ; preds = %29
  store i8 65, ptr %15, align 1, !tbaa !9
  br label %39

33:                                               ; preds = %29
  %34 = load i32, ptr %13, align 4, !tbaa !10
  %35 = icmp eq i32 %34, 1
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  store i8 33, ptr %15, align 1, !tbaa !9
  br label %38

37:                                               ; preds = %33
  store i8 1, ptr %15, align 1, !tbaa !9
  br label %38

38:                                               ; preds = %37, %36
  br label %39

39:                                               ; preds = %38, %32
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load i8, ptr %40, align 1
  %42 = and i8 %41, -64
  %43 = or i8 %42, 1
  store i8 %43, ptr %40, align 1
  %44 = load i8, ptr %15, align 1, !tbaa !9
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.UTP_COMMAND_UPIU, ptr %45, i32 0, i32 1
  store i8 %44, ptr %46, align 1, !tbaa !12
  %47 = load i8, ptr %9, align 1, !tbaa !9
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.UTP_COMMAND_UPIU, ptr %48, i32 0, i32 2
  store i8 %47, ptr %49, align 1, !tbaa !15
  %50 = load i8, ptr %10, align 1, !tbaa !9
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.UTP_COMMAND_UPIU, ptr %51, i32 0, i32 3
  store i8 %50, ptr %52, align 1, !tbaa !16
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.UTP_COMMAND_UPIU, ptr %53, i32 0, i32 4
  %55 = load i8, ptr %54, align 1
  %56 = and i8 %55, -16
  %57 = or i8 %56, 0
  store i8 %57, ptr %54, align 1
  call void @SwapLittleEndianToBigEndian(ptr noundef %14, i32 noundef 4)
  %58 = load i32, ptr %14, align 4, !tbaa !10
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.UTP_COMMAND_UPIU, ptr %59, i32 0, i32 11
  store i32 %58, ptr %60, align 1, !tbaa !17
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.UTP_COMMAND_UPIU, ptr %61, i32 0, i32 12
  %63 = getelementptr inbounds [16 x i8], ptr %62, i64 0, i64 0
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  %65 = load i8, ptr %12, align 1, !tbaa !9
  %66 = zext i8 %65 to i64
  %67 = call ptr @CopyMem(ptr noundef %63, ptr noundef %64, i64 noundef %66)
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #3
  ret i64 0
}

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) #1

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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !7, i64 1}
!13 = !{!"", !7, i64 0, !7, i64 0, !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !7, i64 9, !14, i64 10, !11, i64 12, !7, i64 16}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !7, i64 2}
!16 = !{!13, !7, i64 3}
!17 = !{!13, !11, i64 12}


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

@.str.10 = external hidden unnamed_addr constant [154 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [51 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @SwapLittleEndianToBigEndian(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @UfsInitCommandUpiu(ptr noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2, ptr noundef %3, i8 noundef zeroext %4, i32 noundef %5, i32 noundef %6) local_unnamed_addr #1 {
  %8 = alloca i32, align 4
  store i32 %6, ptr %8, align 4, !tbaa !5
  %9 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %9, 0
  br i1 %.not, label %14, label %10

10:                                               ; preds = %7
  %11 = icmp ne ptr %0, null
  %12 = icmp ne ptr %3, null
  %or.cond = and i1 %11, %12
  br i1 %or.cond, label %14, label %13

13:                                               ; preds = %10
  tail call void @DebugAssert(ptr noundef nonnull @.str.10, i64 noundef 283, ptr noundef nonnull @.str.25) #2
  br label %14

14:                                               ; preds = %13, %10, %7
  %switch.selectcmp = icmp eq i32 %5, 1
  %switch.select = select i1 %switch.selectcmp, i8 33, i8 1
  %switch.selectcmp17 = icmp eq i32 %5, 2
  %switch.select18 = select i1 %switch.selectcmp17, i8 65, i8 %switch.select
  %15 = load i8, ptr %0, align 1
  %16 = and i8 %15, -64
  %17 = or disjoint i8 %16, 1
  store i8 %17, ptr %0, align 1
  %18 = getelementptr inbounds i8, ptr %0, i64 1
  store i8 %switch.select18, ptr %18, align 1, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %0, i64 2
  store i8 %1, ptr %19, align 1, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %0, i64 3
  store i8 %2, ptr %20, align 1, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %0, i64 4
  %22 = load i8, ptr %21, align 1
  %23 = and i8 %22, -16
  store i8 %23, ptr %21, align 1
  call void @SwapLittleEndianToBigEndian(ptr noundef nonnull %8, i32 noundef 4)
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %24, ptr %25, align 1, !tbaa !14
  %26 = getelementptr inbounds i8, ptr %0, i64 16
  %27 = zext i8 %4 to i64
  %28 = call ptr @CopyMem(ptr noundef nonnull %26, ptr noundef %3, i64 noundef %27) #2
  ret i64 0
}

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

attributes #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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 1}
!10 = !{!"", !7, i64 0, !7, i64 0, !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !7, i64 9, !11, i64 10, !6, i64 12, !7, i64 16}
!11 = !{!"short", !7, i64 0}
!12 = !{!10, !7, i64 2}
!13 = !{!10, !7, i64 3}
!14 = !{!10, !6, i64 12}


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