; LLVM IR from fhanau/Efficient-Compression-Tool :: src/leanify/leanify.ll (ZN4FileC2EPKc)

; 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.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 }
%class.File = type { i32, ptr, i64 }

@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4FileC2EPKc(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1) unnamed_addr #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.stat, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  %8 = getelementptr inbounds %class.File, ptr %7, i32 0, i32 1
  store ptr null, ptr %8, align 8, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call i32 (ptr, i32, ...) @open(ptr noundef %9, i32 noundef 2)
  %11 = getelementptr inbounds %class.File, ptr %7, i32 0, i32 0
  store i32 %10, ptr %11, align 8, !tbaa !13
  %12 = getelementptr inbounds %class.File, ptr %7, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %14 = icmp eq i32 %13, -1
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  call void @perror(ptr noundef @.str)
  br label %40

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 144, ptr %5) #4
  %17 = getelementptr inbounds %class.File, ptr %7, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %19 = call i32 @fstat(i32 noundef %18, ptr noundef %5) #4
  %20 = icmp eq i32 %19, -1
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  call void @perror(ptr noundef @.str.1)
  store i32 1, ptr %6, align 4
  br label %38

22:                                               ; preds = %16
  %23 = getelementptr inbounds %struct.stat, ptr %5, i32 0, i32 8
  %24 = load i64, ptr %23, align 8, !tbaa !14
  %25 = getelementptr inbounds %class.File, ptr %7, i32 0, i32 2
  store i64 %24, ptr %25, align 8, !tbaa !17
  %26 = getelementptr inbounds %class.File, ptr %7, i32 0, i32 2
  %27 = load i64, ptr %26, align 8, !tbaa !17
  %28 = getelementptr inbounds %class.File, ptr %7, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !13
  %30 = call ptr @mmap(ptr noundef null, i64 noundef %27, i32 noundef 3, i32 noundef 2, i32 noundef %29, i64 noundef 0) #4
  %31 = getelementptr inbounds %class.File, ptr %7, i32 0, i32 1
  store ptr %30, ptr %31, align 8, !tbaa !9
  %32 = getelementptr inbounds %class.File, ptr %7, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = icmp eq ptr %33, inttoptr (i64 -1 to ptr)
  br i1 %34, label %35, label %37

35:                                               ; preds = %22
  call void @perror(ptr noundef @.str.2)
  %36 = getelementptr inbounds %class.File, ptr %7, i32 0, i32 1
  store ptr null, ptr %36, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %35, %22
  store i32 0, ptr %6, align 4
  br label %38

38:                                               ; preds = %37, %21
  call void @llvm.lifetime.end.p0(i64 144, ptr %5) #4
  %39 = load i32, ptr %6, align 4
  switch i32 %39, label %41 [
    i32 0, label %40
    i32 1, label %40
  ]

40:                                               ; preds = %38, %38, %15
  ret void

41:                                               ; preds = %38
  unreachable
}

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

declare void @perror(ptr noundef) #1

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

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

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

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

attributes #0 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTS4File", !11, i64 0, !6, i64 8, !12, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !11, i64 0}
!14 = !{!15, !12, i64 48}
!15 = !{!"_ZTS4stat", !12, i64 0, !12, i64 8, !12, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !16, i64 72, !16, i64 88, !16, i64 104, !7, i64 120}
!16 = !{!"_ZTS8timespec", !12, i64 0, !12, i64 8}
!17 = !{!10, !12, i64 16}


; 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.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 }

@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4FileC2EPKc(ptr nocapture noundef nonnull align 8 dereferenceable(24) %0, ptr nocapture noundef readonly %1) unnamed_addr #0 align 2 {
  %3 = alloca %struct.stat, align 8
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr null, ptr %4, align 8, !tbaa !5
  %5 = tail call i32 (ptr, i32, ...) @open(ptr noundef %1, i32 noundef 2)
  store i32 %5, ptr %0, align 8, !tbaa !12
  %6 = icmp eq i32 %5, -1
  br i1 %6, label %7, label %8

7:                                                ; preds = %2
  tail call void @perror(ptr noundef nonnull @.str) #5
  br label %21

8:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %3) #6
  %9 = call i32 @fstat(i32 noundef %5, ptr noundef nonnull %3) #6
  %10 = icmp eq i32 %9, -1
  br i1 %10, label %11, label %12

11:                                               ; preds = %8
  tail call void @perror(ptr noundef nonnull @.str.1) #5
  br label %20

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %3, i64 48
  %14 = load i64, ptr %13, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %14, ptr %15, align 8, !tbaa !16
  %16 = load i32, ptr %0, align 8, !tbaa !12
  %17 = tail call ptr @mmap(ptr noundef null, i64 noundef %14, i32 noundef 3, i32 noundef 2, i32 noundef %16, i64 noundef 0) #6
  store ptr %17, ptr %4, align 8, !tbaa !5
  %18 = icmp eq ptr %17, inttoptr (i64 -1 to ptr)
  br i1 %18, label %19, label %20

19:                                               ; preds = %12
  tail call void @perror(ptr noundef nonnull @.str.2) #5
  store ptr null, ptr %4, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %12, %19, %11
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %3) #6
  br label %21

21:                                               ; preds = %20, %7
  ret void
}

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

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) local_unnamed_addr #2

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

; Function Attrs: nofree nounwind
declare noundef i32 @fstat(i32 noundef, ptr nocapture noundef) local_unnamed_addr #2

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

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

attributes #0 = { 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 #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 = { 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 #3 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { cold }
attributes #6 = { 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, !10, i64 8}
!6 = !{!"_ZTS4File", !7, i64 0, !10, i64 8, !11, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!14, !11, i64 48}
!14 = !{!"_ZTS4stat", !11, i64 0, !11, i64 8, !11, i64 16, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !15, i64 72, !15, i64 88, !15, i64 104, !8, i64 120}
!15 = !{!"_ZTS8timespec", !11, i64 0, !11, i64 8}
!16 = !{!6, !11, i64 16}


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