; LLVM IR from asllop/AppOS :: core/mem/arch/pc32 (mem_arch)

; 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.idt_entry = type { i16, i16, i8, i8, i16 }
%struct.gdt_reg = type <{ i16, i32 }>

@IDT = external hidden global [256 x %struct.idt_entry], align 16
@IDTR = external hidden global %struct.gdt_reg, align 1

; Function Attrs: nounwind uwtable
define dso_local void @setup_idt() #0 {
  %1 = alloca i32, align 4
  store i32 ptrtoint (ptr @IDT to i32), ptr getelementptr inbounds (%struct.gdt_reg, ptr @IDTR, i32 0, i32 1), align 1, !tbaa !5
  store i16 2047, ptr @IDTR, align 1, !tbaa !11
  call void asm "lidt $0\0A", "=*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype(%struct.gdt_reg) @IDTR) #2, !srcloc !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !13
  br label %2

2:                                                ; preds = %27, %0
  %3 = load i32, ptr %1, align 4, !tbaa !13
  %4 = icmp slt i32 %3, 256
  br i1 %4, label %6, label %5

5:                                                ; preds = %2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %30

6:                                                ; preds = %2
  %7 = load i32, ptr %1, align 4, !tbaa !13
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [256 x %struct.idt_entry], ptr @IDT, i64 0, i64 %8
  %10 = getelementptr inbounds %struct.idt_entry, ptr %9, i32 0, i32 2
  store i8 0, ptr %10, align 4, !tbaa !14
  %11 = load i32, ptr %1, align 4, !tbaa !13
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [256 x %struct.idt_entry], ptr @IDT, i64 0, i64 %12
  %14 = getelementptr inbounds %struct.idt_entry, ptr %13, i32 0, i32 1
  store i16 0, ptr %14, align 2, !tbaa !16
  %15 = load i32, ptr %1, align 4, !tbaa !13
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [256 x %struct.idt_entry], ptr @IDT, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.idt_entry, ptr %17, i32 0, i32 3
  store i8 0, ptr %18, align 1, !tbaa !17
  %19 = load i32, ptr %1, align 4, !tbaa !13
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [256 x %struct.idt_entry], ptr @IDT, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.idt_entry, ptr %21, i32 0, i32 0
  store i16 0, ptr %22, align 8, !tbaa !18
  %23 = load i32, ptr %1, align 4, !tbaa !13
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [256 x %struct.idt_entry], ptr @IDT, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.idt_entry, ptr %25, i32 0, i32 4
  store i16 0, ptr %26, align 2, !tbaa !19
  br label %27

27:                                               ; preds = %6
  %28 = load i32, ptr %1, align 4, !tbaa !13
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %1, align 4, !tbaa !13
  br label %2, !llvm.loop !20

30:                                               ; preds = %5
  ret void
}

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

; 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 = { 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 2}
!6 = !{!"gdt_reg", !7, i64 0, !10, i64 2}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{i64 1278}
!13 = !{!10, !10, i64 0}
!14 = !{!15, !8, i64 4}
!15 = !{!"idt_entry", !7, i64 0, !7, i64 2, !8, i64 4, !8, i64 5, !7, i64 6}
!16 = !{!15, !7, i64 2}
!17 = !{!15, !8, i64 5}
!18 = !{!15, !7, i64 0}
!19 = !{!15, !7, i64 6}
!20 = distinct !{!20, !21}
!21 = !{!"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"

%struct.idt_entry = type { i16, i16, i8, i8, i16 }
%struct.gdt_reg = type <{ i16, i32 }>

@IDT = external hidden global [256 x %struct.idt_entry], align 16
@IDTR = external hidden global %struct.gdt_reg, align 1

; Function Attrs: nounwind uwtable
define dso_local void @setup_idt() local_unnamed_addr #0 {
  store i32 ptrtoint (ptr @IDT to i32), ptr getelementptr inbounds (i8, ptr @IDTR, i64 2), align 1, !tbaa !5
  store i16 2047, ptr @IDTR, align 1, !tbaa !11
  tail call void asm "lidt $0\0A", "=*m,~{dirflag},~{fpsr},~{flags}"(ptr nonnull elementtype(%struct.gdt_reg) @IDTR) #2, !srcloc !12
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(2048) @IDT, i8 0, i64 2048, i1 false), !tbaa !13
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }
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 2}
!6 = !{!"gdt_reg", !7, i64 0, !10, i64 2}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{i64 1278}
!13 = !{!8, !8, i64 0}


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