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

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

@gfind.first = external hidden global i32, align 4
@gfind.ipfdirs_save = external hidden global ptr, align 8
@gfind.ipfenvlen = external hidden global i32, align 4
@gfind.ipfdirs = external hidden global ptr, align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@file = external hidden global [200 x i8], align 16

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

; Function Attrs: nounwind uwtable
define dso_local ptr @gfind(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %10 = load i32, ptr @gfind.first, align 4, !tbaa !9
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %31

12:                                               ; preds = %2
  store i32 0, ptr @gfind.first, align 4, !tbaa !9
  %13 = call ptr @getenv(ptr noundef @.str) #6
  store ptr %13, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %12
  store ptr @.str.1, ptr %6, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %16, %12
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = call i64 @strlen(ptr noundef %18) #7
  %20 = add i64 %19, 1
  %21 = trunc i64 %20 to i32
  store i32 %21, ptr @gfind.ipfenvlen, align 4, !tbaa !9
  %22 = load i32, ptr @gfind.ipfenvlen, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = call noalias ptr @malloc(i64 noundef %23) #8
  store ptr %24, ptr @gfind.ipfdirs, align 8, !tbaa !5
  %25 = load i32, ptr @gfind.ipfenvlen, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = call noalias ptr @malloc(i64 noundef %26) #8
  store ptr %27, ptr @gfind.ipfdirs_save, align 8, !tbaa !5
  %28 = load ptr, ptr @gfind.ipfdirs_save, align 8, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call ptr @strcpy(ptr noundef %28, ptr noundef %29) #6
  br label %31

31:                                               ; preds = %17, %2
  %32 = load i32, ptr @gfind.ipfenvlen, align 4, !tbaa !9
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %69

34:                                               ; preds = %31
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 0
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = sext i8 %37 to i32
  %39 = icmp ne i32 %38, 119
  br i1 %39, label %40, label %69

40:                                               ; preds = %34
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 0
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = sext i8 %43 to i32
  %45 = icmp ne i32 %44, 47
  br i1 %45, label %46, label %69

46:                                               ; preds = %40
  %47 = load ptr, ptr @gfind.ipfdirs, align 8, !tbaa !5
  %48 = load ptr, ptr @gfind.ipfdirs_save, align 8, !tbaa !5
  %49 = call ptr @strcpy(ptr noundef %47, ptr noundef %48) #6
  %50 = load ptr, ptr @gfind.ipfdirs, align 8, !tbaa !5
  %51 = call ptr @strtok(ptr noundef %50, ptr noundef @.str.2) #6
  store ptr %51, ptr %7, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %66, %46
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %68

55:                                               ; preds = %52
  store i8 0, ptr @file, align 16, !tbaa !11
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = call ptr @strcpy(ptr noundef @file, ptr noundef %56) #6
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = call ptr @strcat(ptr noundef @file, ptr noundef %58) #6
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = call noalias ptr @fopen(ptr noundef @file, ptr noundef %60)
  store ptr %61, ptr %8, align 8, !tbaa !5
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %66

63:                                               ; preds = %55
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = call i32 @fclose(ptr noundef %64)
  store ptr @file, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %70

66:                                               ; preds = %55
  %67 = call ptr @strtok(ptr noundef null, ptr noundef @.str.2) #6
  store ptr %67, ptr %7, align 8, !tbaa !5
  br label %52, !llvm.loop !12

68:                                               ; preds = %52
  br label %69

69:                                               ; preds = %68, %40, %34, %31
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %70

70:                                               ; preds = %69, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %71 = load ptr, ptr %3, align 8
  ret ptr %71
}

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

; 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 ptr @getenv(ptr noundef) #3

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #5

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind
declare ptr @strtok(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind
declare ptr @strcat(ptr noundef, ptr noundef) #3

declare i32 @fclose(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 "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 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 #5 = { nounwind allocsize(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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { nounwind allocsize(0) }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@gfind.first = external hidden local_unnamed_addr global i32, align 4
@gfind.ipfdirs_save = external hidden local_unnamed_addr global ptr, align 8
@gfind.ipfenvlen = external hidden local_unnamed_addr global i32, align 4
@gfind.ipfdirs = external hidden local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@file = external hidden global [200 x i8], align 16

; Function Attrs: nofree nounwind uwtable
define dso_local noundef ptr @gfind(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @gfind.first, align 4, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %._crit_edge, label %4

._crit_edge:                                      ; preds = %2
  %.pre = load i32, ptr @gfind.ipfenvlen, align 4, !tbaa !5
  br label %14

4:                                                ; preds = %2
  store i32 0, ptr @gfind.first, align 4, !tbaa !5
  %5 = tail call ptr @getenv(ptr noundef nonnull @.str) #7
  %6 = icmp eq ptr %5, null
  %spec.store.select = select i1 %6, ptr @.str.1, ptr %5
  %7 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %spec.store.select) #8
  %8 = trunc i64 %7 to i32
  %9 = add i32 %8, 1
  store i32 %9, ptr @gfind.ipfenvlen, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = tail call noalias ptr @malloc(i64 noundef %10) #9
  store ptr %11, ptr @gfind.ipfdirs, align 8, !tbaa !9
  %12 = tail call noalias ptr @malloc(i64 noundef %10) #9
  store ptr %12, ptr @gfind.ipfdirs_save, align 8, !tbaa !9
  %13 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) %spec.store.select) #7
  br label %14

14:                                               ; preds = %._crit_edge, %4
  %15 = phi i32 [ %.pre, %._crit_edge ], [ %9, %4 ]
  %.not13 = icmp eq i32 %15, 0
  br i1 %.not13, label %.loopexit, label %16

16:                                               ; preds = %14
  %17 = load i8, ptr %1, align 1, !tbaa !11
  %.not14 = icmp eq i8 %17, 119
  br i1 %.not14, label %.loopexit, label %18

18:                                               ; preds = %16
  %19 = load i8, ptr %0, align 1, !tbaa !11
  %.not15 = icmp eq i8 %19, 47
  br i1 %.not15, label %.loopexit, label %20

20:                                               ; preds = %18
  %21 = load ptr, ptr @gfind.ipfdirs, align 8, !tbaa !9
  %22 = load ptr, ptr @gfind.ipfdirs_save, align 8, !tbaa !9
  %23 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %21, ptr noundef nonnull dereferenceable(1) %22) #7
  %24 = load ptr, ptr @gfind.ipfdirs, align 8, !tbaa !9
  %25 = tail call ptr @strtok(ptr noundef %24, ptr noundef nonnull @.str.2) #7
  %.not1618 = icmp eq ptr %25, null
  br i1 %.not1618, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %20, %31
  %.01119 = phi ptr [ %32, %31 ], [ %25, %20 ]
  store i8 0, ptr @file, align 16, !tbaa !11
  %26 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) @file, ptr noundef nonnull dereferenceable(1) %.01119) #7
  %27 = tail call ptr @strcat(ptr noundef nonnull dereferenceable(1) @file, ptr noundef nonnull dereferenceable(1) %0) #7
  %28 = tail call noalias ptr @fopen(ptr noundef nonnull @file, ptr noundef nonnull %1)
  %.not17 = icmp eq ptr %28, null
  br i1 %.not17, label %31, label %29

29:                                               ; preds = %.lr.ph
  %30 = tail call i32 @fclose(ptr noundef nonnull %28)
  br label %.loopexit

31:                                               ; preds = %.lr.ph
  %32 = tail call ptr @strtok(ptr noundef null, ptr noundef nonnull @.str.2) #7
  %.not16 = icmp eq ptr %32, null
  br i1 %.not16, label %.loopexit, label %.lr.ph, !llvm.loop !12

.loopexit:                                        ; preds = %31, %20, %14, %16, %18, %29
  %.0 = phi ptr [ @file, %29 ], [ null, %18 ], [ null, %16 ], [ null, %14 ], [ null, %20 ], [ null, %31 ]
  ret ptr %.0
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: nofree nounwind memory(read)
declare noundef ptr @getenv(ptr nocapture noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #5

; Function Attrs: mustprogress nofree nounwind willreturn
declare ptr @strtok(ptr noundef, ptr nocapture noundef readonly) local_unnamed_addr #6

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcat(ptr noalias noundef returned, ptr noalias nocapture noundef readonly) local_unnamed_addr #5

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #1

attributes #0 = { nofree 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 = { nofree 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 = { nofree nounwind 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 = { 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 #4 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #5 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 #6 = { mustprogress nofree nounwind willreturn "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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { nounwind allocsize(0) }

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


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