; LLVM IR from xing1357/SimpleOS :: src (gdt)

; 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.GDT = type { i16, i16, i8, i8, i8, i8 }

@g_gdt = external dso_local global [8 x %struct.GDT], align 16

; Function Attrs: nounwind uwtable
define dso_local void @gdt_set_entry(i32 noundef %0, i32 noundef %1, i32 noundef %2, i8 noundef zeroext %3, i8 noundef zeroext %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca i8, align 1
  %11 = alloca ptr, align 8
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i8 %3, ptr %9, align 1, !tbaa !9
  store i8 %4, ptr %10, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [8 x %struct.GDT], ptr @g_gdt, i64 0, i64 %13
  store ptr %14, ptr %11, align 8, !tbaa !10
  %15 = load i32, ptr %8, align 4, !tbaa !5
  %16 = and i32 %15, 65535
  %17 = trunc i32 %16 to i16
  %18 = load ptr, ptr %11, align 8, !tbaa !10
  %19 = getelementptr inbounds %struct.GDT, ptr %18, i32 0, i32 0
  store i16 %17, ptr %19, align 1, !tbaa !12
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = and i32 %20, 65535
  %22 = trunc i32 %21 to i16
  %23 = load ptr, ptr %11, align 8, !tbaa !10
  %24 = getelementptr inbounds %struct.GDT, ptr %23, i32 0, i32 1
  store i16 %22, ptr %24, align 1, !tbaa !15
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = lshr i32 %25, 16
  %27 = and i32 %26, 255
  %28 = trunc i32 %27 to i8
  %29 = load ptr, ptr %11, align 8, !tbaa !10
  %30 = getelementptr inbounds %struct.GDT, ptr %29, i32 0, i32 2
  store i8 %28, ptr %30, align 1, !tbaa !16
  %31 = load i8, ptr %9, align 1, !tbaa !9
  %32 = load ptr, ptr %11, align 8, !tbaa !10
  %33 = getelementptr inbounds %struct.GDT, ptr %32, i32 0, i32 3
  store i8 %31, ptr %33, align 1, !tbaa !17
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = lshr i32 %34, 16
  %36 = and i32 %35, 15
  %37 = trunc i32 %36 to i8
  %38 = load ptr, ptr %11, align 8, !tbaa !10
  %39 = getelementptr inbounds %struct.GDT, ptr %38, i32 0, i32 4
  store i8 %37, ptr %39, align 1, !tbaa !18
  %40 = load ptr, ptr %11, align 8, !tbaa !10
  %41 = getelementptr inbounds %struct.GDT, ptr %40, i32 0, i32 4
  %42 = load i8, ptr %41, align 1, !tbaa !18
  %43 = zext i8 %42 to i32
  %44 = load i8, ptr %10, align 1, !tbaa !9
  %45 = zext i8 %44 to i32
  %46 = and i32 %45, 240
  %47 = or i32 %43, %46
  %48 = trunc i32 %47 to i8
  %49 = load ptr, ptr %11, align 8, !tbaa !10
  %50 = getelementptr inbounds %struct.GDT, ptr %49, i32 0, i32 4
  store i8 %48, ptr %50, align 1, !tbaa !18
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = lshr i32 %51, 24
  %53 = and i32 %52, 255
  %54 = trunc i32 %53 to i8
  %55 = load ptr, ptr %11, align 8, !tbaa !10
  %56 = getelementptr inbounds %struct.GDT, ptr %55, i32 0, i32 5
  store i8 %54, ptr %56, align 1, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  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, !6, i64 0}
!6 = !{!"int", !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 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"", !14, i64 0, !14, i64 2, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !14, i64 2}
!16 = !{!13, !7, i64 4}
!17 = !{!13, !7, i64 5}
!18 = !{!13, !7, i64 6}
!19 = !{!13, !7, i64 7}


; 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.GDT = type { i16, i16, i8, i8, i8, i8 }

@g_gdt = external dso_local local_unnamed_addr global [8 x %struct.GDT], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @gdt_set_entry(i32 noundef %0, i32 noundef %1, i32 noundef %2, i8 noundef zeroext %3, i8 noundef zeroext %4) local_unnamed_addr #0 {
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds [8 x %struct.GDT], ptr @g_gdt, i64 0, i64 %6
  %8 = trunc i32 %2 to i16
  store i16 %8, ptr %7, align 8, !tbaa !5
  %9 = trunc i32 %1 to i16
  %10 = getelementptr inbounds i8, ptr %7, i64 2
  store i16 %9, ptr %10, align 2, !tbaa !10
  %11 = lshr i32 %1, 16
  %12 = trunc i32 %11 to i8
  %13 = getelementptr inbounds i8, ptr %7, i64 4
  store i8 %12, ptr %13, align 4, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %7, i64 5
  store i8 %3, ptr %14, align 1, !tbaa !12
  %15 = lshr i32 %2, 16
  %16 = getelementptr inbounds i8, ptr %7, i64 6
  %17 = and i8 %4, -16
  %18 = trunc i32 %15 to i8
  %19 = and i8 %18, 15
  %20 = or disjoint i8 %19, %17
  store i8 %20, ptr %16, align 2, !tbaa !13
  %21 = lshr i32 %1, 24
  %22 = trunc nuw i32 %21 to i8
  %23 = getelementptr inbounds i8, ptr %7, i64 7
  store i8 %22, ptr %23, align 1, !tbaa !14
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) 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" }

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass