#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct rlimit {
  long rlim_cur;
  long rlim_max;
};

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_NOFILE;
int /*<<< orphan*/ perror(char *);
scalar_t__ setrlimit(int /*<<< orphan*/, struct rlimit *);
int set_nofile(long cur, long max) {
  struct rlimit rl;
  rl.rlim_cur = cur;
  rl.rlim_max = max;
  if (setrlimit(RLIMIT_NOFILE, &rl)) {
    perror("setrlimit");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_nofile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1030 <setrlimit@plt>
cmp    $0x0,%rax
je     1174 <set_nofile+0x54>
lea    0xe9d(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    117b <set_nofile+0x5b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_nofile>:
sub    $0x18,%rsp
mov    %rdi,0x8(%rsp)
mov    %rsi,0x10(%rsp)
mov    0x2eb3(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <setrlimit@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1150 <set_nofile+0x30>
add    $0x18,%rsp
ret
lea    0xea9(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.rlimit = type { i64, i64 }
@RLIMIT_NOFILE = global i32 0
@.str = [10 x i8] c"setrlimit\00"
define i32 @set_nofile(i64 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca %struct.rlimit
store i64 %0, i64* %4
store i64 %1, i64* %5
%7 = load i64, i64* %4
%8 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 0
store i64 %7, i64* %8
%9 = load i64, i64* %5
%10 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 1
store i64 %9, i64* %10
%11 = load i32, i32* @RLIMIT_NOFILE
%12 = call i64 @setrlimit(i32 %11, %struct.rlimit* %6)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %17
16: ; preds = %2
store i32 0, i32* %3
br label %17
17: ; preds = %16, %14
%18 = load i32, i32* %3
ret i32 %18
}

LLVM IR (-O2):
%struct.rlimit = type { i64, i64 }
@RLIMIT_NOFILE = global i32 0
@.str = [10 x i8] c"setrlimit\00"
define i32 @set_nofile(i64 %0, i64 %1) {
%3 = alloca %struct.rlimit
%4 = bitcast %struct.rlimit* %3 to i8*
%5 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 0
store i64 %0, i64* %5
%6 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 1
store i64 %1, i64* %6
%7 = load i32, i32* @RLIMIT_NOFILE
%8 = call i64 @setrlimit(i32 %7, %struct.rlimit* %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %2, %10
%13 = phi i32 [ -1, %10 ], [ 0, %2 ]
ret i32 %13
}