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

; 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.LexState = type { i32, i32, i32, %struct.Token, %struct.Token, ptr, ptr, ptr, ptr, ptr, i8 }
%struct.Token = type { i32, %union.SemInfo }
%union.SemInfo = type { double }
%struct.Mbuffer = type { ptr, i64, i64 }
%struct.Zio = type { i64, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define hidden void @luaX_setinput(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.LexState, ptr %9, i32 0, i32 10
  store i8 46, ptr %10, align 8, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.LexState, ptr %12, i32 0, i32 6
  store ptr %11, ptr %13, align 8, !tbaa !13
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.LexState, ptr %14, i32 0, i32 4
  %16 = getelementptr inbounds %struct.Token, ptr %15, i32 0, i32 0
  store i32 287, ptr %16, align 8, !tbaa !14
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.LexState, ptr %18, i32 0, i32 7
  store ptr %17, ptr %19, align 8, !tbaa !15
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.LexState, ptr %20, i32 0, i32 5
  store ptr null, ptr %21, align 8, !tbaa !16
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.LexState, ptr %22, i32 0, i32 1
  store i32 1, ptr %23, align 4, !tbaa !17
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.LexState, ptr %24, i32 0, i32 2
  store i32 1, ptr %25, align 8, !tbaa !18
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.LexState, ptr %27, i32 0, i32 9
  store ptr %26, ptr %28, align 8, !tbaa !19
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.LexState, ptr %29, i32 0, i32 6
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.LexState, ptr %32, i32 0, i32 8
  %34 = load ptr, ptr %33, align 8, !tbaa !20
  %35 = getelementptr inbounds %struct.Mbuffer, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !21
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.LexState, ptr %37, i32 0, i32 8
  %39 = load ptr, ptr %38, align 8, !tbaa !20
  %40 = getelementptr inbounds %struct.Mbuffer, ptr %39, i32 0, i32 2
  %41 = load i64, ptr %40, align 8, !tbaa !24
  %42 = mul i64 %41, 1
  %43 = call ptr @luaM_realloc_(ptr noundef %31, ptr noundef %36, i64 noundef %42, i64 noundef 32)
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.LexState, ptr %44, i32 0, i32 8
  %46 = load ptr, ptr %45, align 8, !tbaa !20
  %47 = getelementptr inbounds %struct.Mbuffer, ptr %46, i32 0, i32 0
  store ptr %43, ptr %47, align 8, !tbaa !21
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.LexState, ptr %48, i32 0, i32 8
  %50 = load ptr, ptr %49, align 8, !tbaa !20
  %51 = getelementptr inbounds %struct.Mbuffer, ptr %50, i32 0, i32 2
  store i64 32, ptr %51, align 8, !tbaa !24
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.LexState, ptr %52, i32 0, i32 7
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = getelementptr inbounds %struct.Zio, ptr %54, i32 0, i32 0
  %56 = load i64, ptr %55, align 8, !tbaa !25
  %57 = add i64 %56, -1
  store i64 %57, ptr %55, align 8, !tbaa !25
  %58 = icmp ugt i64 %56, 0
  br i1 %58, label %59, label %68

59:                                               ; preds = %4
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.LexState, ptr %60, i32 0, i32 7
  %62 = load ptr, ptr %61, align 8, !tbaa !15
  %63 = getelementptr inbounds %struct.Zio, ptr %62, i32 0, i32 1
  %64 = load ptr, ptr %63, align 8, !tbaa !27
  %65 = getelementptr inbounds i8, ptr %64, i32 1
  store ptr %65, ptr %63, align 8, !tbaa !27
  %66 = load i8, ptr %64, align 1, !tbaa !28
  %67 = zext i8 %66 to i32
  br label %73

68:                                               ; preds = %4
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.LexState, ptr %69, i32 0, i32 7
  %71 = load ptr, ptr %70, align 8, !tbaa !15
  %72 = call i32 @luaZ_fill(ptr noundef %71)
  br label %73

73:                                               ; preds = %68, %59
  %74 = phi i32 [ %67, %59 ], [ %72, %68 ]
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.LexState, ptr %75, i32 0, i32 0
  store i32 %74, ptr %76, align 8, !tbaa !29
  ret void
}

declare hidden ptr @luaM_realloc_(ptr noundef, ptr noundef, i64 noundef, i64 noundef) #1

declare hidden i32 @luaZ_fill(ptr noundef) #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 = { "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 88}
!10 = !{!"LexState", !11, i64 0, !11, i64 4, !11, i64 8, !12, i64 16, !12, i64 32, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !7, i64 88}
!11 = !{!"int", !7, i64 0}
!12 = !{!"Token", !11, i64 0, !7, i64 8}
!13 = !{!10, !6, i64 56}
!14 = !{!10, !11, i64 32}
!15 = !{!10, !6, i64 64}
!16 = !{!10, !6, i64 48}
!17 = !{!10, !11, i64 4}
!18 = !{!10, !11, i64 8}
!19 = !{!10, !6, i64 80}
!20 = !{!10, !6, i64 72}
!21 = !{!22, !6, i64 0}
!22 = !{!"Mbuffer", !6, i64 0, !23, i64 8, !23, i64 16}
!23 = !{!"long", !7, i64 0}
!24 = !{!22, !23, i64 16}
!25 = !{!26, !23, i64 0}
!26 = !{!"Zio", !23, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!27 = !{!26, !6, i64 8}
!28 = !{!7, !7, i64 0}
!29 = !{!10, !11, 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
define hidden void @luaX_setinput(ptr noundef %0, ptr nocapture noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %1, i64 88
  store i8 46, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 56
  store ptr %0, ptr %6, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %1, i64 32
  store i32 287, ptr %7, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %1, i64 64
  store ptr %2, ptr %8, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %1, i64 48
  store ptr null, ptr %9, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 1, ptr %10, align 4, !tbaa !16
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 1, ptr %11, align 8, !tbaa !17
  %12 = getelementptr inbounds i8, ptr %1, i64 80
  store ptr %3, ptr %12, align 8, !tbaa !18
  %13 = getelementptr inbounds i8, ptr %1, i64 72
  %14 = load ptr, ptr %13, align 8, !tbaa !19
  %15 = load ptr, ptr %14, align 8, !tbaa !20
  %16 = getelementptr inbounds i8, ptr %14, i64 16
  %17 = load i64, ptr %16, align 8, !tbaa !23
  %18 = tail call ptr @luaM_realloc_(ptr noundef %0, ptr noundef %15, i64 noundef %17, i64 noundef 32) #2
  %19 = load ptr, ptr %13, align 8, !tbaa !19
  store ptr %18, ptr %19, align 8, !tbaa !20
  %20 = getelementptr inbounds i8, ptr %19, i64 16
  store i64 32, ptr %20, align 8, !tbaa !23
  %21 = load ptr, ptr %8, align 8, !tbaa !14
  %22 = load i64, ptr %21, align 8, !tbaa !24
  %23 = add i64 %22, -1
  store i64 %23, ptr %21, align 8, !tbaa !24
  %.not = icmp eq i64 %22, 0
  br i1 %.not, label %30, label %24

24:                                               ; preds = %4
  %25 = getelementptr inbounds i8, ptr %21, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !26
  %27 = getelementptr inbounds i8, ptr %26, i64 1
  store ptr %27, ptr %25, align 8, !tbaa !26
  %28 = load i8, ptr %26, align 1, !tbaa !27
  %29 = zext i8 %28 to i32
  br label %32

30:                                               ; preds = %4
  %31 = tail call i32 @luaZ_fill(ptr noundef nonnull %21) #2
  br label %32

32:                                               ; preds = %30, %24
  %33 = phi i32 [ %29, %24 ], [ %31, %30 ]
  store i32 %33, ptr %1, align 8, !tbaa !28
  ret void
}

declare hidden ptr @luaM_realloc_(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

declare hidden i32 @luaZ_fill(ptr noundef) local_unnamed_addr #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 = { "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, !8, i64 88}
!6 = !{!"LexState", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 32, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !8, i64 88}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"Token", !7, i64 0, !8, i64 8}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !11, i64 56}
!13 = !{!6, !7, i64 32}
!14 = !{!6, !11, i64 64}
!15 = !{!6, !11, i64 48}
!16 = !{!6, !7, i64 4}
!17 = !{!6, !7, i64 8}
!18 = !{!6, !11, i64 80}
!19 = !{!6, !11, i64 72}
!20 = !{!21, !11, i64 0}
!21 = !{!"Mbuffer", !11, i64 0, !22, i64 8, !22, i64 16}
!22 = !{!"long", !8, i64 0}
!23 = !{!21, !22, i64 16}
!24 = !{!25, !22, i64 0}
!25 = !{!"Zio", !22, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!26 = !{!25, !11, i64 8}
!27 = !{!8, !8, i64 0}
!28 = !{!6, !7, i64 0}


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