; LLVM IR from Aeternum-Veritas/Merry :: legacy (merry_fio)

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @merry_open_new_file(ptr noundef %0, i64 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  store i8 1, ptr %4, align 1
  br label %40

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !11
  %14 = load i64, ptr %6, align 8, !tbaa !9
  switch i64 %14, label %30 [
    i64 2, label %15
    i64 0, label %18
    i64 4, label %21
    i64 3, label %24
    i64 1, label %27
  ]

15:                                               ; preds = %13
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = call i32 (ptr, i32, ...) @open(ptr noundef %16, i32 noundef 1088, i32 noundef 384)
  store i32 %17, ptr %8, align 4, !tbaa !11
  br label %31

18:                                               ; preds = %13
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call i32 (ptr, i32, ...) @open(ptr noundef %19, i32 noundef 0)
  store i32 %20, ptr %8, align 4, !tbaa !11
  br label %31

21:                                               ; preds = %13
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call i32 (ptr, i32, ...) @open(ptr noundef %22, i32 noundef 66, i32 noundef 384)
  store i32 %23, ptr %8, align 4, !tbaa !11
  br label %31

24:                                               ; preds = %13
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = call i32 (ptr, i32, ...) @open(ptr noundef %25, i32 noundef 576, i32 noundef 384)
  store i32 %26, ptr %8, align 4, !tbaa !11
  br label %31

27:                                               ; preds = %13
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = call i32 (ptr, i32, ...) @open(ptr noundef %28, i32 noundef 65, i32 noundef 384)
  store i32 %29, ptr %8, align 4, !tbaa !11
  br label %31

30:                                               ; preds = %13
  store i8 1, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %39

31:                                               ; preds = %27, %24, %21, %18, %15
  %32 = load i32, ptr %8, align 4, !tbaa !11
  %33 = icmp eq i32 %32, -1
  br i1 %33, label %34, label %35

34:                                               ; preds = %31
  store i8 1, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %39

35:                                               ; preds = %31
  %36 = load i32, ptr %8, align 4, !tbaa !11
  %37 = sext i32 %36 to i64
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %37, ptr %38, align 8, !tbaa !9
  store i8 0, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %39

39:                                               ; preds = %35, %34, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %40

40:                                               ; preds = %39, %12
  %41 = load i8, ptr %4, align 1
  ret i8 %41
}

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

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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"

; Function Attrs: nofree nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @merry_open_new_file(ptr noundef readonly %0, i64 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %20, label %5

5:                                                ; preds = %3
  switch i64 %1, label %20 [
    i64 2, label %6
    i64 0, label %8
    i64 4, label %10
    i64 3, label %12
    i64 1, label %14
  ]

6:                                                ; preds = %5
  %7 = tail call i32 (ptr, i32, ...) @open(ptr noundef nonnull %0, i32 noundef 1088, i32 noundef 384) #2
  br label %16

8:                                                ; preds = %5
  %9 = tail call i32 (ptr, i32, ...) @open(ptr noundef nonnull %0, i32 noundef 0) #2
  br label %16

10:                                               ; preds = %5
  %11 = tail call i32 (ptr, i32, ...) @open(ptr noundef nonnull %0, i32 noundef 66, i32 noundef 384) #2
  br label %16

12:                                               ; preds = %5
  %13 = tail call i32 (ptr, i32, ...) @open(ptr noundef nonnull %0, i32 noundef 576, i32 noundef 384) #2
  br label %16

14:                                               ; preds = %5
  %15 = tail call i32 (ptr, i32, ...) @open(ptr noundef nonnull %0, i32 noundef 65, i32 noundef 384) #2
  br label %16

16:                                               ; preds = %14, %12, %10, %8, %6
  %.0 = phi i32 [ %15, %14 ], [ %13, %12 ], [ %11, %10 ], [ %9, %8 ], [ %7, %6 ]
  %17 = icmp eq i32 %.0, -1
  br i1 %17, label %20, label %18

18:                                               ; preds = %16
  %19 = sext i32 %.0 to i64
  store i64 %19, ptr %2, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %18, %5, %16, %3
  %.1 = phi i8 [ 1, %3 ], [ 0, %18 ], [ 1, %5 ], [ 1, %16 ]
  ret i8 %.1
}

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

attributes #0 = { nofree 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 = { 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 = { 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"}


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