; LLVM IR from ramsdell/lineqpp :: lua (lcode)

; 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.expdesc = type { i32, %union.anon, i32, i32 }
%union.anon = type { double }
%struct.anon = type { i32, i32 }
%struct.FuncState = type { ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i16, i8, [60 x %struct.upvaldesc], [200 x i16] }
%struct.upvaldesc = type { i8, i8 }

; Function Attrs: nounwind uwtable
declare hidden void @luaK_dischargevars(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @luaK_exp2nextreg(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @exp2reg(ptr noundef, ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define hidden i32 @luaK_exp2anyreg(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %5, align 8, !tbaa !5
  call void @luaK_dischargevars(ptr noundef %6, ptr noundef %7)
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.expdesc, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = icmp eq i32 %10, 12
  br i1 %11, label %12, label %47

12:                                               ; preds = %2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.expdesc, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 8, !tbaa !12
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.expdesc, ptr %16, i32 0, i32 3
  %18 = load i32, ptr %17, align 4, !tbaa !13
  %19 = icmp ne i32 %15, %18
  br i1 %19, label %25, label %20

20:                                               ; preds = %12
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.expdesc, ptr %21, i32 0, i32 1
  %23 = getelementptr inbounds %struct.anon, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !14
  store i32 %24, ptr %3, align 4
  br label %54

25:                                               ; preds = %12
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.expdesc, ptr %26, i32 0, i32 1
  %28 = getelementptr inbounds %struct.anon, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !14
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.FuncState, ptr %30, i32 0, i32 13
  %32 = load i8, ptr %31, align 2, !tbaa !15
  %33 = zext i8 %32 to i32
  %34 = icmp sge i32 %29, %33
  br i1 %34, label %35, label %46

35:                                               ; preds = %25
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.expdesc, ptr %38, i32 0, i32 1
  %40 = getelementptr inbounds %struct.anon, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !14
  call void @exp2reg(ptr noundef %36, ptr noundef %37, i32 noundef %41)
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.expdesc, ptr %42, i32 0, i32 1
  %44 = getelementptr inbounds %struct.anon, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !14
  store i32 %45, ptr %3, align 4
  br label %54

46:                                               ; preds = %25
  br label %47

47:                                               ; preds = %46, %2
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  call void @luaK_exp2nextreg(ptr noundef %48, ptr noundef %49)
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.expdesc, ptr %50, i32 0, i32 1
  %52 = getelementptr inbounds %struct.anon, ptr %51, i32 0, i32 0
  %53 = load i32, ptr %52, align 8, !tbaa !14
  store i32 %53, ptr %3, align 4
  br label %54

54:                                               ; preds = %47, %35, %20
  %55 = load i32, ptr %3, align 4
  ret i32 %55
}

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

!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, !11, i64 0}
!10 = !{!"expdesc", !11, i64 0, !7, i64 8, !11, i64 16, !11, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 16}
!13 = !{!10, !11, i64 20}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !7, i64 74}
!16 = !{!"FuncState", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !17, i64 72, !7, i64 74, !7, i64 75, !7, i64 196}
!17 = !{!"short", !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: nounwind uwtable
declare hidden void @luaK_dischargevars(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @luaK_exp2nextreg(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @exp2reg(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define hidden i32 @luaK_exp2anyreg(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  tail call void @luaK_dischargevars(ptr noundef %0, ptr noundef %1)
  %3 = load i32, ptr %1, align 8, !tbaa !5
  %4 = icmp eq i32 %3, 12
  br i1 %4, label %5, label %17

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 16
  %7 = load i32, ptr %6, align 8, !tbaa !10
  %8 = getelementptr inbounds i8, ptr %1, i64 20
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %.not = icmp eq i32 %7, %9
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  br i1 %.not, label %19, label %11

11:                                               ; preds = %5
  %12 = load i32, ptr %10, align 8, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %0, i64 74
  %14 = load i8, ptr %13, align 2, !tbaa !13
  %15 = zext i8 %14 to i32
  %.not16 = icmp slt i32 %12, %15
  br i1 %.not16, label %17, label %16

16:                                               ; preds = %11
  tail call void @exp2reg(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %12)
  br label %19

17:                                               ; preds = %11, %2
  tail call void @luaK_exp2nextreg(ptr noundef %0, ptr noundef nonnull %1)
  %18 = getelementptr inbounds i8, ptr %1, i64 8
  br label %19

19:                                               ; preds = %5, %17, %16
  %.0.in = phi ptr [ %10, %16 ], [ %18, %17 ], [ %10, %5 ]
  %.0 = load i32, ptr %.0.in, align 8, !tbaa !12
  ret i32 %.0
}

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

!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 = !{!"expdesc", !7, i64 0, !8, i64 8, !7, i64 16, !7, i64 20}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 16}
!11 = !{!6, !7, i64 20}
!12 = !{!8, !8, i64 0}
!13 = !{!14, !8, i64 74}
!14 = !{!"FuncState", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !15, i64 32, !15, i64 40, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !16, i64 72, !8, i64 74, !8, i64 75, !8, i64 196}
!15 = !{!"any pointer", !8, i64 0}
!16 = !{!"short", !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass