; LLVM IR from tomoyasuzuki/kvmm :: blk (emulate_disk_portw)

; 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.vcpu = type { i32, ptr, %struct.kvm_sregs, %struct.kvm_regs }
%struct.kvm_sregs = type { %struct.kvm_segment, %struct.kvm_segment, %struct.kvm_segment, %struct.kvm_segment, %struct.kvm_segment, %struct.kvm_segment, %struct.kvm_segment, %struct.kvm_segment, %struct.kvm_dtable, %struct.kvm_dtable, i64, i64, i64, i64, i64, i64, i64, [4 x i64] }
%struct.kvm_segment = type { i64, i32, i16, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8 }
%struct.kvm_dtable = type { i64, i16, [3 x i16] }
%struct.kvm_regs = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }
%struct.kvm_run = type { i8, i8, [6 x i8], i32, i8, i8, i16, i64, i64, %union.anon, i64, i64, %union.anon.27 }
%union.anon = type { %struct.anon.12 }
%struct.anon.12 = type { [32 x i64] }
%union.anon.27 = type { %struct.kvm_sync_regs, [1528 x i8] }
%struct.kvm_sync_regs = type { %struct.kvm_regs, %struct.kvm_sregs, %struct.kvm_vcpu_events }
%struct.kvm_vcpu_events = type { %struct.anon.28, %struct.anon.29, %struct.anon.30, i32, i32, %struct.anon.31, [27 x i8], i8, i64 }
%struct.anon.28 = type { i8, i8, i8, i8, i32 }
%struct.anon.29 = type { i8, i8, i8, i8 }
%struct.anon.30 = type { i8, i8, i8, i8 }
%struct.anon.31 = type { i8, i8, i8, i8 }
%struct.anon.2 = type { i8, i8, i16, i32, i64 }
%struct.blk = type { ptr, i8, i8, i8, i8, i8, i8, i8, i32, i8 }

@blk = external dso_local global ptr, align 8

; 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
declare dso_local void @emulate_diskw(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @update_blk_index() #1

; Function Attrs: nounwind uwtable
define dso_local void @emulate_disk_portw(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.vcpu, ptr %5, i32 0, i32 1
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.vcpu, ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.kvm_run, ptr %10, i32 0, i32 9
  %12 = getelementptr inbounds %struct.anon.2, ptr %11, i32 0, i32 4
  %13 = load i64, ptr %12, align 8, !tbaa !18
  %14 = getelementptr inbounds i8, ptr %7, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !18
  store i8 %15, ptr %3, align 1, !tbaa !18
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.vcpu, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.kvm_run, ptr %18, i32 0, i32 9
  %20 = getelementptr inbounds %struct.anon.2, ptr %19, i32 0, i32 2
  %21 = load i16, ptr %20, align 2, !tbaa !18
  %22 = zext i16 %21 to i32
  switch i32 %22, label %49 [
    i32 496, label %23
    i32 498, label %25
    i32 499, label %29
    i32 500, label %33
    i32 501, label %37
    i32 502, label %41
    i32 1014, label %45
  ]

23:                                               ; preds = %1
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  call void @emulate_diskw(ptr noundef %24)
  br label %50

25:                                               ; preds = %1
  %26 = load i8, ptr %3, align 1, !tbaa !18
  %27 = load ptr, ptr @blk, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.blk, ptr %27, i32 0, i32 2
  store i8 %26, ptr %28, align 1, !tbaa !19
  br label %50

29:                                               ; preds = %1
  %30 = load i8, ptr %3, align 1, !tbaa !18
  %31 = load ptr, ptr @blk, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.blk, ptr %31, i32 0, i32 3
  store i8 %30, ptr %32, align 2, !tbaa !21
  br label %50

33:                                               ; preds = %1
  %34 = load i8, ptr %3, align 1, !tbaa !18
  %35 = load ptr, ptr @blk, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.blk, ptr %35, i32 0, i32 4
  store i8 %34, ptr %36, align 1, !tbaa !22
  br label %50

37:                                               ; preds = %1
  %38 = load i8, ptr %3, align 1, !tbaa !18
  %39 = load ptr, ptr @blk, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.blk, ptr %39, i32 0, i32 5
  store i8 %38, ptr %40, align 4, !tbaa !23
  br label %41

41:                                               ; preds = %37, %1
  %42 = load i8, ptr %3, align 1, !tbaa !18
  %43 = load ptr, ptr @blk, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.blk, ptr %43, i32 0, i32 6
  store i8 %42, ptr %44, align 1, !tbaa !24
  br label %50

45:                                               ; preds = %1
  %46 = load i8, ptr %3, align 1, !tbaa !18
  %47 = load ptr, ptr @blk, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.blk, ptr %47, i32 0, i32 9
  store i8 %46, ptr %48, align 4, !tbaa !25
  br label %49

49:                                               ; preds = %45, %1
  br label %50

50:                                               ; preds = %49, %41, %33, %29, %25, %23
  call void @update_blk_index()
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.vcpu, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.kvm_run, ptr %53, i32 0, i32 9
  %55 = getelementptr inbounds %struct.anon.2, ptr %54, i32 0, i32 2
  %56 = load i16, ptr %55, align 2, !tbaa !18
  %57 = zext i16 %56 to i32
  %58 = icmp eq i32 %57, 496
  br i1 %58, label %68, label %59

59:                                               ; preds = %50
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.vcpu, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.kvm_run, ptr %62, i32 0, i32 9
  %64 = getelementptr inbounds %struct.anon.2, ptr %63, i32 0, i32 2
  %65 = load i16, ptr %64, align 2, !tbaa !18
  %66 = zext i16 %65 to i32
  %67 = icmp eq i32 %66, 503
  br i1 %67, label %68, label %76

68:                                               ; preds = %59, %50
  %69 = load ptr, ptr @blk, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.blk, ptr %69, i32 0, i32 9
  %71 = load i8, ptr %70, align 4, !tbaa !25
  %72 = zext i8 %71 to i32
  %73 = icmp eq i32 %72, 0
  br i1 %73, label %74, label %76

74:                                               ; preds = %68
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  call void @enq_irr(ptr noundef %75, i32 noundef 46)
  br label %76

76:                                               ; preds = %74, %68, %59
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  ret void
}

declare void @enq_irr(ptr noundef, i32 noundef) #2

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 = { "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, !6, i64 8}
!10 = !{!"vcpu", !11, i64 0, !6, i64 8, !12, i64 16, !17, i64 328}
!11 = !{!"int", !7, i64 0}
!12 = !{!"kvm_sregs", !13, i64 0, !13, i64 24, !13, i64 48, !13, i64 72, !13, i64 96, !13, i64 120, !13, i64 144, !13, i64 168, !16, i64 192, !16, i64 208, !14, i64 224, !14, i64 232, !14, i64 240, !14, i64 248, !14, i64 256, !14, i64 264, !14, i64 272, !7, i64 280}
!13 = !{!"kvm_segment", !14, i64 0, !11, i64 8, !15, i64 12, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 19, !7, i64 20, !7, i64 21, !7, i64 22, !7, i64 23}
!14 = !{!"long long", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!"kvm_dtable", !14, i64 0, !15, i64 8, !7, i64 10}
!17 = !{!"kvm_regs", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !14, i64 72, !14, i64 80, !14, i64 88, !14, i64 96, !14, i64 104, !14, i64 112, !14, i64 120, !14, i64 128, !14, i64 136}
!18 = !{!7, !7, i64 0}
!19 = !{!20, !7, i64 9}
!20 = !{!"blk", !6, i64 0, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !7, i64 12, !7, i64 13, !7, i64 14, !11, i64 16, !7, i64 20}
!21 = !{!20, !7, i64 10}
!22 = !{!20, !7, i64 11}
!23 = !{!20, !7, i64 12}
!24 = !{!20, !7, i64 13}
!25 = !{!20, !7, i64 20}


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

@blk = external dso_local local_unnamed_addr global ptr, align 8

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

; Function Attrs: nounwind uwtable
declare dso_local void @update_blk_index() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @emulate_disk_portw(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 40
  %5 = load i64, ptr %4, align 8, !tbaa !17
  %6 = getelementptr inbounds i8, ptr %3, i64 %5
  %7 = load i8, ptr %6, align 1, !tbaa !17
  %8 = getelementptr inbounds i8, ptr %3, i64 34
  %9 = load i16, ptr %8, align 2, !tbaa !17
  switch i16 %9, label %29 [
    i16 496, label %10
    i16 498, label %11
    i16 499, label %14
    i16 500, label %17
    i16 501, label %20
    i16 502, label %._crit_edge
    i16 1014, label %26
  ]

._crit_edge:                                      ; preds = %1
  %.pre = load ptr, ptr @blk, align 8, !tbaa !18
  br label %23

10:                                               ; preds = %1
  tail call void @emulate_diskw(ptr noundef nonnull %0)
  br label %29

11:                                               ; preds = %1
  %12 = load ptr, ptr @blk, align 8, !tbaa !18
  %13 = getelementptr inbounds i8, ptr %12, i64 9
  store i8 %7, ptr %13, align 1, !tbaa !19
  br label %29

14:                                               ; preds = %1
  %15 = load ptr, ptr @blk, align 8, !tbaa !18
  %16 = getelementptr inbounds i8, ptr %15, i64 10
  store i8 %7, ptr %16, align 2, !tbaa !21
  br label %29

17:                                               ; preds = %1
  %18 = load ptr, ptr @blk, align 8, !tbaa !18
  %19 = getelementptr inbounds i8, ptr %18, i64 11
  store i8 %7, ptr %19, align 1, !tbaa !22
  br label %29

20:                                               ; preds = %1
  %21 = load ptr, ptr @blk, align 8, !tbaa !18
  %22 = getelementptr inbounds i8, ptr %21, i64 12
  store i8 %7, ptr %22, align 4, !tbaa !23
  br label %23

23:                                               ; preds = %._crit_edge, %20
  %24 = phi ptr [ %.pre, %._crit_edge ], [ %21, %20 ]
  %25 = getelementptr inbounds i8, ptr %24, i64 13
  store i8 %7, ptr %25, align 1, !tbaa !24
  br label %29

26:                                               ; preds = %1
  %27 = load ptr, ptr @blk, align 8, !tbaa !18
  %28 = getelementptr inbounds i8, ptr %27, i64 20
  store i8 %7, ptr %28, align 4, !tbaa !25
  br label %29

29:                                               ; preds = %1, %26, %23, %17, %14, %11, %10
  tail call void @update_blk_index()
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 34
  %32 = load i16, ptr %31, align 2, !tbaa !17
  switch i16 %32, label %39 [
    i16 496, label %33
    i16 503, label %33
  ]

33:                                               ; preds = %29, %29
  %34 = load ptr, ptr @blk, align 8, !tbaa !18
  %35 = getelementptr inbounds i8, ptr %34, i64 20
  %36 = load i8, ptr %35, align 4, !tbaa !25
  %37 = icmp eq i8 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %33
  tail call void @enq_irr(ptr noundef nonnull %0, i32 noundef 46) #2
  br label %39

39:                                               ; preds = %29, %38, %33
  ret void
}

declare void @enq_irr(ptr noundef, i32 noundef) local_unnamed_addr #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 = { "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, !10, i64 8}
!6 = !{!"vcpu", !7, i64 0, !10, i64 8, !11, i64 16, !16, i64 328}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"kvm_sregs", !12, i64 0, !12, i64 24, !12, i64 48, !12, i64 72, !12, i64 96, !12, i64 120, !12, i64 144, !12, i64 168, !15, i64 192, !15, i64 208, !13, i64 224, !13, i64 232, !13, i64 240, !13, i64 248, !13, i64 256, !13, i64 264, !13, i64 272, !8, i64 280}
!12 = !{!"kvm_segment", !13, i64 0, !7, i64 8, !14, i64 12, !8, i64 14, !8, i64 15, !8, i64 16, !8, i64 17, !8, i64 18, !8, i64 19, !8, i64 20, !8, i64 21, !8, i64 22, !8, i64 23}
!13 = !{!"long long", !8, i64 0}
!14 = !{!"short", !8, i64 0}
!15 = !{!"kvm_dtable", !13, i64 0, !14, i64 8, !8, i64 10}
!16 = !{!"kvm_regs", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !13, i64 72, !13, i64 80, !13, i64 88, !13, i64 96, !13, i64 104, !13, i64 112, !13, i64 120, !13, i64 128, !13, i64 136}
!17 = !{!8, !8, i64 0}
!18 = !{!10, !10, i64 0}
!19 = !{!20, !8, i64 9}
!20 = !{!"blk", !10, i64 0, !8, i64 8, !8, i64 9, !8, i64 10, !8, i64 11, !8, i64 12, !8, i64 13, !8, i64 14, !7, i64 16, !8, i64 20}
!21 = !{!20, !8, i64 10}
!22 = !{!20, !8, i64 11}
!23 = !{!20, !8, i64 12}
!24 = !{!20, !8, i64 13}
!25 = !{!20, !8, i64 20}


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