; LLVM IR from Angold-4/chainsaw :: src/debug/editor.ll (ZN6Editor4saveER12editorConfig)

; 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.editorConfig = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, i32, ptr, [80 x i8], %"class.std::__cxx11::basic_string", i8, i64 }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@.str.36 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [30 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

declare i64 @write(i32 noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6Editor16SetStatusMessageEPKcz(ptr noundef nonnull align 8 dereferenceable(448), ptr noundef, ...) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6Editor4saveER12editorConfig(ptr noundef nonnull align 8 dereferenceable(448) %0, ptr noundef nonnull align 8 dereferenceable(192) %1) #4 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call noundef ptr @_ZN6Editor12RowsToStringEPiR12editorConfig(ptr noundef nonnull align 8 dereferenceable(448) %10, ptr noundef %6, ptr noundef nonnull align 8 dereferenceable(192) %11)
  store ptr %12, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.editorConfig, ptr %13, i32 0, i32 12
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = call i32 (ptr, i32, ...) @open(ptr noundef %15, i32 noundef 66, i32 noundef 420)
  store i32 %16, ptr %8, align 4, !tbaa !16
  %17 = load i32, ptr %8, align 4, !tbaa !16
  %18 = icmp eq i32 %17, -1
  br i1 %18, label %19, label %20

19:                                               ; preds = %2
  br label %44

20:                                               ; preds = %2
  %21 = load i32, ptr %8, align 4, !tbaa !16
  %22 = load i32, ptr %6, align 4, !tbaa !16
  %23 = sext i32 %22 to i64
  %24 = call i32 @ftruncate(i32 noundef %21, i64 noundef %23) #6
  %25 = icmp eq i32 %24, -1
  br i1 %25, label %26, label %27

26:                                               ; preds = %20
  br label %44

27:                                               ; preds = %20
  %28 = load i32, ptr %8, align 4, !tbaa !16
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load i32, ptr %6, align 4, !tbaa !16
  %31 = sext i32 %30 to i64
  %32 = call i64 @write(i32 noundef %28, ptr noundef %29, i64 noundef %31)
  %33 = load i32, ptr %6, align 4, !tbaa !16
  %34 = sext i32 %33 to i64
  %35 = icmp ne i64 %32, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %27
  br label %44

37:                                               ; preds = %27
  %38 = load i32, ptr %8, align 4, !tbaa !16
  %39 = call i32 @close(i32 noundef %38)
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free(ptr noundef %40) #6
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.editorConfig, ptr %41, i32 0, i32 11
  store i32 0, ptr %42, align 8, !tbaa !17
  %43 = load i32, ptr %6, align 4, !tbaa !16
  call void (ptr, ptr, ...) @_ZN6Editor16SetStatusMessageEPKcz(ptr noundef nonnull align 8 dereferenceable(448) %10, ptr noundef @.str.36, i32 noundef %43)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %58

44:                                               ; preds = %36, %26, %19
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  call void @free(ptr noundef %45) #6
  %46 = load i32, ptr %8, align 4, !tbaa !16
  %47 = icmp ne i32 %46, -1
  br i1 %47, label %48, label %51

48:                                               ; preds = %44
  %49 = load i32, ptr %8, align 4, !tbaa !16
  %50 = call i32 @close(i32 noundef %49)
  br label %51

51:                                               ; preds = %48, %44
  %52 = call ptr @__errno_location() #7
  %53 = load i32, ptr %52, align 4, !tbaa !16
  %54 = call ptr @strerror(i32 noundef %53) #6
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.editorConfig, ptr %55, i32 0, i32 12
  %57 = load ptr, ptr %56, align 8, !tbaa !9
  call void (ptr, ptr, ...) @_ZN6Editor16SetStatusMessageEPKcz(ptr noundef nonnull align 8 dereferenceable(448) %10, ptr noundef @.str.37, ptr noundef %54, ptr noundef %57)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %58

58:                                               ; preds = %51, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  %59 = load i32, ptr %3, align 4
  ret i32 %59
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN6Editor12RowsToStringEPiR12editorConfig(ptr noundef nonnull align 8 dereferenceable(448), ptr noundef, ptr noundef nonnull align 8 dereferenceable(192)) #3 align 2

declare i32 @open(ptr noundef, i32 noundef, ...) #1

; Function Attrs: nounwind
declare i32 @ftruncate(i32 noundef, i64 noundef) #5

declare i32 @close(i32 noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #5

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #5

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 = { nounwind willreturn memory(none) "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 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 #4 = { 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(none) }

!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, !6, i64 56}
!10 = !{!"_ZTS12editorConfig", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !6, i64 40, !11, i64 48, !6, i64 56, !7, i64 64, !12, i64 144, !15, i64 176, !14, i64 184}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !13, i64 0, !14, i64 8, !7, i64 16}
!13 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!10, !11, i64 48}


; 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.36 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [30 x i8], align 1

; 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: nofree
declare noundef i64 @write(i32 noundef, ptr nocapture noundef readonly, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6Editor16SetStatusMessageEPKcz(ptr noundef nonnull align 8 dereferenceable(448), ptr noundef, ...) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN6Editor4saveER12editorConfig(ptr noundef nonnull align 8 dereferenceable(448) %0, ptr noundef nonnull align 8 dereferenceable(192) %1) local_unnamed_addr #4 align 2 {
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #8
  %4 = call noundef ptr @_ZN6Editor12RowsToStringEPiR12editorConfig(ptr noundef nonnull align 8 dereferenceable(448) %0, ptr noundef nonnull %3, ptr noundef nonnull align 8 dereferenceable(192) %1)
  %5 = getelementptr inbounds i8, ptr %1, i64 56
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = call i32 (ptr, i32, ...) @open(ptr noundef %6, i32 noundef 66, i32 noundef 420)
  %8 = icmp eq i32 %7, -1
  br i1 %8, label %24, label %9

9:                                                ; preds = %2
  %10 = load i32, ptr %3, align 4, !tbaa !15
  %11 = sext i32 %10 to i64
  %12 = call i32 @ftruncate(i32 noundef %7, i64 noundef %11) #8
  %13 = icmp eq i32 %12, -1
  br i1 %13, label %25, label %14

14:                                               ; preds = %9
  %15 = load i32, ptr %3, align 4, !tbaa !15
  %16 = sext i32 %15 to i64
  %17 = call i64 @write(i32 noundef %7, ptr noundef %4, i64 noundef %16)
  %18 = load i32, ptr %3, align 4, !tbaa !15
  %19 = sext i32 %18 to i64
  %.not = icmp eq i64 %17, %19
  br i1 %.not, label %20, label %25

20:                                               ; preds = %14
  %21 = call i32 @close(i32 noundef %7)
  call void @free(ptr noundef %4) #8
  %22 = getelementptr inbounds i8, ptr %1, i64 48
  store i32 0, ptr %22, align 8, !tbaa !16
  %23 = load i32, ptr %3, align 4, !tbaa !15
  call void (ptr, ptr, ...) @_ZN6Editor16SetStatusMessageEPKcz(ptr noundef nonnull align 8 dereferenceable(448) %0, ptr noundef nonnull @.str.36, i32 noundef %23)
  br label %32

24:                                               ; preds = %2
  call void @free(ptr noundef %4) #8
  br label %27

25:                                               ; preds = %14, %9
  call void @free(ptr noundef %4) #8
  %26 = call i32 @close(i32 noundef %7)
  br label %27

27:                                               ; preds = %24, %25
  %28 = tail call ptr @__errno_location() #9
  %29 = load i32, ptr %28, align 4, !tbaa !15
  %30 = call ptr @strerror(i32 noundef %29) #8
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  call void (ptr, ptr, ...) @_ZN6Editor16SetStatusMessageEPKcz(ptr noundef nonnull align 8 dereferenceable(448) %0, ptr noundef nonnull @.str.37, ptr noundef %30, ptr noundef %31)
  br label %32

32:                                               ; preds = %27, %20
  %.0 = phi i32 [ 1, %27 ], [ 0, %20 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #8
  ret i32 %.0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN6Editor12RowsToStringEPiR12editorConfig(ptr noundef nonnull align 8 dereferenceable(448), ptr noundef, ptr noundef nonnull align 8 dereferenceable(192)) local_unnamed_addr #3 align 2

; Function Attrs: nofree
declare noundef i32 @open(ptr nocapture noundef readonly, i32 noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @ftruncate(i32 noundef, i64 noundef) local_unnamed_addr #5

declare i32 @close(i32 noundef) local_unnamed_addr #6

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #7

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #5

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree "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 nofree nosync nounwind willreturn memory(none) "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 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 #4 = { 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 #5 = { 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 #6 = { "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 #7 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #8 = { nounwind }
attributes #9 = { nounwind willreturn memory(none) }

!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 56}
!6 = !{!"_ZTS12editorConfig", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !10, i64 40, !7, i64 48, !10, i64 56, !8, i64 64, !11, i64 144, !14, i64 176, !13, i64 184}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !12, i64 0, !13, i64 8, !8, i64 16}
!12 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !10, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!"bool", !8, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!6, !7, i64 48}


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