; LLVM IR from ligurio/unreliablefs :: unreliablefs/tests (fsx)

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

@file_size = external dso_local global i64, align 8
@testcalls = external dso_local global i64, align 8
@simulatedopcount = external dso_local global i64, align 8
@debug = external dso_local global i32, align 4
@fd = external dso_local global i32, align 4
@.str.77 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.78 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.79 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.80 = external hidden unnamed_addr constant [15 x i8], align 1

; 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 void @prt(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
declare dso_local void @prterr(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @report_failure(i32 noundef) #1

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

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

declare i32 @msync(ptr noundef, i64 noundef, i32 noundef) #3

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

5:                                                ; preds = %0
  store i32 1, ptr %2, align 4
  br label %34

6:                                                ; preds = %0
  %7 = load i64, ptr @testcalls, align 8, !tbaa !5
  %8 = load i64, ptr @simulatedopcount, align 8, !tbaa !5
  %9 = icmp ule i64 %7, %8
  br i1 %9, label %10, label %11

10:                                               ; preds = %6
  store i32 1, ptr %2, align 4
  br label %34

11:                                               ; preds = %6
  %12 = load i32, ptr @debug, align 4, !tbaa !9
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %16

14:                                               ; preds = %11
  %15 = load i64, ptr @testcalls, align 8, !tbaa !5
  call void (ptr, ...) @prt(ptr noundef @.str.77, i64 noundef %15)
  br label %16

16:                                               ; preds = %14, %11
  %17 = load i64, ptr @file_size, align 8, !tbaa !5
  %18 = load i32, ptr @fd, align 4, !tbaa !9
  %19 = call ptr @mmap(ptr noundef null, i64 noundef %17, i32 noundef 3, i32 noundef 1, i32 noundef %18, i64 noundef 0) #4
  store ptr %19, ptr %1, align 8, !tbaa !11
  %20 = icmp eq ptr %19, inttoptr (i64 -1 to ptr)
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  call void @prterr(ptr noundef @.str.78)
  call void @report_failure(i32 noundef 205)
  br label %22

22:                                               ; preds = %21, %16
  %23 = load ptr, ptr %1, align 8, !tbaa !11
  %24 = call i32 @msync(ptr noundef %23, i64 noundef 0, i32 noundef 6)
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %22
  call void @prterr(ptr noundef @.str.79)
  call void @report_failure(i32 noundef 206)
  br label %27

27:                                               ; preds = %26, %22
  %28 = load ptr, ptr %1, align 8, !tbaa !11
  %29 = load i64, ptr @file_size, align 8, !tbaa !5
  %30 = call i32 @munmap(ptr noundef %28, i64 noundef %29) #4
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %27
  call void @prterr(ptr noundef @.str.80)
  call void @report_failure(i32 noundef 207)
  br label %33

33:                                               ; preds = %32, %27
  store i32 0, ptr %2, align 4
  br label %34

34:                                               ; preds = %33, %10, %5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  %35 = load i32, ptr %2, align 4
  switch i32 %35, label %37 [
    i32 0, label %36
    i32 1, label %36
  ]

36:                                               ; preds = %34, %34
  ret void

37:                                               ; preds = %34
  unreachable
}

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 = { "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 }

!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 = !{!"long", !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 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !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"

@file_size = external dso_local local_unnamed_addr global i64, align 8
@testcalls = external dso_local local_unnamed_addr global i64, align 8
@simulatedopcount = external dso_local local_unnamed_addr global i64, align 8
@debug = external dso_local local_unnamed_addr global i32, align 4
@fd = external dso_local local_unnamed_addr global i32, align 4
@.str.77 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.78 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.79 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.80 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @prt(ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @prterr(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @report_failure(i32 noundef) local_unnamed_addr #0

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

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

declare i32 @msync(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @doinvl() local_unnamed_addr #0 {
  %1 = load i64, ptr @file_size, align 8, !tbaa !5
  %2 = icmp eq i64 %1, 0
  br i1 %2, label %22, label %3

3:                                                ; preds = %0
  %4 = load i64, ptr @testcalls, align 8, !tbaa !5
  %5 = load i64, ptr @simulatedopcount, align 8, !tbaa !5
  %.not = icmp ugt i64 %4, %5
  br i1 %.not, label %6, label %22

6:                                                ; preds = %3
  %7 = load i32, ptr @debug, align 4, !tbaa !9
  %.not2 = icmp eq i32 %7, 0
  br i1 %.not2, label %9, label %8

8:                                                ; preds = %6
  tail call void (ptr, ...) @prt(ptr noundef nonnull @.str.77, i64 noundef %4)
  %.pre = load i64, ptr @file_size, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %8, %6
  %10 = phi i64 [ %.pre, %8 ], [ %1, %6 ]
  %11 = load i32, ptr @fd, align 4, !tbaa !9
  %12 = tail call ptr @mmap(ptr noundef null, i64 noundef %10, i32 noundef 3, i32 noundef 1, i32 noundef %11, i64 noundef 0) #3
  %13 = icmp eq ptr %12, inttoptr (i64 -1 to ptr)
  br i1 %13, label %14, label %15

14:                                               ; preds = %9
  tail call void @prterr(ptr noundef nonnull @.str.78)
  tail call void @report_failure(i32 noundef 205)
  br label %15

15:                                               ; preds = %14, %9
  %16 = tail call i32 @msync(ptr noundef %12, i64 noundef 0, i32 noundef 6) #3
  %.not3 = icmp eq i32 %16, 0
  br i1 %.not3, label %18, label %17

17:                                               ; preds = %15
  tail call void @prterr(ptr noundef nonnull @.str.79)
  tail call void @report_failure(i32 noundef 206)
  br label %18

18:                                               ; preds = %17, %15
  %19 = load i64, ptr @file_size, align 8, !tbaa !5
  %20 = tail call i32 @munmap(ptr noundef %12, i64 noundef %19) #3
  %.not4 = icmp eq i32 %20, 0
  br i1 %.not4, label %22, label %21

21:                                               ; preds = %18
  tail call void @prterr(ptr noundef nonnull @.str.80)
  tail call void @report_failure(i32 noundef 207)
  br label %22

22:                                               ; preds = %18, %21, %3, %0
  ret void
}

attributes #0 = { 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 = { 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 = { "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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


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