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

; 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.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
define dso_local void @update_blk_index() #1 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  %2 = load ptr, ptr @blk, align 8, !tbaa !5
  %3 = getelementptr inbounds %struct.blk, ptr %2, i32 0, i32 3
  %4 = load i8, ptr %3, align 2, !tbaa !9
  %5 = zext i8 %4 to i32
  %6 = or i32 0, %5
  %7 = load ptr, ptr @blk, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.blk, ptr %7, i32 0, i32 4
  %9 = load i8, ptr %8, align 1, !tbaa !12
  %10 = zext i8 %9 to i32
  %11 = shl i32 %10, 8
  %12 = or i32 %6, %11
  %13 = load ptr, ptr @blk, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.blk, ptr %13, i32 0, i32 5
  %15 = load i8, ptr %14, align 4, !tbaa !13
  %16 = zext i8 %15 to i32
  %17 = shl i32 %16, 16
  %18 = or i32 %12, %17
  store i32 %18, ptr %1, align 4, !tbaa !14
  %19 = load i32, ptr %1, align 4, !tbaa !14
  %20 = mul i32 %19, 512
  %21 = load ptr, ptr @blk, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.blk, ptr %21, i32 0, i32 8
  store i32 %20, ptr %22, align 8, !tbaa !15
  %23 = load ptr, ptr @blk, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.blk, ptr %23, i32 0, i32 6
  %25 = load i8, ptr %24, align 1, !tbaa !16
  %26 = zext i8 %25 to i32
  %27 = icmp eq i32 %26, 240
  br i1 %27, label %28, label %33

28:                                               ; preds = %0
  %29 = load ptr, ptr @blk, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.blk, ptr %29, i32 0, i32 8
  %31 = load i32, ptr %30, align 8, !tbaa !15
  %32 = add i32 %31, 5120000
  store i32 %32, ptr %30, align 8, !tbaa !15
  br label %33

33:                                               ; preds = %28, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret void
}

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 = { 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, !7, i64 10}
!10 = !{!"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}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !7, i64 11}
!13 = !{!10, !7, i64 12}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 16}
!16 = !{!10, !7, i64 13}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @update_blk_index() local_unnamed_addr #0 {
  %1 = load ptr, ptr @blk, align 8, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %1, i64 10
  %3 = load i16, ptr %2, align 2
  %4 = zext i16 %3 to i32
  %5 = shl nuw nsw i32 %4, 9
  %6 = getelementptr inbounds i8, ptr %1, i64 12
  %7 = load i8, ptr %6, align 4, !tbaa !9
  %8 = zext i8 %7 to i32
  %9 = shl i32 %8, 25
  %10 = or disjoint i32 %9, %5
  %11 = getelementptr inbounds i8, ptr %1, i64 16
  store i32 %10, ptr %11, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %1, i64 13
  %13 = load i8, ptr %12, align 1, !tbaa !13
  %14 = icmp eq i8 %13, -16
  br i1 %14, label %15, label %17

15:                                               ; preds = %0
  %16 = add i32 %10, 5120000
  store i32 %16, ptr %11, align 8, !tbaa !12
  br label %17

17:                                               ; preds = %15, %0
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 12}
!10 = !{!"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}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 16}
!13 = !{!10, !7, i64 13}


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