; LLVM IR from InductiveComputerScience/infracore :: drivers/disk-linux-file (disk-linux-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.DiskStructure = type { ptr }
%struct.DiskStructureLinux = type { i32, %union.sem_t, ptr, i64, i64 }
%union.sem_t = type { i64, [24 x i8] }

; 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
define dso_local zeroext i1 @Write(ptr noundef %0, double noundef %1, ptr noundef %2, i64 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i8, align 1
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.DiskStructure, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  store ptr %18, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.DiskStructureLinux, ptr %19, i32 0, i32 4
  %21 = load i64, ptr %20, align 8, !tbaa !15
  store i64 %21, ptr %15, align 8, !tbaa !11
  %22 = load double, ptr %6, align 8, !tbaa !9
  %23 = fptoui double %22 to i64
  store i64 %23, ptr %14, align 8, !tbaa !11
  store i8 1, ptr %10, align 1, !tbaa !18
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.DiskStructureLinux, ptr %24, i32 0, i32 1
  %26 = call i32 @sem_wait(ptr noundef %25)
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.DiskStructureLinux, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !20
  %30 = load i64, ptr %14, align 8, !tbaa !11
  %31 = load i64, ptr %15, align 8, !tbaa !11
  %32 = mul i64 %30, %31
  %33 = call i64 @sys_lseek(i32 noundef %29, i64 noundef %32, i32 noundef 0)
  store i64 %33, ptr %13, align 8, !tbaa !11
  %34 = load i64, ptr %13, align 8, !tbaa !11
  %35 = icmp ne i64 %34, -1
  br i1 %35, label %36, label %82

36:                                               ; preds = %4
  store i64 0, ptr %12, align 8, !tbaa !11
  br label %37

37:                                               ; preds = %67, %36
  %38 = load i64, ptr %12, align 8, !tbaa !11
  %39 = load i64, ptr %15, align 8, !tbaa !11
  %40 = icmp ult i64 %38, %39
  br i1 %40, label %41, label %44

41:                                               ; preds = %37
  %42 = load i8, ptr %10, align 1, !tbaa !18, !range !21, !noundef !22
  %43 = trunc i8 %42 to i1
  br label %44

44:                                               ; preds = %41, %37
  %45 = phi i1 [ false, %37 ], [ %43, %41 ]
  br i1 %45, label %46, label %68

46:                                               ; preds = %44
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.DiskStructureLinux, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 8, !tbaa !20
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load i64, ptr %12, align 8, !tbaa !11
  %52 = getelementptr inbounds i8, ptr %50, i64 %51
  %53 = load i64, ptr %15, align 8, !tbaa !11
  %54 = load i64, ptr %12, align 8, !tbaa !11
  %55 = sub i64 %53, %54
  %56 = call i64 @sys_write(i32 noundef %49, ptr noundef %52, i64 noundef %55)
  store i64 %56, ptr %11, align 8, !tbaa !11
  %57 = load i64, ptr %11, align 8, !tbaa !11
  %58 = icmp ne i64 %57, 0
  br i1 %58, label %59, label %66

59:                                               ; preds = %46
  %60 = load i64, ptr %11, align 8, !tbaa !11
  %61 = icmp slt i64 %60, 0
  br i1 %61, label %62, label %66

62:                                               ; preds = %59
  %63 = load i64, ptr %11, align 8, !tbaa !11
  %64 = load i64, ptr %12, align 8, !tbaa !11
  %65 = add nsw i64 %64, %63
  store i64 %65, ptr %12, align 8, !tbaa !11
  br label %67

66:                                               ; preds = %59, %46
  store i8 0, ptr %10, align 1, !tbaa !18
  br label %67

67:                                               ; preds = %66, %62
  br label %37, !llvm.loop !23

68:                                               ; preds = %44
  %69 = load i8, ptr %10, align 1, !tbaa !18, !range !21, !noundef !22
  %70 = trunc i8 %69 to i1
  br i1 %70, label %71, label %81

71:                                               ; preds = %68
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.DiskStructureLinux, ptr %72, i32 0, i32 0
  %74 = load i32, ptr %73, align 8, !tbaa !20
  %75 = call i32 @sys_fsync(i32 noundef %74)
  %76 = sext i32 %75 to i64
  store i64 %76, ptr %11, align 8, !tbaa !11
  %77 = load i64, ptr %11, align 8, !tbaa !11
  %78 = icmp eq i64 %77, 0
  br i1 %78, label %79, label %80

79:                                               ; preds = %71
  store i8 1, ptr %10, align 1, !tbaa !18
  br label %80

80:                                               ; preds = %79, %71
  br label %81

81:                                               ; preds = %80, %68
  br label %82

82:                                               ; preds = %81, %4
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.DiskStructureLinux, ptr %83, i32 0, i32 1
  %85 = call i32 @sem_post(ptr noundef %84) #4
  %86 = load i8, ptr %10, align 1, !tbaa !18, !range !21, !noundef !22
  %87 = trunc i8 %86 to i1
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret i1 %87
}

declare i32 @sem_wait(ptr noundef) #2

declare i64 @sys_lseek(i32 noundef, i64 noundef, i32 noundef) #2

declare i64 @sys_write(i32 noundef, ptr noundef, i64 noundef) #2

declare i32 @sys_fsync(i32 noundef) #2

; Function Attrs: nounwind
declare i32 @sem_post(ptr noundef) #3

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 = { "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 "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"DiskStructure", !6, i64 0}
!15 = !{!16, !12, i64 56}
!16 = !{!"DiskStructureLinux", !17, i64 0, !7, i64 8, !6, i64 40, !12, i64 48, !12, i64 56}
!17 = !{!"int", !7, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"_Bool", !7, i64 0}
!20 = !{!16, !17, i64 0}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = distinct !{!23, !24}
!24 = !{!"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: nounwind uwtable
define dso_local zeroext i1 @Write(ptr nocapture noundef readonly %0, double noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 56
  %7 = load i64, ptr %6, align 8, !tbaa !10
  %8 = fptoui double %1 to i64
  %9 = getelementptr inbounds i8, ptr %5, i64 8
  %10 = tail call i32 @sem_wait(ptr noundef nonnull %9) #4
  %11 = load i32, ptr %5, align 8, !tbaa !14
  %12 = mul i64 %7, %8
  %13 = tail call i64 @sys_lseek(i32 noundef %11, i64 noundef %12, i32 noundef 0) #4
  %.not = icmp eq i64 %13, -1
  br i1 %.not, label %26, label %.preheader

.preheader:                                       ; preds = %4
  %.not32 = icmp eq i64 %7, 0
  br i1 %.not32, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.030 = phi i8 [ %.1, %.lr.ph ], [ 1, %.preheader ]
  %.02529 = phi i64 [ %.126, %.lr.ph ], [ 0, %.preheader ]
  %14 = load i32, ptr %5, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %2, i64 %.02529
  %16 = sub i64 %7, %.02529
  %17 = tail call i64 @sys_write(i32 noundef %14, ptr noundef %15, i64 noundef %16) #4
  %18 = icmp slt i64 %17, 0
  %19 = tail call i64 @llvm.smin.i64(i64 %17, i64 0)
  %.126 = add nsw i64 %19, %.02529
  %.1 = select i1 %18, i8 %.030, i8 0
  %20 = icmp ult i64 %.126, %7
  %21 = trunc nuw i8 %.1 to i1
  %22 = select i1 %20, i1 %21, i1 false
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph
  br i1 %21, label %._crit_edge.thread, label %26

._crit_edge.thread:                               ; preds = %.preheader, %._crit_edge
  %.0.lcssa36 = phi i8 [ %.1, %._crit_edge ], [ 1, %.preheader ]
  %23 = load i32, ptr %5, align 8, !tbaa !14
  %24 = tail call i32 @sys_fsync(i32 noundef %23) #4
  %25 = icmp eq i32 %24, 0
  %spec.select = select i1 %25, i8 1, i8 %.0.lcssa36
  br label %26

26:                                               ; preds = %._crit_edge.thread, %._crit_edge, %4
  %.2 = phi i8 [ %.1, %._crit_edge ], [ 1, %4 ], [ %spec.select, %._crit_edge.thread ]
  %27 = tail call i32 @sem_post(ptr noundef nonnull %9) #4
  %28 = trunc nuw i8 %.2 to i1
  ret i1 %28
}

declare i32 @sem_wait(ptr noundef) local_unnamed_addr #1

declare i64 @sys_lseek(i32 noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

declare i64 @sys_write(i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare i32 @sys_fsync(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @sem_post(ptr noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #3

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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 0}
!6 = !{!"DiskStructure", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !13, i64 56}
!11 = !{!"DiskStructureLinux", !12, i64 0, !8, i64 8, !7, i64 40, !13, i64 48, !13, i64 56}
!12 = !{!"int", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!11, !12, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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