; LLVM IR from kmxz/overlayfs-tools :: lib (set_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.5 = external hidden unnamed_addr constant [28 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 i32 @openat(i32 noundef, ptr noundef, i32 noundef, ...) #1

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

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

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

declare i32 @close(i32 noundef) #1

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

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

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

25:                                               ; preds = %5
  %26 = load i32, ptr %12, align 4, !tbaa !5
  %27 = load ptr, ptr %9, align 8, !tbaa !9
  %28 = load ptr, ptr %10, align 8, !tbaa !9
  %29 = load i64, ptr %11, align 8, !tbaa !11
  %30 = call i32 @fsetxattr(i32 noundef %26, ptr noundef %27, ptr noundef %28, i64 noundef %29, i32 noundef 1) #5
  store i32 %30, ptr %13, align 4, !tbaa !5
  %31 = load i32, ptr %13, align 4, !tbaa !5
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %38

33:                                               ; preds = %25
  %34 = call ptr @__errno_location() #6
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp ne i32 %35, 17
  br i1 %36, label %37, label %38

37:                                               ; preds = %33
  br label %57

38:                                               ; preds = %33, %25
  %39 = call ptr @__errno_location() #6
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = icmp eq i32 %40, 17
  br i1 %41, label %42, label %52

42:                                               ; preds = %38
  %43 = load i32, ptr %12, align 4, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !9
  %45 = load ptr, ptr %10, align 8, !tbaa !9
  %46 = load i64, ptr %11, align 8, !tbaa !11
  %47 = call i32 @fsetxattr(i32 noundef %43, ptr noundef %44, ptr noundef %45, i64 noundef %46, i32 noundef 2) #5
  store i32 %47, ptr %13, align 4, !tbaa !5
  %48 = load i32, ptr %13, align 4, !tbaa !5
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %42
  br label %57

51:                                               ; preds = %42
  br label %52

52:                                               ; preds = %51, %38
  br label %53

53:                                               ; preds = %57, %52
  %54 = load i32, ptr %12, align 4, !tbaa !5
  %55 = call i32 @close(i32 noundef %54)
  %56 = load i32, ptr %13, align 4, !tbaa !5
  store i32 %56, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %63

57:                                               ; preds = %50, %37
  %58 = load ptr, ptr %8, align 8, !tbaa !9
  %59 = load ptr, ptr %9, align 8, !tbaa !9
  %60 = call ptr @__errno_location() #6
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = call ptr @strerror(i32 noundef %61) #5
  call void (ptr, ...) @print_err(ptr noundef @.str.5, ptr noundef %58, ptr noundef %59, ptr noundef %62)
  br label %53

63:                                               ; preds = %53, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  %64 = load i32, ptr %6, align 4
  ret i32 %64
}

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

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


; 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.5 = external hidden unnamed_addr constant [28 x i8], align 1

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

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

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

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

declare i32 @close(i32 noundef) local_unnamed_addr #0

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

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

12:                                               ; preds = %5
  %13 = tail call i32 @fsetxattr(i32 noundef %6, ptr noundef %2, ptr noundef %3, i64 noundef %4, i32 noundef 1) #4
  %.not = icmp eq i32 %13, 0
  %.pre = tail call ptr @__errno_location() #5
  %.pr = load i32, ptr %.pre, align 4, !tbaa !5
  %14 = icmp eq i32 %.pr, 17
  br i1 %.not, label %16, label %15

15:                                               ; preds = %12
  br i1 %14, label %.thread, label %20

16:                                               ; preds = %12
  br i1 %14, label %.thread, label %18

.thread:                                          ; preds = %15, %16
  %17 = tail call i32 @fsetxattr(i32 noundef %6, ptr noundef %2, ptr noundef %3, i64 noundef %4, i32 noundef 2) #4
  %.not24 = icmp eq i32 %17, 0
  br i1 %.not24, label %18, label %20

18:                                               ; preds = %16, %.thread, %20
  %.0 = phi i32 [ %.1, %20 ], [ 0, %.thread ], [ 0, %16 ]
  %19 = tail call i32 @close(i32 noundef %6) #4
  br label %23

20:                                               ; preds = %.thread, %15
  %.1 = phi i32 [ %17, %.thread ], [ %13, %15 ]
  %21 = load i32, ptr %.pre, align 4, !tbaa !5
  %22 = tail call ptr @strerror(i32 noundef %21) #4
  tail call void (ptr, ...) @print_err(ptr noundef nonnull @.str.5, ptr noundef %1, ptr noundef %2, ptr noundef %22) #4
  br label %18

23:                                               ; preds = %18, %8
  %.018 = phi i32 [ -1, %8 ], [ %.0, %18 ]
  ret i32 %.018
}

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

attributes #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 = { 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 #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 = { 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 = { nounwind }
attributes #5 = { 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"}


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