; LLVM IR from dennisss/tansa :: src/stereo/utils.ll (Z8spacetokPc)

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

@_ZL7laststr = external hidden global ptr, align 8

; 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: mustprogress nounwind uwtable
define dso_local noundef ptr @_Z8spacetokPc(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %11

9:                                                ; preds = %1
  %10 = load ptr, ptr @_ZL7laststr, align 8, !tbaa !5
  store ptr %10, ptr %3, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %9, %1
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = load i8, ptr %12, align 1, !tbaa !9
  store i8 %13, ptr %4, align 1, !tbaa !9
  br label %14

14:                                               ; preds = %25, %11
  %15 = load i8, ptr %4, align 1, !tbaa !9
  %16 = sext i8 %15 to i32
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %23

18:                                               ; preds = %14
  %19 = load i8, ptr %4, align 1, !tbaa !9
  %20 = sext i8 %19 to i32
  %21 = call i32 @isspace(i32 noundef %20) #4
  %22 = icmp ne i32 %21, 0
  br label %23

23:                                               ; preds = %18, %14
  %24 = phi i1 [ false, %14 ], [ %22, %18 ]
  br i1 %24, label %25, label %30

25:                                               ; preds = %23
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i32 1
  store ptr %27, ptr %3, align 8, !tbaa !5
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = load i8, ptr %28, align 1, !tbaa !9
  store i8 %29, ptr %4, align 1, !tbaa !9
  br label %14, !llvm.loop !10

30:                                               ; preds = %23
  %31 = load i8, ptr %4, align 1, !tbaa !9
  %32 = sext i8 %31 to i32
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %30
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %66

35:                                               ; preds = %30
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %36, ptr %5, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %49, %35
  %38 = load i8, ptr %4, align 1, !tbaa !9
  %39 = sext i8 %38 to i32
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %47

41:                                               ; preds = %37
  %42 = load i8, ptr %4, align 1, !tbaa !9
  %43 = sext i8 %42 to i32
  %44 = call i32 @isspace(i32 noundef %43) #4
  %45 = icmp ne i32 %44, 0
  %46 = xor i1 %45, true
  br label %47

47:                                               ; preds = %41, %37
  %48 = phi i1 [ false, %37 ], [ %46, %41 ]
  br i1 %48, label %49, label %54

49:                                               ; preds = %47
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i32 1
  store ptr %51, ptr %3, align 8, !tbaa !5
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = load i8, ptr %52, align 1, !tbaa !9
  store i8 %53, ptr %4, align 1, !tbaa !9
  br label %37, !llvm.loop !12

54:                                               ; preds = %47
  %55 = load i8, ptr %4, align 1, !tbaa !9
  %56 = sext i8 %55 to i32
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %58, label %60

58:                                               ; preds = %54
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %59, ptr @_ZL7laststr, align 8, !tbaa !5
  br label %64

60:                                               ; preds = %54
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  store i8 0, ptr %61, align 1, !tbaa !9
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %62, i64 1
  store ptr %63, ptr @_ZL7laststr, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %60, %58
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %65, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %66

66:                                               ; preds = %64, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  %67 = load ptr, ptr %2, align 8
  ret ptr %67
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @isspace(i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 willreturn memory(read) "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 }
attributes #4 = { nounwind willreturn memory(read) }

!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++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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

@_ZL7laststr = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree nounwind memory(readwrite, inaccessiblemem: read) uwtable
define dso_local noundef ptr @_Z8spacetokPc(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  %3 = load ptr, ptr @_ZL7laststr, align 8
  %spec.select = select i1 %2, ptr %3, ptr %0
  %.01933 = load i8, ptr %spec.select, align 1, !tbaa !5
  %cond34 = icmp eq i8 %.01933, 0
  br i1 %cond34, label %.loopexit29, label %.lr.ph

.lr.ph:                                           ; preds = %1, %6
  %.01936 = phi i8 [ %.019, %6 ], [ %.01933, %1 ]
  %.12135 = phi ptr [ %7, %6 ], [ %spec.select, %1 ]
  %4 = sext i8 %.01936 to i32
  %5 = tail call i32 @isspace(i32 noundef %4) #2
  %.not25 = icmp eq i32 %5, 0
  br i1 %.not25, label %.critedge.preheader, label %6

6:                                                ; preds = %.lr.ph
  %7 = getelementptr inbounds i8, ptr %.12135, i64 1
  %.019 = load i8, ptr %7, align 1, !tbaa !5
  %cond = icmp eq i8 %.019, 0
  br i1 %cond, label %.loopexit29, label %.lr.ph, !llvm.loop !8

.critedge.preheader:                              ; preds = %.lr.ph, %.critedge
  %.138 = phi i8 [ %11, %.critedge ], [ %.01936, %.lr.ph ]
  %.237 = phi ptr [ %10, %.critedge ], [ %.12135, %.lr.ph ]
  %8 = sext i8 %.138 to i32
  %9 = tail call i32 @isspace(i32 noundef %8) #2
  %.not27 = icmp eq i32 %9, 0
  br i1 %.not27, label %.critedge, label %.critedge2

.critedge:                                        ; preds = %.critedge.preheader
  %10 = getelementptr inbounds i8, ptr %.237, i64 1
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %cond28 = icmp eq i8 %11, 0
  br i1 %cond28, label %.loopexit, label %.critedge.preheader, !llvm.loop !10

.critedge2:                                       ; preds = %.critedge.preheader
  store i8 0, ptr %.237, align 1, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %.237, i64 1
  br label %.loopexit

.loopexit:                                        ; preds = %.critedge, %.critedge2
  %storemerge = phi ptr [ %12, %.critedge2 ], [ %10, %.critedge ]
  store ptr %storemerge, ptr @_ZL7laststr, align 8, !tbaa !11
  br label %.loopexit29

.loopexit29:                                      ; preds = %6, %1, %.loopexit
  %.0 = phi ptr [ %.12135, %.loopexit ], [ null, %1 ], [ null, %6 ]
  ret ptr %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @isspace(i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nofree nounwind memory(readwrite, inaccessiblemem: read) 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 = { mustprogress nofree nounwind willreturn memory(read) "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 willreturn memory(read) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !6, i64 0}


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