; LLVM IR from snowballstem/snowball :: compiler (tokeniser)

; 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.tokeniser = type { ptr, ptr, i32, ptr, i32, i32, ptr, ptr, i32, i32, i32, ptr, i32, i32, i32, i32, i8, i8, i32, i32, ptr, i32, [94 x i8] }
%struct.m_pair = type { ptr, ptr, ptr }
%struct.input = type { ptr, ptr, i32, ptr, i32, i32 }

; 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: nounwind
declare void @free(ptr noundef) #1

declare void @lose_s(ptr noundef) #2

declare void @check_free(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @close_tokeniser(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.tokeniser, ptr %7, i32 0, i32 6
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  call void @lose_b(ptr noundef %9)
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.tokeniser, ptr %10, i32 0, i32 7
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  call void @lose_s(ptr noundef %12)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.tokeniser, ptr %13, i32 0, i32 11
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  store ptr %15, ptr %3, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %19, %1
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %31

19:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.m_pair, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  store ptr %22, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.m_pair, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  call void @lose_s(ptr noundef %25)
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.m_pair, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  call void @lose_b(ptr noundef %28)
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  call void @check_free(ptr noundef %29)
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %30, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %16, !llvm.loop !18

31:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.tokeniser, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !20
  store ptr %34, ptr %5, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %38, %31
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %44

38:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.input, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !21
  store ptr %41, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  call void @check_free(ptr noundef %42)
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %43, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %35, !llvm.loop !23

44:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.tokeniser, ptr %45, i32 0, i32 4
  %47 = load i32, ptr %46, align 8, !tbaa !24
  %48 = icmp sgt i32 %47, 0
  br i1 %48, label %49, label %53

49:                                               ; preds = %44
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.tokeniser, ptr %50, i32 0, i32 3
  %52 = load ptr, ptr %51, align 8, !tbaa !25
  call void @free(ptr noundef %52) #4
  br label %63

53:                                               ; preds = %44
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.tokeniser, ptr %54, i32 0, i32 4
  %56 = load i32, ptr %55, align 8, !tbaa !24
  %57 = icmp slt i32 %56, 0
  br i1 %57, label %58, label %62

58:                                               ; preds = %53
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.tokeniser, ptr %59, i32 0, i32 3
  %61 = load ptr, ptr %60, align 8, !tbaa !25
  call void @lose_s(ptr noundef %61)
  br label %62

62:                                               ; preds = %58, %53
  br label %63

63:                                               ; preds = %62, %49
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  call void @check_free(ptr noundef %64)
  ret void
}

declare void @lose_b(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { "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 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 #4 = { 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, !6, i64 40}
!10 = !{!"tokeniser", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !11, i64 32, !11, i64 36, !6, i64 40, !6, i64 48, !11, i64 56, !11, i64 60, !11, i64 64, !6, i64 72, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !7, i64 96, !7, i64 97, !11, i64 100, !11, i64 104, !6, i64 112, !11, i64 120, !7, i64 124}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 48}
!13 = !{!10, !6, i64 72}
!14 = !{!15, !6, i64 0}
!15 = !{!"m_pair", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!15, !6, i64 8}
!17 = !{!15, !6, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!10, !6, i64 0}
!21 = !{!22, !6, i64 0}
!22 = !{!"input", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !11, i64 32, !11, i64 36}
!23 = distinct !{!23, !19}
!24 = !{!10, !11, i64 32}
!25 = !{!10, !6, i64 24}


; 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

declare void @lose_s(ptr noundef) local_unnamed_addr #1

declare void @check_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @close_tokeniser(ptr noundef %0) local_unnamed_addr #2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  tail call void @lose_b(ptr noundef %3) #3
  %4 = getelementptr inbounds i8, ptr %0, i64 48
  %5 = load ptr, ptr %4, align 8, !tbaa !11
  tail call void @lose_s(ptr noundef %5) #3
  %6 = getelementptr inbounds i8, ptr %0, i64 72
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %.not22 = icmp eq ptr %7, null
  br i1 %.not22, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.023 = phi ptr [ %8, %.lr.ph ], [ %7, %1 ]
  %8 = load ptr, ptr %.023, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %.023, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  tail call void @lose_s(ptr noundef %10) #3
  %11 = getelementptr inbounds i8, ptr %.023, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !16
  tail call void @lose_b(ptr noundef %12) #3
  tail call void @check_free(ptr noundef nonnull %.023) #3
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %.lr.ph, %1
  %13 = load ptr, ptr %0, align 8, !tbaa !19
  %.not2124 = icmp eq ptr %13, null
  br i1 %.not2124, label %._crit_edge28, label %.lr.ph27

.lr.ph27:                                         ; preds = %._crit_edge, %.lr.ph27
  %.01925 = phi ptr [ %14, %.lr.ph27 ], [ %13, %._crit_edge ]
  %14 = load ptr, ptr %.01925, align 8, !tbaa !20
  tail call void @check_free(ptr noundef nonnull %.01925) #3
  %.not21 = icmp eq ptr %14, null
  br i1 %.not21, label %._crit_edge28, label %.lr.ph27, !llvm.loop !22

._crit_edge28:                                    ; preds = %.lr.ph27, %._crit_edge
  %15 = getelementptr inbounds i8, ptr %0, i64 32
  %16 = load i32, ptr %15, align 8, !tbaa !23
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %18, label %21

18:                                               ; preds = %._crit_edge28
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  %20 = load ptr, ptr %19, align 8, !tbaa !24
  tail call void @free(ptr noundef %20) #3
  br label %26

21:                                               ; preds = %._crit_edge28
  %22 = icmp slt i32 %16, 0
  br i1 %22, label %23, label %26

23:                                               ; preds = %21
  %24 = getelementptr inbounds i8, ptr %0, i64 24
  %25 = load ptr, ptr %24, align 8, !tbaa !24
  tail call void @lose_s(ptr noundef %25) #3
  br label %26

26:                                               ; preds = %21, %23, %18
  tail call void @check_free(ptr noundef nonnull %0) #3
  ret void
}

declare void @lose_b(ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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, !7, i64 40}
!6 = !{!"tokeniser", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !10, i64 32, !10, i64 36, !7, i64 40, !7, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !7, i64 72, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !8, i64 96, !8, i64 97, !10, i64 100, !10, i64 104, !7, i64 112, !10, i64 120, !8, i64 124}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 48}
!12 = !{!6, !7, i64 72}
!13 = !{!14, !7, i64 0}
!14 = !{!"m_pair", !7, i64 0, !7, i64 8, !7, i64 16}
!15 = !{!14, !7, i64 8}
!16 = !{!14, !7, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !7, i64 0}
!20 = !{!21, !7, i64 0}
!21 = !{!"input", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !10, i64 32, !10, i64 36}
!22 = distinct !{!22, !18}
!23 = !{!6, !10, i64 32}
!24 = !{!6, !7, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass