; LLVM IR from jspd-group/pegit :: src (file)

; 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.strbuf = type { i64, i64, ptr }
%struct.filespec = type { %struct.strbuf, ptr, i64, %struct.stat, %struct.filecache, [20 x i8], i64, %struct.strbuf, i32 }
%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.filecache = type { ptr }

@stderr = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [40 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

declare void @strbuf_init(ptr noundef, i64 noundef) #1

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

declare void @strbuf_release(ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @file_length(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @filespec_getfullpath(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @filespec_cachefile(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca %struct.strbuf, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.filespec, ptr %7, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = call i64 @file_length(ptr noundef %9)
  %11 = trunc i64 %10 to i32
  store i32 %11, ptr %4, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #4
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.filespec, ptr %12, i32 0, i32 4
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.filespec, ptr %14, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = load i32, ptr %4, align 4, !tbaa !17
  %18 = sext i32 %17 to i64
  %19 = call i32 @filecache_init_file(ptr noundef %13, ptr noundef %16, i64 noundef %18)
  %20 = icmp slt i32 %19, 0
  br i1 %20, label %21, label %27

21:                                               ; preds = %1
  call void @strbuf_init(ptr noundef %5, i64 noundef 0)
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  call void @filespec_getfullpath(ptr noundef %22, ptr noundef %5)
  %23 = load ptr, ptr @stderr, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.strbuf, ptr %5, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !18
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef @.str.4, ptr noundef %25) #4
  call void @strbuf_release(ptr noundef %5)
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %30

27:                                               ; preds = %1
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.filespec, ptr %28, i32 0, i32 8
  store i32 1, ptr %29, align 8, !tbaa !19
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %30

30:                                               ; preds = %27, %21
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %31 = load i32, ptr %2, align 4
  ret i32 %31
}

attributes #0 = { 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 #1 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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, !6, i64 24}
!10 = !{!"filespec", !11, i64 0, !6, i64 24, !12, i64 32, !13, i64 40, !16, i64 184, !7, i64 192, !12, i64 216, !11, i64 224, !14, i64 248}
!11 = !{!"strbuf", !12, i64 0, !12, i64 8, !6, i64 16}
!12 = !{!"long", !7, i64 0}
!13 = !{!"stat", !12, i64 0, !12, i64 8, !12, i64 16, !14, i64 24, !14, i64 28, !14, i64 32, !14, i64 36, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !15, i64 72, !15, i64 88, !15, i64 104, !7, i64 120}
!14 = !{!"int", !7, i64 0}
!15 = !{!"timespec", !12, i64 0, !12, i64 8}
!16 = !{!"filecache", !6, i64 0}
!17 = !{!14, !14, i64 0}
!18 = !{!11, !6, i64 16}
!19 = !{!10, !14, i64 248}


; 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.strbuf = type { i64, i64, ptr }

@stderr = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [40 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

declare void @strbuf_init(ptr noundef, i64 noundef) local_unnamed_addr #1

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

declare void @strbuf_release(ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @file_length(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @filespec_getfullpath(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @filespec_cachefile(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca %struct.strbuf, align 8
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = tail call i64 @file_length(ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #4
  %6 = getelementptr inbounds i8, ptr %0, i64 184
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %sext = shl i64 %5, 32
  %8 = ashr exact i64 %sext, 32
  %9 = tail call i32 @filecache_init_file(ptr noundef nonnull %6, ptr noundef %7, i64 noundef %8)
  %10 = icmp slt i32 %9, 0
  br i1 %10, label %11, label %16

11:                                               ; preds = %1
  call void @strbuf_init(ptr noundef nonnull %2, i64 noundef 0) #4
  call void @filespec_getfullpath(ptr noundef nonnull %0, ptr noundef nonnull %2)
  %12 = load ptr, ptr @stderr, align 8, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %2, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str.4, ptr noundef %14) #5
  call void @strbuf_release(ptr noundef nonnull %2) #4
  br label %18

16:                                               ; preds = %1
  %17 = getelementptr inbounds i8, ptr %0, i64 248
  store i32 1, ptr %17, align 8, !tbaa !18
  br label %18

18:                                               ; preds = %16, %11
  %.0 = phi i32 [ -1, %11 ], [ 0, %16 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #4
  ret i32 %.0
}

attributes #0 = { 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 #1 = { "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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind }
attributes #5 = { cold 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, !11, i64 24}
!6 = !{!"filespec", !7, i64 0, !11, i64 24, !8, i64 32, !12, i64 40, !15, i64 184, !9, i64 192, !8, i64 216, !7, i64 224, !13, i64 248}
!7 = !{!"strbuf", !8, i64 0, !8, i64 8, !11, i64 16}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"stat", !8, i64 0, !8, i64 8, !8, i64 16, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !8, i64 40, !8, i64 48, !8, i64 56, !8, i64 64, !14, i64 72, !14, i64 88, !14, i64 104, !9, i64 120}
!13 = !{!"int", !9, i64 0}
!14 = !{!"timespec", !8, i64 0, !8, i64 8}
!15 = !{!"filecache", !11, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!7, !11, i64 16}
!18 = !{!6, !13, i64 248}


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