; LLVM IR from kala13x/libxutils :: src/sys (xfs)

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

; 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 uwtable
declare dso_local zeroext i8 @XFile_IsOpen(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @XFile_Read(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @XFile_GetLine(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %16

13:                                               ; preds = %3
  %14 = load i64, ptr %7, align 8, !tbaa !9
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %17, label %16

16:                                               ; preds = %13, %3
  store i32 -2, ptr %4, align 4
  br label %60

17:                                               ; preds = %13
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 0
  store i8 0, ptr %19, align 1, !tbaa !11
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call zeroext i8 @XFile_IsOpen(ptr noundef %20)
  %22 = icmp ne i8 %21, 0
  br i1 %22, label %24, label %23

23:                                               ; preds = %17
  store i32 -1, ptr %4, align 4
  br label %60

24:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = trunc i64 %25 to i32
  %27 = sub nsw i32 %26, 1
  store i32 %27, ptr %8, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #2
  br label %28

28:                                               ; preds = %57, %24
  %29 = load i32, ptr %9, align 4, !tbaa !12
  %30 = load i32, ptr %8, align 4, !tbaa !12
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %32, label %58

32:                                               ; preds = %28
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = call i32 @XFile_Read(ptr noundef %33, ptr noundef %10, i64 noundef 1)
  %35 = icmp sle i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %32
  br label %58

37:                                               ; preds = %32
  %38 = load i8, ptr %10, align 1, !tbaa !11
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load i32, ptr %9, align 4, !tbaa !12
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %9, align 4, !tbaa !12
  %42 = sext i32 %40 to i64
  %43 = getelementptr inbounds i8, ptr %39, i64 %42
  store i8 %38, ptr %43, align 1, !tbaa !11
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load i32, ptr %9, align 4, !tbaa !12
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %44, i64 %46
  store i8 0, ptr %47, align 1, !tbaa !11
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load i32, ptr %9, align 4, !tbaa !12
  %50 = sub nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i8, ptr %48, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !11
  %54 = sext i8 %53 to i32
  %55 = icmp eq i32 %54, 10
  br i1 %55, label %56, label %57

56:                                               ; preds = %37
  br label %58

57:                                               ; preds = %37
  br label %28, !llvm.loop !14

58:                                               ; preds = %56, %36, %28
  %59 = load i32, ptr %9, align 4, !tbaa !12
  store i32 %59, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %60

60:                                               ; preds = %58, %23, %16
  %61 = load i32, ptr %4, align 4
  ret i32 %61
}

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @XFile_IsOpen(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @XFile_Read(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @XFile_GetLine(ptr noundef %0, ptr noundef writeonly %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = alloca i8, align 1
  %5 = icmp ne ptr %1, null
  %6 = icmp ne i64 %2, 0
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %7, label %22

7:                                                ; preds = %3
  store i8 0, ptr %1, align 1, !tbaa !5
  %8 = tail call zeroext i8 @XFile_IsOpen(ptr noundef %0)
  %.not = icmp eq i8 %8, 0
  br i1 %.not, label %22, label %9

9:                                                ; preds = %7
  %10 = trunc i64 %2 to i32
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #3
  %11 = tail call i32 @llvm.smax.i32(i32 %10, i32 1)
  %smax = add nsw i32 %11, -1
  %wide.trip.count = zext nneg i32 %smax to i64
  br label %12

12:                                               ; preds = %16, %9
  %indvars.iv = phi i64 [ %indvars.iv.next, %16 ], [ 0, %9 ]
  %exitcond.not = icmp eq i64 %indvars.iv, %wide.trip.count
  br i1 %exitcond.not, label %.split.loop.exit22, label %13

13:                                               ; preds = %12
  %14 = call i32 @XFile_Read(ptr noundef %0, ptr noundef nonnull %4, i64 noundef 1)
  %15 = icmp slt i32 %14, 1
  br i1 %15, label %.split.loop.exit20, label %16

16:                                               ; preds = %13
  %17 = load i8, ptr %4, align 1, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  store i8 %17, ptr %18, align 1, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next
  store i8 0, ptr %19, align 1, !tbaa !5
  %20 = icmp eq i8 %17, 10
  br i1 %20, label %.split.loop.exit, label %12, !llvm.loop !8

.split.loop.exit:                                 ; preds = %16
  %indvars.le = trunc i64 %indvars.iv.next to i32
  br label %.split.loop.exit22

.split.loop.exit20:                               ; preds = %13
  %21 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.split.loop.exit22

.split.loop.exit22:                               ; preds = %12, %.split.loop.exit20, %.split.loop.exit
  %.1 = phi i32 [ %indvars.le, %.split.loop.exit ], [ %21, %.split.loop.exit20 ], [ %smax, %12 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #3
  br label %22

22:                                               ; preds = %7, %3, %.split.loop.exit22
  %.016 = phi i32 [ %.1, %.split.loop.exit22 ], [ -2, %3 ], [ -1, %7 ]
  ret i32 %.016
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass