; LLVM IR from masyagin1998/GCI :: src/lexer (pos)

; 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.POS = type { ptr, i64, i64, i64, i64 }

; Function Attrs: inlinehint nounwind uwtable
declare dso_local i32 @pos_is_eof(ptr noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare dso_local i32 @pos_is_newline(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @pos_next(ptr dead_on_unwind noalias writable sret(%struct.POS) align 8 %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.POS, ptr %7, i32 0, i32 2
  %9 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %9, ptr %4, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.POS, ptr %10, i32 0, i32 3
  %12 = load i64, ptr %11, align 8, !tbaa !13
  store i64 %12, ptr %5, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.POS, ptr %13, i32 0, i32 4
  %15 = load i64, ptr %14, align 8, !tbaa !14
  store i64 %15, ptr %6, align 8, !tbaa !12
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call i32 @pos_is_eof(ptr noundef %16)
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %32, label %19

19:                                               ; preds = %2
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = call i32 @pos_is_newline(ptr noundef %20)
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %26

23:                                               ; preds = %19
  %24 = load i64, ptr %4, align 8, !tbaa !12
  %25 = add i64 %24, 1
  store i64 %25, ptr %4, align 8, !tbaa !12
  store i64 1, ptr %5, align 8, !tbaa !12
  br label %29

26:                                               ; preds = %19
  %27 = load i64, ptr %5, align 8, !tbaa !12
  %28 = add i64 %27, 1
  store i64 %28, ptr %5, align 8, !tbaa !12
  br label %29

29:                                               ; preds = %26, %23
  %30 = load i64, ptr %6, align 8, !tbaa !12
  %31 = add i64 %30, 1
  store i64 %31, ptr %6, align 8, !tbaa !12
  br label %32

32:                                               ; preds = %29, %2
  %33 = getelementptr inbounds %struct.POS, ptr %0, i32 0, i32 0
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.POS, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !15
  store ptr %36, ptr %33, align 8, !tbaa !15
  %37 = getelementptr inbounds %struct.POS, ptr %0, i32 0, i32 1
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.POS, ptr %38, i32 0, i32 1
  %40 = load i64, ptr %39, align 8, !tbaa !16
  store i64 %40, ptr %37, align 8, !tbaa !16
  %41 = getelementptr inbounds %struct.POS, ptr %0, i32 0, i32 2
  %42 = load i64, ptr %4, align 8, !tbaa !12
  store i64 %42, ptr %41, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.POS, ptr %0, i32 0, i32 3
  %44 = load i64, ptr %5, align 8, !tbaa !12
  store i64 %44, ptr %43, align 8, !tbaa !13
  %45 = getelementptr inbounds %struct.POS, ptr %0, i32 0, i32 4
  %46 = load i64, ptr %6, align 8, !tbaa !12
  store i64 %46, ptr %45, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  ret void
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 16}
!10 = !{!"POS", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 24}
!14 = !{!10, !11, i64 32}
!15 = !{!10, !6, i64 0}
!16 = !{!10, !11, i64 8}


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

%struct.POS = type { ptr, i64, i64, i64, i64 }

; Function Attrs: inlinehint nounwind uwtable
declare dso_local i32 @pos_is_eof(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare dso_local i32 @pos_is_newline(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @pos_next(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.POS) align 8 %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %1, i64 16
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 24
  %6 = load i64, ptr %5, align 8, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %1, i64 32
  %8 = load i64, ptr %7, align 8, !tbaa !12
  %9 = tail call i32 @pos_is_eof(ptr noundef %1)
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %15

10:                                               ; preds = %2
  %11 = tail call i32 @pos_is_newline(ptr noundef nonnull %1)
  %.not15 = icmp ne i32 %11, 0
  %12 = add i64 %6, 1
  %13 = zext i1 %.not15 to i64
  %.013 = add i64 %4, %13
  %.012 = select i1 %.not15, i64 1, i64 %12
  %14 = add i64 %8, 1
  br label %15

15:                                               ; preds = %10, %2
  %.114 = phi i64 [ %4, %2 ], [ %.013, %10 ]
  %.1 = phi i64 [ %6, %2 ], [ %.012, %10 ]
  %.0 = phi i64 [ %8, %2 ], [ %14, %10 ]
  %16 = load ptr, ptr %1, align 8, !tbaa !13
  store ptr %16, ptr %0, align 8, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = getelementptr inbounds i8, ptr %1, i64 8
  %19 = load i64, ptr %18, align 8, !tbaa !14
  store i64 %19, ptr %17, align 8, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %.114, ptr %20, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %.1, ptr %21, align 8, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 %.0, ptr %22, align 8, !tbaa !12
  ret void
}

attributes #0 = { 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 #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)"}
!5 = !{!6, !10, i64 16}
!6 = !{!"POS", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 24}
!12 = !{!6, !10, i64 32}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !10, i64 8}


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