; LLVM IR from tomoyasuzuki/kvmm :: io (emulate_io_out)

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

; Function Attrs: nounwind uwtable
define dso_local void @emulate_io_out(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.vcpu, ptr %3, i32 0, i32 1
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %6 = getelementptr inbounds %struct.kvm_run, ptr %5, i32 0, i32 9
  %7 = getelementptr inbounds %struct.anon.2, ptr %6, i32 0, i32 2
  %8 = load i16, ptr %7, align 2, !tbaa !18
  %9 = zext i16 %8 to i32
  switch i32 %9, label %36 [
    i32 496, label %10
    i32 497, label %10
    i32 498, label %10
    i32 499, label %10
    i32 500, label %10
    i32 501, label %10
    i32 502, label %10
    i32 503, label %10
    i32 1014, label %12
    i32 1016, label %14
    i32 1017, label %14
    i32 1018, label %14
    i32 1019, label %14
    i32 1020, label %14
    i32 1021, label %14
  ]

10:                                               ; preds = %1, %1, %1, %1, %1, %1, %1, %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  call void @emulate_disk_portw(ptr noundef %11)
  br label %37

12:                                               ; preds = %1
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  call void @emulate_disk_portw(ptr noundef %13)
  br label %37

14:                                               ; preds = %1, %1, %1, %1, %1, %1
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %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
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.vcpu, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.kvm_run, ptr %25, i32 0, i32 9
  %27 = getelementptr inbounds %struct.anon.2, ptr %26, i32 0, i32 3
  %28 = load i32, ptr %27, align 4, !tbaa !18
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.vcpu, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.kvm_run, ptr %31, i32 0, i32 9
  %33 = getelementptr inbounds %struct.anon.2, ptr %32, i32 0, i32 1
  %34 = load i8, ptr %33, align 1, !tbaa !18
  %35 = zext i8 %34 to i32
  call void @emulate_uart_portw(ptr noundef %15, i32 noundef %22, i32 noundef %28, i32 noundef %35)
  br label %37

36:                                               ; preds = %1
  br label %37

37:                                               ; preds = %36, %14, %12, %10
  ret void
}

declare void @emulate_disk_portw(ptr noundef) #1

declare void @emulate_uart_portw(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #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" }

!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}


; 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 void @emulate_io_out(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 34
  %5 = load i16, ptr %4, align 2, !tbaa !17
  switch i16 %5, label %15 [
    i16 496, label %6
    i16 497, label %6
    i16 498, label %6
    i16 499, label %6
    i16 500, label %6
    i16 501, label %6
    i16 502, label %6
    i16 503, label %6
    i16 1014, label %7
    i16 1016, label %8
    i16 1017, label %8
    i16 1018, label %8
    i16 1019, label %8
    i16 1020, label %8
    i16 1021, label %8
  ]

6:                                                ; preds = %1, %1, %1, %1, %1, %1, %1, %1
  tail call void @emulate_disk_portw(ptr noundef nonnull %0) #2
  br label %15

7:                                                ; preds = %1
  tail call void @emulate_disk_portw(ptr noundef nonnull %0) #2
  br label %15

8:                                                ; preds = %1, %1, %1, %1, %1, %1
  %9 = zext nneg i16 %5 to i32
  %10 = getelementptr inbounds i8, ptr %3, i64 36
  %11 = load i32, ptr %10, align 4, !tbaa !17
  %12 = getelementptr inbounds i8, ptr %3, i64 33
  %13 = load i8, ptr %12, align 1, !tbaa !17
  %14 = zext i8 %13 to i32
  tail call void @emulate_uart_portw(ptr noundef nonnull %0, i32 noundef %9, i32 noundef %11, i32 noundef %14) #2
  br label %15

15:                                               ; preds = %1, %8, %7, %6
  ret void
}

declare void @emulate_disk_portw(ptr noundef) local_unnamed_addr #1

declare void @emulate_uart_portw(ptr noundef, i32 noundef, i32 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}


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