; LLVM IR from kmhofmann/selene :: selene/base/io (FileUtils)

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

@.str.1 = external hidden unnamed_addr constant [3 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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32)) #2 align 2

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

declare i32 @fclose(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN3sln19write_data_contentsERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPKhm(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef %1, i64 noundef %2) #3 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %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 ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %16) #4
  %18 = call noalias ptr @fopen(ptr noundef %17, ptr noundef @.str.1)
  store ptr %18, ptr %8, align 8, !tbaa !5
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %3
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %71

22:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 65535, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %23 = load i64, ptr %7, align 8, !tbaa !9
  %24 = udiv i64 %23, 65535
  store i64 %24, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = urem i64 %25, 65535
  store i64 %26, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %48, %22
  %28 = load i64, ptr %13, align 8, !tbaa !9
  %29 = load i64, ptr %11, align 8, !tbaa !9
  %30 = icmp ult i64 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  store i32 2, ptr %9, align 4
  br label %51

32:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load i64, ptr %13, align 8, !tbaa !9
  %35 = mul i64 %34, 65535
  %36 = getelementptr inbounds i8, ptr %33, i64 %35
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = call i64 @fwrite(ptr noundef %36, i64 noundef 1, i64 noundef 65535, ptr noundef %37)
  store i64 %38, ptr %14, align 8, !tbaa !9
  %39 = load i64, ptr %14, align 8, !tbaa !9
  %40 = icmp ne i64 %39, 65535
  br i1 %40, label %41, label %44

41:                                               ; preds = %32
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = call i32 @fclose(ptr noundef %42)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %45

44:                                               ; preds = %32
  store i32 0, ptr %9, align 4
  br label %45

45:                                               ; preds = %44, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  %46 = load i32, ptr %9, align 4
  switch i32 %46, label %51 [
    i32 0, label %47
  ]

47:                                               ; preds = %45
  br label %48

48:                                               ; preds = %47
  %49 = load i64, ptr %13, align 8, !tbaa !9
  %50 = add i64 %49, 1
  store i64 %50, ptr %13, align 8, !tbaa !9
  br label %27, !llvm.loop !11

51:                                               ; preds = %45, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  %52 = load i32, ptr %9, align 4
  switch i32 %52, label %70 [
    i32 2, label %53
  ]

53:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load i64, ptr %11, align 8, !tbaa !9
  %56 = mul i64 %55, 65535
  %57 = getelementptr inbounds i8, ptr %54, i64 %56
  %58 = load i64, ptr %12, align 8, !tbaa !9
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = call i64 @fwrite(ptr noundef %57, i64 noundef 1, i64 noundef %58, ptr noundef %59)
  store i64 %60, ptr %15, align 8, !tbaa !9
  %61 = load i64, ptr %15, align 8, !tbaa !9
  %62 = icmp ne i64 %61, 65535
  br i1 %62, label %63, label %66

63:                                               ; preds = %53
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = call i32 @fclose(ptr noundef %64)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %69

66:                                               ; preds = %53
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = call i32 @fclose(ptr noundef %67)
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %69

69:                                               ; preds = %66, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  br label %70

70:                                               ; preds = %69, %51
  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 8, ptr %10) #4
  br label %71

71:                                               ; preds = %70, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %72 = load i1, ptr %4, align 1
  ret i1 %72
}

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress 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 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3sln19write_data_contentsERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPKhm(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr nocapture noundef %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = tail call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #2
  %5 = tail call noalias ptr @fopen(ptr noundef %4, ptr noundef nonnull @.str.1)
  %6 = icmp eq ptr %5, null
  br i1 %6, label %19, label %7

7:                                                ; preds = %3
  %8 = udiv i64 %2, 65535
  %9 = urem i64 %2, 65535
  %.not2630.not = icmp ult i64 %2, 65535
  br i1 %.not2630.not, label %.critedge29, label %.critedge

10:                                               ; preds = %.critedge
  %11 = add nuw nsw i64 %.02431, 1
  %exitcond.not = icmp eq i64 %11, %8
  br i1 %exitcond.not, label %.critedge29, label %.critedge, !llvm.loop !5

.critedge:                                        ; preds = %7, %10
  %.02431 = phi i64 [ %11, %10 ], [ 0, %7 ]
  %12 = mul nuw i64 %.02431, 65535
  %13 = getelementptr inbounds i8, ptr %1, i64 %12
  %14 = tail call i64 @fwrite(ptr noundef %13, i64 noundef 1, i64 noundef 65535, ptr noundef nonnull %5)
  %.not = icmp eq i64 %14, 65535
  br i1 %.not, label %10, label %.sink.split

.critedge29:                                      ; preds = %10, %7
  %15 = mul nuw i64 %8, 65535
  %16 = getelementptr inbounds i8, ptr %1, i64 %15
  %17 = tail call i64 @fwrite(ptr noundef %16, i64 noundef 1, i64 noundef %9, ptr noundef nonnull %5)
  %.not27 = icmp eq i64 %17, 65535
  br label %.sink.split

.sink.split:                                      ; preds = %.critedge, %.critedge29
  %.5.ph = phi i1 [ %.not27, %.critedge29 ], [ false, %.critedge ]
  %18 = tail call i32 @fclose(ptr noundef nonnull %5)
  br label %19

19:                                               ; preds = %.sink.split, %3
  %.5 = phi i1 [ false, %3 ], [ %.5.ph, %.sink.split ]
  ret i1 %.5
}

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #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 = { mustprogress 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass