; LLVM IR from marcobambini/gravity :: src/compiler (gravity_lexer)

; 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.gravity_lexer_t = type { ptr, i32, i32, i32, i32, i32, i32, %struct.gtoken_s, i8, i8, ptr, i32 }
%struct.gtoken_s = type { i32, i32, i32, i32, i32, i32, i32, i32, ptr }

; 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: inlinehint nounwind uwtable
declare hidden zeroext i1 @is_newline(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @gravity_lexer_skip_line(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %30, %1
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.gravity_lexer_t, ptr %6, i32 0, i32 1
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.gravity_lexer_t, ptr %9, i32 0, i32 3
  %11 = load i32, ptr %10, align 8, !tbaa !14
  %12 = icmp uge i32 %8, %11
  %13 = xor i1 %12, true
  br i1 %13, label %14, label %31

14:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !15
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = call zeroext i1 @next_utf8(ptr noundef %15, ptr noundef %3)
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = load i32, ptr %3, align 4, !tbaa !15
  %19 = call zeroext i1 @is_newline(ptr noundef %17, i32 noundef %18)
  br i1 %19, label %20, label %27

20:                                               ; preds = %14
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.gravity_lexer_t, ptr %21, i32 0, i32 4
  %23 = load i32, ptr %22, align 4, !tbaa !16
  %24 = add i32 %23, 1
  store i32 %24, ptr %22, align 4, !tbaa !16
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.gravity_lexer_t, ptr %25, i32 0, i32 5
  store i32 1, ptr %26, align 8, !tbaa !17
  store i32 3, ptr %4, align 4
  br label %28

27:                                               ; preds = %14
  store i32 0, ptr %4, align 4
  br label %28

28:                                               ; preds = %27, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %29 = load i32, ptr %4, align 4
  switch i32 %29, label %32 [
    i32 0, label %30
    i32 3, label %31
  ]

30:                                               ; preds = %28
  br label %5, !llvm.loop !18

31:                                               ; preds = %28, %5
  ret void

32:                                               ; preds = %28
  unreachable
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @next_utf8(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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, !11, i64 8}
!10 = !{!"gravity_lexer_t", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !12, i64 32, !13, i64 72, !13, i64 73, !6, i64 80, !11, i64 88}
!11 = !{!"int", !7, i64 0}
!12 = !{!"gtoken_s", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !6, i64 32}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!10, !11, i64 16}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !11, i64 20}
!17 = !{!10, !11, i64 24}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @is_newline(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @gravity_lexer_skip_line(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca i32, align 4
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i32, ptr %3, align 8, !tbaa !5
  %6 = load i32, ptr %4, align 8, !tbaa !13
  %.not8 = icmp ult i32 %5, %6
  br i1 %.not8, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %1, %14
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  store i32 0, ptr %2, align 4, !tbaa !14
  %7 = call zeroext i1 @next_utf8(ptr noundef nonnull %0, ptr noundef nonnull %2)
  %8 = load i32, ptr %2, align 4, !tbaa !14
  %9 = call zeroext i1 @is_newline(ptr noundef nonnull %0, i32 noundef %8)
  br i1 %9, label %.thread, label %14

.thread:                                          ; preds = %.lr.ph
  %10 = getelementptr inbounds i8, ptr %0, i64 20
  %11 = load i32, ptr %10, align 4, !tbaa !15
  %12 = add i32 %11, 1
  store i32 %12, ptr %10, align 4, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 1, ptr %13, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  br label %.loopexit

14:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  %15 = load i32, ptr %3, align 8, !tbaa !5
  %16 = load i32, ptr %4, align 8, !tbaa !13
  %.not = icmp ult i32 %15, %16
  br i1 %.not, label %.lr.ph, label %.loopexit

.loopexit:                                        ; preds = %14, %1, %.thread
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @next_utf8(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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, !10, i64 8}
!6 = !{!"gravity_lexer_t", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !11, i64 32, !12, i64 72, !12, i64 73, !7, i64 80, !10, i64 88}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"gtoken_s", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !7, i64 32}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!6, !10, i64 16}
!14 = !{!10, !10, i64 0}
!15 = !{!6, !10, i64 20}
!16 = !{!6, !10, i64 24}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass