; LLVM IR from paintdream/DontStarveLuaJIT :: src/luajit/src (lj_opt_narrow)

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

%union.TValue = type { i64 }

; 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: alwaysinline nounwind uwtable
declare hidden double @numberVnum(ptr noundef) #1

; Function Attrs: nounwind uwtable
define hidden i32 @lj_opt_narrow_forl(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %union.TValue, ptr %10, i64 0
  %12 = call i32 @narrow_forl(ptr noundef %9, ptr noundef %11)
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %48

14:                                               ; preds = %2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %union.TValue, ptr %16, i64 1
  %18 = call i32 @narrow_forl(ptr noundef %15, ptr noundef %17)
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %48

20:                                               ; preds = %14
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %union.TValue, ptr %22, i64 2
  %24 = call i32 @narrow_forl(ptr noundef %21, ptr noundef %23)
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %48

26:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %union.TValue, ptr %27, i64 2
  %29 = call double @numberVnum(ptr noundef %28)
  store double %29, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %union.TValue, ptr %30, i64 1
  %32 = call double @numberVnum(ptr noundef %31)
  %33 = load double, ptr %6, align 8, !tbaa !9
  %34 = fadd double %32, %33
  store double %34, ptr %7, align 8, !tbaa !9
  %35 = load double, ptr %6, align 8, !tbaa !9
  %36 = fcmp ole double 0.000000e+00, %35
  br i1 %36, label %37, label %40

37:                                               ; preds = %26
  %38 = load double, ptr %7, align 8, !tbaa !9
  %39 = fcmp ole double %38, 0x41DFFFFFFFC00000
  br i1 %39, label %43, label %44

40:                                               ; preds = %26
  %41 = load double, ptr %7, align 8, !tbaa !9
  %42 = fcmp oge double %41, 0xC1E0000000000000
  br i1 %42, label %43, label %44

43:                                               ; preds = %40, %37
  store i32 19, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %45

44:                                               ; preds = %40, %37
  store i32 0, ptr %8, align 4
  br label %45

45:                                               ; preds = %44, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %46 = load i32, ptr %8, align 4
  switch i32 %46, label %51 [
    i32 0, label %47
    i32 1, label %49
  ]

47:                                               ; preds = %45
  br label %48

48:                                               ; preds = %47, %20, %14, %2
  store i32 14, ptr %3, align 4
  br label %49

49:                                               ; preds = %48, %45
  %50 = load i32, ptr %3, align 4
  ret i32 %50

51:                                               ; preds = %45
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden i32 @narrow_forl(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline 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 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 #3 = { 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, !10, i64 0}
!10 = !{!"double", !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: alwaysinline nounwind uwtable
declare hidden double @numberVnum(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define hidden range(i32 14, 20) i32 @lj_opt_narrow_forl(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call i32 @narrow_forl(ptr noundef %0, ptr noundef %1)
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %19, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = tail call i32 @narrow_forl(ptr noundef %0, ptr noundef nonnull %5)
  %.not14 = icmp eq i32 %6, 0
  br i1 %.not14, label %19, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %1, i64 16
  %9 = tail call i32 @narrow_forl(ptr noundef %0, ptr noundef nonnull %8)
  %.not15 = icmp eq i32 %9, 0
  br i1 %.not15, label %19, label %10

10:                                               ; preds = %7
  %11 = tail call double @numberVnum(ptr noundef nonnull %8)
  %12 = tail call double @numberVnum(ptr noundef nonnull %5)
  %13 = fadd double %11, %12
  %14 = fcmp ult double %11, 0.000000e+00
  br i1 %14, label %17, label %15

15:                                               ; preds = %10
  %16 = fcmp ugt double %13, 0x41DFFFFFFFC00000
  br i1 %16, label %19, label %.thread

17:                                               ; preds = %10
  %18 = fcmp ult double %13, 0xC1E0000000000000
  br i1 %18, label %19, label %.thread

.thread:                                          ; preds = %17, %15
  br label %19

19:                                               ; preds = %2, %4, %7, %15, %17, %.thread
  %.1 = phi i32 [ 19, %.thread ], [ 14, %17 ], [ 14, %15 ], [ 14, %7 ], [ 14, %4 ], [ 14, %2 ]
  ret i32 %.1
}

; Function Attrs: nounwind uwtable
declare hidden i32 @narrow_forl(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { alwaysinline 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 = { 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" }

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


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