; LLVM IR from clbx/Cosmic :: src/cosproc.ll (ZN7cosproc4DIVREt)

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

%class.cosproc = type { ptr, ptr, i16, i16, [8 x i8], [8 x i8], [257 x %"struct.cosproc::Instruction"] }
%"struct.cosproc::Instruction" = type { { i64, i64 }, { i64, i64 }, ptr, i32 }

; 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: mustprogress nounwind uwtable
define dso_local void @_ZN7cosproc4DIVREt(ptr noundef nonnull align 8 dereferenceable(12376) %0, i16 noundef zeroext %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i16 %1, ptr %4, align 2, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #2
  %9 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 4
  %10 = load i16, ptr %4, align 2, !tbaa !9
  %11 = zext i16 %10 to i64
  %12 = getelementptr inbounds [8 x i8], ptr %9, i64 0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !11
  store i8 %13, ptr %5, align 1, !tbaa !11
  %14 = load i8, ptr %5, align 1, !tbaa !11
  %15 = icmp ne i8 %14, 0
  br i1 %15, label %19, label %16

16:                                               ; preds = %2
  %17 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 5
  %18 = getelementptr inbounds [8 x i8], ptr %17, i64 0, i64 6
  store i8 1, ptr %18, align 2, !tbaa !12
  store i32 1, ptr %6, align 4
  br label %66

19:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %20 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 4
  %21 = getelementptr inbounds [8 x i8], ptr %20, i64 0, i64 0
  %22 = load i8, ptr %21, align 4, !tbaa !11
  %23 = zext i8 %22 to i32
  %24 = load i8, ptr %5, align 1, !tbaa !11
  %25 = zext i8 %24 to i32
  %26 = sdiv i32 %23, %25
  store i32 %26, ptr %7, align 4, !tbaa !14
  %27 = load i32, ptr %7, align 4, !tbaa !14
  %28 = icmp uge i32 %27, 128
  %29 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 5
  %30 = getelementptr inbounds [8 x i8], ptr %29, i64 0, i64 1
  %31 = zext i1 %28 to i8
  store i8 %31, ptr %30, align 1, !tbaa !12
  %32 = load i32, ptr %7, align 4, !tbaa !14
  %33 = icmp ugt i32 %32, 255
  %34 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 5
  %35 = getelementptr inbounds [8 x i8], ptr %34, i64 0, i64 2
  %36 = zext i1 %33 to i8
  store i8 %36, ptr %35, align 2, !tbaa !12
  %37 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 4
  %38 = getelementptr inbounds [8 x i8], ptr %37, i64 0, i64 0
  %39 = load i8, ptr %38, align 4, !tbaa !11
  %40 = zext i8 %39 to i32
  %41 = load i32, ptr %7, align 4, !tbaa !14
  %42 = xor i32 %40, %41
  %43 = load i8, ptr %5, align 1, !tbaa !11
  %44 = zext i8 %43 to i32
  %45 = load i32, ptr %7, align 4, !tbaa !14
  %46 = xor i32 %44, %45
  %47 = and i32 %42, %46
  %48 = and i32 %47, 128
  %49 = icmp ne i32 %48, 0
  %50 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 5
  %51 = getelementptr inbounds [8 x i8], ptr %50, i64 0, i64 3
  %52 = zext i1 %49 to i8
  store i8 %52, ptr %51, align 1, !tbaa !12
  %53 = load i32, ptr %7, align 4, !tbaa !14
  %54 = and i32 %53, 255
  %55 = trunc i32 %54 to i8
  %56 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 4
  %57 = getelementptr inbounds [8 x i8], ptr %56, i64 0, i64 0
  store i8 %55, ptr %57, align 4, !tbaa !11
  %58 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 4
  %59 = getelementptr inbounds [8 x i8], ptr %58, i64 0, i64 0
  %60 = load i8, ptr %59, align 4, !tbaa !11
  %61 = zext i8 %60 to i32
  %62 = icmp eq i32 %61, 0
  %63 = getelementptr inbounds %class.cosproc, ptr %8, i32 0, i32 5
  %64 = getelementptr inbounds [8 x i8], ptr %63, i64 0, i64 0
  %65 = zext i1 %62 to i8
  store i8 %65, ptr %64, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  store i32 0, ptr %6, align 4
  br label %66

66:                                               ; preds = %19, %16
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #2
  %67 = load i32, ptr %6, align 4
  switch i32 %67, label %69 [
    i32 0, label %68
    i32 1, label %68
  ]

68:                                               ; preds = %66, %66
  ret void

69:                                               ; preds = %66
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_ZN7cosproc4DIVREt(ptr nocapture noundef nonnull align 8 dereferenceable(12376) %0, i16 noundef zeroext %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 20
  %4 = zext i16 %1 to i64
  %5 = getelementptr inbounds [8 x i8], ptr %3, i64 0, i64 %4
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %.not = icmp eq i8 %6, 0
  br i1 %.not, label %7, label %9

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 34
  store i8 1, ptr %8, align 2, !tbaa !8
  br label %21

9:                                                ; preds = %2
  %10 = load i8, ptr %3, align 4, !tbaa !5
  %11 = udiv i8 %10, %6
  %12 = getelementptr inbounds i8, ptr %0, i64 28
  %13 = getelementptr inbounds i8, ptr %0, i64 29
  %.lobit = lshr i8 %11, 7
  store i8 %.lobit, ptr %13, align 1, !tbaa !8
  %14 = getelementptr inbounds i8, ptr %0, i64 30
  store i8 0, ptr %14, align 2, !tbaa !8
  %15 = xor i8 %11, %10
  %16 = xor i8 %11, %6
  %17 = and i8 %15, %16
  %18 = getelementptr inbounds i8, ptr %0, i64 31
  %.lobit9 = lshr i8 %17, 7
  store i8 %.lobit9, ptr %18, align 1, !tbaa !8
  store i8 %11, ptr %3, align 4, !tbaa !5
  %19 = icmp ugt i8 %6, %10
  %20 = zext i1 %19 to i8
  store i8 %20, ptr %12, align 4, !tbaa !8
  br label %21

21:                                               ; preds = %9, %7
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"bool", !6, i64 0}


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