; LLVM IR from hoytech/vmtouch :: vmtouch (increment_nofile_rlimit)

; 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.rlimit = type { i64, i64 }

@.str.40 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.41 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.43 = external hidden unnamed_addr constant [40 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare hidden void @fatal(ptr noundef, ...) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local void @increment_nofile_rlimit() #2 {
  %1 = alloca %struct.rlimit, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %1) #4
  %2 = call i32 @getrlimit64(i32 noundef 7, ptr noundef %1) #4
  %3 = icmp ne i32 %2, 0
  br i1 %3, label %4, label %8

4:                                                ; preds = %0
  %5 = call ptr @__errno_location() #5
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = call ptr @strerror(i32 noundef %6) #4
  call void (ptr, ...) @fatal(ptr noundef @.str.40, ptr noundef %7)
  br label %8

8:                                                ; preds = %4, %0
  %9 = getelementptr inbounds %struct.rlimit, ptr %1, i32 0, i32 1
  %10 = load i64, ptr %9, align 8, !tbaa !9
  %11 = add i64 %10, 1
  %12 = getelementptr inbounds %struct.rlimit, ptr %1, i32 0, i32 0
  store i64 %11, ptr %12, align 8, !tbaa !12
  %13 = getelementptr inbounds %struct.rlimit, ptr %1, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = add i64 %14, 1
  %16 = getelementptr inbounds %struct.rlimit, ptr %1, i32 0, i32 1
  store i64 %15, ptr %16, align 8, !tbaa !9
  %17 = call i32 @setrlimit64(i32 noundef 7, ptr noundef %1) #4
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %35

19:                                               ; preds = %8
  %20 = call ptr @__errno_location() #5
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = icmp eq i32 %21, 1
  br i1 %22, label %23, label %31

23:                                               ; preds = %19
  %24 = call i32 @getuid() #4
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %29, label %26

26:                                               ; preds = %23
  %27 = call i32 @geteuid() #4
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %26, %23
  call void (ptr, ...) @fatal(ptr noundef @.str.41)
  br label %30

30:                                               ; preds = %29, %26
  call void (ptr, ...) @fatal(ptr noundef @.str.42)
  br label %31

31:                                               ; preds = %30, %19
  %32 = call ptr @__errno_location() #5
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = call ptr @strerror(i32 noundef %33) #4
  call void (ptr, ...) @fatal(ptr noundef @.str.43, ptr noundef %34)
  br label %35

35:                                               ; preds = %31, %8
  call void @llvm.lifetime.end.p0(i64 16, ptr %1) #4
  ret void
}

; Function Attrs: nounwind
declare i32 @getrlimit64(i32 noundef, ptr noundef) #0

; Function Attrs: nounwind
declare i32 @setrlimit64(i32 noundef, ptr noundef) #0

; Function Attrs: nounwind
declare i32 @getuid() #0

; Function Attrs: nounwind
declare i32 @geteuid() #0

attributes #0 = { 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 #1 = { 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 #2 = { 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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"}
!9 = !{!10, !11, i64 8}
!10 = !{!"rlimit", !11, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, 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"

%struct.rlimit = type { i64, i64 }

@.str.40 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.41 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.43 = external hidden unnamed_addr constant [40 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare hidden void @fatal(ptr noundef, ...) 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: nounwind uwtable
define dso_local void @increment_nofile_rlimit() local_unnamed_addr #2 {
  %1 = alloca %struct.rlimit, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #4
  %2 = call i32 @getrlimit64(i32 noundef 7, ptr noundef nonnull %1) #4
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %7, label %3

3:                                                ; preds = %0
  %4 = tail call ptr @__errno_location() #5
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = call ptr @strerror(i32 noundef %5) #4
  call void (ptr, ...) @fatal(ptr noundef nonnull @.str.40, ptr noundef %6)
  br label %7

7:                                                ; preds = %3, %0
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = add i64 %9, 1
  store i64 %10, ptr %1, align 8, !tbaa !12
  store i64 %10, ptr %8, align 8, !tbaa !9
  %11 = call i32 @setrlimit64(i32 noundef 7, ptr noundef nonnull %1) #4
  %.not1 = icmp eq i32 %11, 0
  br i1 %.not1, label %27, label %12

12:                                               ; preds = %7
  %13 = tail call ptr @__errno_location() #5
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = icmp eq i32 %14, 1
  br i1 %15, label %16, label %24

16:                                               ; preds = %12
  %17 = call i32 @getuid() #4
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %22, label %19

19:                                               ; preds = %16
  %20 = call i32 @geteuid() #4
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %19, %16
  call void (ptr, ...) @fatal(ptr noundef nonnull @.str.41)
  br label %23

23:                                               ; preds = %22, %19
  call void (ptr, ...) @fatal(ptr noundef nonnull @.str.42)
  %.pre = load i32, ptr %13, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %23, %12
  %25 = phi i32 [ %.pre, %23 ], [ %14, %12 ]
  %26 = call ptr @strerror(i32 noundef %25) #4
  call void (ptr, ...) @fatal(ptr noundef nonnull @.str.43, ptr noundef %26)
  br label %27

27:                                               ; preds = %24, %7
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #4
  ret void
}

; Function Attrs: nounwind
declare i32 @getrlimit64(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind
declare i32 @setrlimit64(i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind
declare i32 @getuid() local_unnamed_addr #0

; Function Attrs: nounwind
declare i32 @geteuid() local_unnamed_addr #0

attributes #0 = { 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 #1 = { 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 #2 = { 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 #3 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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"}
!9 = !{!10, !11, i64 8}
!10 = !{!"rlimit", !11, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,TailCallElimPass