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

%struct.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }
%struct.XFile = type { i64, i32, i64, i64, i8, i8, i32, i32 }

; 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
define dso_local i32 @XFile_GetStats(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca %struct.stat, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = call zeroext i8 @XFile_IsOpen(ptr noundef %6)
  %8 = icmp ne i8 %7, 0
  br i1 %8, label %10, label %9

9:                                                ; preds = %1
  store i32 -1, ptr %2, align 4
  br label %44

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 144, ptr %4) #3
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.XFile, ptr %11, i32 0, i32 7
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = call i32 @fstat(i32 noundef %13, ptr noundef %4) #3
  %15 = icmp slt i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %10
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %43

17:                                               ; preds = %10
  %18 = getelementptr inbounds %struct.stat, ptr %4, i32 0, i32 9
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = icmp ne i64 %19, 0
  br i1 %20, label %21, label %24

21:                                               ; preds = %17
  %22 = getelementptr inbounds %struct.stat, ptr %4, i32 0, i32 9
  %23 = load i64, ptr %22, align 8, !tbaa !13
  br label %25

24:                                               ; preds = %17
  br label %25

25:                                               ; preds = %24, %21
  %26 = phi i64 [ %23, %21 ], [ 4096, %24 ]
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.XFile, ptr %27, i32 0, i32 2
  store i64 %26, ptr %28, align 8, !tbaa !16
  %29 = getelementptr inbounds %struct.stat, ptr %4, i32 0, i32 3
  %30 = load i32, ptr %29, align 8, !tbaa !17
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.XFile, ptr %31, i32 0, i32 1
  store i32 %30, ptr %32, align 8, !tbaa !18
  %33 = getelementptr inbounds %struct.stat, ptr %4, i32 0, i32 8
  %34 = load i64, ptr %33, align 8, !tbaa !19
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.XFile, ptr %35, i32 0, i32 3
  store i64 %34, ptr %36, align 8, !tbaa !20
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.XFile, ptr %37, i32 0, i32 3
  %39 = load i64, ptr %38, align 8, !tbaa !20
  %40 = icmp ne i64 %39, 0
  %41 = zext i1 %40 to i64
  %42 = select i1 %40, i32 1, i32 0
  store i32 %42, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %43

43:                                               ; preds = %25, %16
  call void @llvm.lifetime.end.p0(i64 144, ptr %4) #3
  br label %44

44:                                               ; preds = %43, %9
  %45 = load i32, ptr %2, align 4
  ret i32 %45
}

; Function Attrs: nounwind
declare i32 @fstat(i32 noundef, 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 = { 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 = { 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, !12, i64 40}
!10 = !{!"XFile", !11, i64 0, !12, i64 8, !11, i64 16, !11, i64 24, !7, i64 32, !7, i64 33, !12, i64 36, !12, i64 40}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !11, i64 56}
!14 = !{!"stat", !11, i64 0, !11, i64 8, !11, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !15, i64 72, !15, i64 88, !15, i64 104, !7, i64 120}
!15 = !{!"timespec", !11, i64 0, !11, i64 8}
!16 = !{!10, !11, i64 16}
!17 = !{!14, !12, i64 24}
!18 = !{!10, !12, i64 8}
!19 = !{!14, !11, i64 48}
!20 = !{!10, !11, i64 24}


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

%struct.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }

; 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
define dso_local range(i32 -1, 2) i32 @XFile_GetStats(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca %struct.stat, align 8
  %3 = tail call zeroext i8 @XFile_IsOpen(ptr noundef %0)
  %.not = icmp eq i8 %3, 0
  br i1 %.not, label %22, label %4

4:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %2) #3
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = call i32 @fstat(i32 noundef %6, ptr noundef nonnull %2) #3
  %8 = icmp slt i32 %7, 0
  br i1 %8, label %21, label %9

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %2, i64 56
  %11 = load i64, ptr %10, align 8
  %.not6 = icmp eq i64 %11, 0
  %12 = select i1 %.not6, i64 4096, i64 %11
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %12, ptr %13, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %2, i64 24
  %15 = load i32, ptr %14, align 8, !tbaa !12
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %15, ptr %16, align 8, !tbaa !15
  %17 = getelementptr inbounds i8, ptr %2, i64 48
  %18 = load i64, ptr %17, align 8, !tbaa !16
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %18, ptr %19, align 8, !tbaa !17
  %.not7 = icmp ne i64 %18, 0
  %20 = zext i1 %.not7 to i32
  br label %21

21:                                               ; preds = %4, %9
  %.0 = phi i32 [ %20, %9 ], [ -1, %4 ]
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %2) #3
  br label %22

22:                                               ; preds = %1, %21
  %.1 = phi i32 [ %.0, %21 ], [ -1, %1 ]
  ret i32 %.1
}

; Function Attrs: nofree nounwind
declare noundef i32 @fstat(i32 noundef, ptr nocapture noundef) local_unnamed_addr #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 = { 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 = { 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, !10, i64 40}
!6 = !{!"XFile", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !8, i64 32, !8, i64 33, !10, i64 36, !10, i64 40}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 16}
!12 = !{!13, !10, i64 24}
!13 = !{!"stat", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !14, i64 72, !14, i64 88, !14, i64 104, !8, i64 120}
!14 = !{!"timespec", !7, i64 0, !7, i64 8}
!15 = !{!6, !10, i64 8}
!16 = !{!13, !7, i64 48}
!17 = !{!6, !7, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass