; LLVM IR from kmxz/overlayfs-tools :: lib (get_xattr)

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

; Function Attrs: nounwind uwtable
define dso_local i64 @get_xattr(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store ptr null, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = load ptr, ptr %8, align 8, !tbaa !9
  %18 = call i32 (i32, ptr, i32, ...) @openat(i32 noundef %16, ptr noundef %17, i32 noundef 657408)
  store i32 %18, ptr %13, align 4, !tbaa !5
  %19 = load i32, ptr %13, align 4, !tbaa !5
  %20 = icmp slt i32 %19, 0
  br i1 %20, label %21, label %26

21:                                               ; preds = %5
  %22 = load ptr, ptr %8, align 8, !tbaa !9
  %23 = call ptr @__errno_location() #6
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = call ptr @strerror(i32 noundef %24) #5
  call void (ptr, ...) @print_err(ptr noundef @.str.3, ptr noundef %22, ptr noundef %25)
  store i64 -1, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %89

26:                                               ; preds = %5
  %27 = load i32, ptr %13, align 4, !tbaa !5
  %28 = load ptr, ptr %9, align 8, !tbaa !9
  %29 = call i64 @fgetxattr(i32 noundef %27, ptr noundef %28, ptr noundef null, i64 noundef 0) #5
  store i64 %29, ptr %14, align 8, !tbaa !11
  %30 = load i64, ptr %14, align 8, !tbaa !11
  %31 = icmp slt i64 %30, 0
  br i1 %31, label %32, label %47

32:                                               ; preds = %26
  %33 = call ptr @__errno_location() #6
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = icmp ne i32 %34, 61
  br i1 %35, label %36, label %41

36:                                               ; preds = %32
  %37 = call ptr @__errno_location() #6
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = icmp ne i32 %38, 95
  br i1 %39, label %40, label %41

40:                                               ; preds = %36
  br label %83

41:                                               ; preds = %36, %32
  %42 = load ptr, ptr %11, align 8, !tbaa !9
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %46

44:                                               ; preds = %41
  %45 = load ptr, ptr %11, align 8, !tbaa !9
  store i8 0, ptr %45, align 1, !tbaa !13
  br label %46

46:                                               ; preds = %44, %41
  store i64 0, ptr %14, align 8, !tbaa !11
  br label %77

47:                                               ; preds = %26
  %48 = load ptr, ptr %11, align 8, !tbaa !9
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %52

50:                                               ; preds = %47
  %51 = load ptr, ptr %11, align 8, !tbaa !9
  store i8 1, ptr %51, align 1, !tbaa !13
  br label %52

52:                                               ; preds = %50, %47
  %53 = load i64, ptr %14, align 8, !tbaa !11
  %54 = icmp eq i64 %53, 0
  br i1 %54, label %58, label %55

55:                                               ; preds = %52
  %56 = load ptr, ptr %10, align 8, !tbaa !9
  %57 = icmp ne ptr %56, null
  br i1 %57, label %59, label %58

58:                                               ; preds = %55, %52
  br label %77

59:                                               ; preds = %55
  %60 = load i64, ptr %14, align 8, !tbaa !11
  %61 = add nsw i64 %60, 1
  %62 = call ptr @smalloc(i64 noundef %61)
  store ptr %62, ptr %12, align 8, !tbaa !9
  %63 = load i32, ptr %13, align 4, !tbaa !5
  %64 = load ptr, ptr %9, align 8, !tbaa !9
  %65 = load ptr, ptr %12, align 8, !tbaa !9
  %66 = load i64, ptr %14, align 8, !tbaa !11
  %67 = call i64 @fgetxattr(i32 noundef %63, ptr noundef %64, ptr noundef %65, i64 noundef %66) #5
  store i64 %67, ptr %14, align 8, !tbaa !11
  %68 = load i64, ptr %14, align 8, !tbaa !11
  %69 = icmp sle i64 %68, 0
  br i1 %69, label %70, label %71

70:                                               ; preds = %59
  br label %81

71:                                               ; preds = %59
  %72 = load ptr, ptr %12, align 8, !tbaa !9
  %73 = load i64, ptr %14, align 8, !tbaa !11
  %74 = getelementptr inbounds i8, ptr %72, i64 %73
  store i8 0, ptr %74, align 1, !tbaa !15
  %75 = load ptr, ptr %12, align 8, !tbaa !9
  %76 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %75, ptr %76, align 8, !tbaa !9
  br label %77

77:                                               ; preds = %83, %71, %58, %46
  %78 = load i32, ptr %13, align 4, !tbaa !5
  %79 = call i32 @close(i32 noundef %78)
  %80 = load i64, ptr %14, align 8, !tbaa !11
  store i64 %80, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %89

81:                                               ; preds = %70
  %82 = load ptr, ptr %12, align 8, !tbaa !9
  call void @free(ptr noundef %82) #5
  br label %83

83:                                               ; preds = %81, %40
  %84 = load ptr, ptr %8, align 8, !tbaa !9
  %85 = load ptr, ptr %9, align 8, !tbaa !9
  %86 = call ptr @__errno_location() #6
  %87 = load i32, ptr %86, align 4, !tbaa !5
  %88 = call ptr @strerror(i32 noundef %87) #5
  call void (ptr, ...) @print_err(ptr noundef @.str.4, ptr noundef %84, ptr noundef %85, ptr noundef %88)
  br label %77

89:                                               ; preds = %77, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %90 = load i64, ptr %6, align 8
  ret i64 %90
}

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

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

declare void @print_err(ptr noundef, ...) #2

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

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

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

declare ptr @smalloc(i64 noundef) #2

declare i32 @close(i32 noundef) #2

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

; 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 "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 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 #5 = { nounwind }
attributes #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!7, !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"

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

; Function Attrs: nounwind uwtable
define dso_local i64 @get_xattr(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef writeonly %3, ptr noundef writeonly %4) local_unnamed_addr #0 {
  %6 = tail call i32 (i32, ptr, i32, ...) @openat(i32 noundef %0, ptr noundef %1, i32 noundef 657408) #5
  %7 = icmp slt i32 %6, 0
  br i1 %7, label %8, label %12

8:                                                ; preds = %5
  %9 = tail call ptr @__errno_location() #6
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = tail call ptr @strerror(i32 noundef %10) #5
  tail call void (ptr, ...) @print_err(ptr noundef nonnull @.str.3, ptr noundef %1, ptr noundef %11) #5
  br label %38

12:                                               ; preds = %5
  %13 = tail call i64 @fgetxattr(i32 noundef %6, ptr noundef %2, ptr noundef null, i64 noundef 0) #5
  %14 = icmp slt i64 %13, 0
  br i1 %14, label %15, label %20

15:                                               ; preds = %12
  %16 = tail call ptr @__errno_location() #6
  %17 = load i32, ptr %16, align 4, !tbaa !5
  switch i32 %17, label %35 [
    i32 61, label %18
    i32 95, label %18
  ]

18:                                               ; preds = %15, %15
  %.not41 = icmp eq ptr %4, null
  br i1 %.not41, label %32, label %19

19:                                               ; preds = %18
  store i8 0, ptr %4, align 1, !tbaa !9
  br label %32

20:                                               ; preds = %12
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %22, label %21

21:                                               ; preds = %20
  store i8 1, ptr %4, align 1, !tbaa !9
  br label %22

22:                                               ; preds = %21, %20
  %23 = icmp ne i64 %13, 0
  %24 = icmp ne ptr %3, null
  %or.cond = and i1 %24, %23
  br i1 %or.cond, label %25, label %32

25:                                               ; preds = %22
  %26 = add nuw nsw i64 %13, 1
  %27 = tail call ptr @smalloc(i64 noundef %26) #5
  %28 = tail call i64 @fgetxattr(i32 noundef %6, ptr noundef %2, ptr noundef %27, i64 noundef %13) #5
  %29 = icmp slt i64 %28, 1
  br i1 %29, label %34, label %30

30:                                               ; preds = %25
  %31 = getelementptr inbounds i8, ptr %27, i64 %28
  store i8 0, ptr %31, align 1, !tbaa !11
  store ptr %27, ptr %3, align 8, !tbaa !12
  br label %32

32:                                               ; preds = %18, %19, %22, %35, %30
  %.0 = phi i64 [ %.1, %35 ], [ %28, %30 ], [ %13, %22 ], [ 0, %19 ], [ 0, %18 ]
  %33 = tail call i32 @close(i32 noundef %6) #5
  br label %38

34:                                               ; preds = %25
  tail call void @free(ptr noundef %27) #5
  %.pre = tail call ptr @__errno_location() #6
  br label %35

35:                                               ; preds = %15, %34
  %.pre-phi = phi ptr [ %16, %15 ], [ %.pre, %34 ]
  %.1 = phi i64 [ %13, %15 ], [ %28, %34 ]
  %36 = load i32, ptr %.pre-phi, align 4, !tbaa !5
  %37 = tail call ptr @strerror(i32 noundef %36) #5
  tail call void (ptr, ...) @print_err(ptr noundef nonnull @.str.4, ptr noundef %1, ptr noundef %2, ptr noundef %37) #5
  br label %32

38:                                               ; preds = %32, %8
  %.029 = phi i64 [ -1, %8 ], [ %.0, %32 ]
  ret i64 %.029
}

declare i32 @openat(i32 noundef, ptr noundef, i32 noundef, ...) local_unnamed_addr #1

declare void @print_err(ptr noundef, ...) local_unnamed_addr #1

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

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

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

declare ptr @smalloc(i64 noundef) local_unnamed_addr #1

declare i32 @close(i32 noundef) local_unnamed_addr #1

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

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 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !7, i64 0}


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