; LLVM IR from holzschu/ios_system :: text_cmds/csplit (csplit)

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

@infn = external dso_local global ptr, align 8
@infile = external dso_local global ptr, align 8
@.str.11 = external hidden unnamed_addr constant [3 x i8], align 1
@lineno = external dso_local global i64, align 8
@overfile = external dso_local global ptr, align 8
@csplit_getline.lbuf = external hidden global [2048 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: noreturn
declare void @err(i32 noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @csplit_getline() #2 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %4 = load ptr, ptr @overfile, align 8, !tbaa !5
  %5 = icmp ne ptr %4, null
  br i1 %5, label %6, label %8

6:                                                ; preds = %0
  %7 = load ptr, ptr @overfile, align 8, !tbaa !5
  br label %10

8:                                                ; preds = %0
  %9 = load ptr, ptr @infile, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %8, %6
  %11 = phi ptr [ %7, %6 ], [ %9, %8 ]
  store ptr %11, ptr %2, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %20, %10
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = call ptr @fgets(ptr noundef @csplit_getline.lbuf, i32 noundef 2048, ptr noundef %13)
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %23

16:                                               ; preds = %12
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = load ptr, ptr @overfile, align 8, !tbaa !5
  %19 = icmp eq ptr %17, %18
  br i1 %19, label %20, label %22

20:                                               ; preds = %16
  %21 = load ptr, ptr @infile, align 8, !tbaa !5
  store ptr %21, ptr %2, align 8, !tbaa !5
  br label %12

22:                                               ; preds = %16
  store ptr null, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %32

23:                                               ; preds = %12
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = call i32 @ferror(ptr noundef %24) #5
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %23
  %28 = load ptr, ptr @infn, align 8, !tbaa !5
  call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef @.str.11, ptr noundef %28) #6
  unreachable

29:                                               ; preds = %23
  %30 = load i64, ptr @lineno, align 8, !tbaa !9
  %31 = add nsw i64 %30, 1
  store i64 %31, ptr @lineno, align 8, !tbaa !9
  store ptr @csplit_getline.lbuf, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %32

32:                                               ; preds = %29, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  %33 = load ptr, ptr %1, align 8
  ret ptr %33
}

declare ptr @fgets(ptr noundef, i32 noundef, ptr noundef) #3

; Function Attrs: nounwind
declare i32 @ferror(ptr noundef) #4

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

!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 = !{!"long", !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"

@infn = external dso_local local_unnamed_addr global ptr, align 8
@infile = external dso_local local_unnamed_addr global ptr, align 8
@.str.11 = external hidden unnamed_addr constant [3 x i8], align 1
@lineno = external dso_local local_unnamed_addr global i64, align 8
@overfile = external dso_local local_unnamed_addr global ptr, align 8
@csplit_getline.lbuf = external hidden global [2048 x i8], align 16

; Function Attrs: noreturn
declare void @err(i32 noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @csplit_getline() local_unnamed_addr #1 {
  %1 = load ptr, ptr @overfile, align 8
  %.not = icmp eq ptr %1, null
  %2 = load ptr, ptr @infile, align 8
  %3 = select i1 %.not, ptr %2, ptr %1
  %4 = tail call ptr @fgets(ptr noundef nonnull @csplit_getline.lbuf, i32 noundef 2048, ptr noundef %3)
  %5 = icmp eq ptr %4, null
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %8
  %.07 = phi ptr [ %9, %8 ], [ %3, %0 ]
  %6 = load ptr, ptr @overfile, align 8, !tbaa !5
  %7 = icmp eq ptr %.07, %6
  br i1 %7, label %8, label %.loopexit

8:                                                ; preds = %.lr.ph
  %9 = load ptr, ptr @infile, align 8, !tbaa !5
  %10 = tail call ptr @fgets(ptr noundef nonnull @csplit_getline.lbuf, i32 noundef 2048, ptr noundef %9)
  %11 = icmp eq ptr %10, null
  br i1 %11, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %8, %0
  %.0.lcssa = phi ptr [ %3, %0 ], [ %9, %8 ]
  %12 = tail call i32 @ferror(ptr noundef %.0.lcssa) #4
  %.not5 = icmp eq i32 %12, 0
  br i1 %.not5, label %15, label %13

13:                                               ; preds = %._crit_edge
  %14 = load ptr, ptr @infn, align 8, !tbaa !5
  tail call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef nonnull @.str.11, ptr noundef %14) #5
  unreachable

15:                                               ; preds = %._crit_edge
  %16 = load i64, ptr @lineno, align 8, !tbaa !9
  %17 = add nsw i64 %16, 1
  store i64 %17, ptr @lineno, align 8, !tbaa !9
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %15
  %.04 = phi ptr [ @csplit_getline.lbuf, %15 ], [ null, %.lr.ph ]
  ret ptr %.04
}

; Function Attrs: nofree nounwind
declare noundef ptr @fgets(ptr noundef, i32 noundef, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind memory(read)
declare noundef i32 @ferror(ptr nocapture noundef) local_unnamed_addr #3

attributes #0 = { noreturn "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 = { 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 #3 = { 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 #4 = { nounwind }
attributes #5 = { noreturn 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}


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