; LLVM IR from mbheinen/bpa-ipf-tsp :: cflow (post_pvcurve)

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

@strtok_x.ptr = external hidden global ptr, align 8
@strtok_x.last_ptr = external hidden global ptr, align 8
@strtok_x.temp_ptr = external hidden global ptr, align 8

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strstr(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local ptr @strtok_x(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %10

8:                                                ; preds = %2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %9, ptr @strtok_x.last_ptr, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %8, %2
  %11 = load ptr, ptr @strtok_x.last_ptr, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %10
  store ptr null, ptr %3, align 8
  br label %41

14:                                               ; preds = %10
  %15 = load ptr, ptr @strtok_x.last_ptr, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = call ptr @strstr(ptr noundef %15, ptr noundef %16) #2
  store ptr %17, ptr @strtok_x.ptr, align 8, !tbaa !5
  %18 = load ptr, ptr @strtok_x.ptr, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %27

20:                                               ; preds = %14
  %21 = load ptr, ptr @strtok_x.ptr, align 8, !tbaa !5
  store i8 0, ptr %21, align 1, !tbaa !9
  %22 = load ptr, ptr @strtok_x.last_ptr, align 8, !tbaa !5
  store ptr %22, ptr @strtok_x.temp_ptr, align 8, !tbaa !5
  %23 = load ptr, ptr @strtok_x.ptr, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call i64 @strlen(ptr noundef %24) #2
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  store ptr %26, ptr @strtok_x.last_ptr, align 8, !tbaa !5
  br label %39

27:                                               ; preds = %14
  %28 = load ptr, ptr @strtok_x.last_ptr, align 8, !tbaa !5
  %29 = call i64 @strlen(ptr noundef %28) #2
  %30 = icmp ugt i64 %29, 0
  br i1 %30, label %31, label %37

31:                                               ; preds = %27
  %32 = load ptr, ptr @strtok_x.last_ptr, align 8, !tbaa !5
  store ptr %32, ptr @strtok_x.temp_ptr, align 8, !tbaa !5
  %33 = load ptr, ptr @strtok_x.last_ptr, align 8, !tbaa !5
  %34 = load ptr, ptr @strtok_x.last_ptr, align 8, !tbaa !5
  %35 = call i64 @strlen(ptr noundef %34) #2
  %36 = getelementptr inbounds i8, ptr %33, i64 %35
  store ptr %36, ptr @strtok_x.last_ptr, align 8, !tbaa !5
  br label %38

37:                                               ; preds = %27
  store ptr null, ptr @strtok_x.last_ptr, align 8, !tbaa !5
  store ptr null, ptr @strtok_x.temp_ptr, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %37, %31
  br label %39

39:                                               ; preds = %38, %20
  %40 = load ptr, ptr @strtok_x.temp_ptr, align 8, !tbaa !5
  store ptr %40, ptr %3, align 8
  br label %41

41:                                               ; preds = %39, %13
  %42 = load ptr, ptr %3, align 8
  ret ptr %42
}

attributes #0 = { 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 #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" }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, 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"

@strtok_x.ptr = external hidden local_unnamed_addr global ptr, align 8
@strtok_x.last_ptr = external hidden local_unnamed_addr global ptr, align 8
@strtok_x.temp_ptr = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strstr(ptr noundef, ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local ptr @strtok_x(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %3, label %.thread

.thread:                                          ; preds = %2
  store ptr %0, ptr @strtok_x.last_ptr, align 8, !tbaa !5
  br label %5

3:                                                ; preds = %2
  %.pr = load ptr, ptr @strtok_x.last_ptr, align 8, !tbaa !5
  %4 = icmp eq ptr %.pr, null
  br i1 %4, label %18, label %5

5:                                                ; preds = %.thread, %3
  %6 = phi ptr [ %0, %.thread ], [ %.pr, %3 ]
  %7 = tail call ptr @strstr(ptr noundef nonnull dereferenceable(1) %6, ptr noundef nonnull dereferenceable(1) %1) #2
  store ptr %7, ptr @strtok_x.ptr, align 8, !tbaa !5
  %.not8 = icmp eq ptr %7, null
  br i1 %.not8, label %13, label %8

8:                                                ; preds = %5
  store i8 0, ptr %7, align 1, !tbaa !9
  %9 = load ptr, ptr @strtok_x.last_ptr, align 8, !tbaa !5
  store ptr %9, ptr @strtok_x.temp_ptr, align 8, !tbaa !5
  %10 = load ptr, ptr @strtok_x.ptr, align 8, !tbaa !5
  %11 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #2
  %12 = getelementptr inbounds i8, ptr %10, i64 %11
  store ptr %12, ptr @strtok_x.last_ptr, align 8, !tbaa !5
  br label %18

13:                                               ; preds = %5
  %char0 = load i8, ptr %6, align 1
  %.not9 = icmp eq i8 %char0, 0
  br i1 %.not9, label %17, label %14

14:                                               ; preds = %13
  store ptr %6, ptr @strtok_x.temp_ptr, align 8, !tbaa !5
  %15 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %6) #2
  %16 = getelementptr inbounds i8, ptr %6, i64 %15
  store ptr %16, ptr @strtok_x.last_ptr, align 8, !tbaa !5
  br label %18

17:                                               ; preds = %13
  store ptr null, ptr @strtok_x.last_ptr, align 8, !tbaa !5
  store ptr null, ptr @strtok_x.temp_ptr, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %8, %17, %14, %3
  %.0 = phi ptr [ null, %3 ], [ %6, %14 ], [ null, %17 ], [ %9, %8 ]
  ret ptr %.0
}

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

!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 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass