#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 {
  unsigned long rlim_cur;
  unsigned long rlim_max;
};

/* Variables and functions */
int ENOSYS;
int __syscall(int, int, ...);
int __setrlimit(int resource, const struct rlimit *rlim) {
  unsigned long k_rlim[2];
  int ret = __syscall(369, 0, resource, rlim, 0);
  if (ret != -ENOSYS)
    return ret;
  k_rlim[0] = ((rlim->rlim_cur) < (-1UL) ? (rlim->rlim_cur) : (-1UL));
  k_rlim[1] = ((rlim->rlim_max) < (-1UL) ? (rlim->rlim_max) : (-1UL));
  return __syscall(75, resource, k_rlim);
}


x86 assembly (clang, -O0):
<__setrlimit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x171,%edi
xor    %r8d,%r8d
mov    %r8d,%esi
mov    $0x0,%al
call   1030 <__syscall@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
xor    %ecx,%ecx
mov    0x2ea1(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
je     115c <__setrlimit+0x4c>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11e0 <__setrlimit+0xd0>
mov    -0x10(%rbp),%rax
cmpq   $0xffffffffffffffff,(%rax)
jae    117a <__setrlimit+0x6a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    118a <__setrlimit+0x7a>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
jmp    118a <__setrlimit+0x7a>
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0xffffffffffffffff,0x8(%rax)
jae    11b2 <__setrlimit+0xa2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    11c2 <__setrlimit+0xb2>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
jmp    11c2 <__setrlimit+0xb2>
mov    -0x38(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
lea    -0x20(%rbp),%rdx
mov    $0x4b,%edi
mov    $0x0,%al
call   1030 <__syscall@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__setrlimit>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x171,%edi
xor    %esi,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
xor    %r8d,%r8d
xor    %eax,%eax
call   1030 <__syscall@plt>
mov    0x2eb0(%rip),%rcx
mov    %eax,%edx
add    (%rcx),%edx
jne    1156 <__setrlimit+0x46>
movups (%rbx),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdx
mov    $0x4b,%edi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <__syscall@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.rlimit = type { i64, i64 }
@ENOSYS = global i32 0
define i32 @__setrlimit(i32 %0, %struct.rlimit* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.rlimit*
%6 = alloca [2 x i64]
%7 = alloca i32
store i32 %0, i32* %4
store %struct.rlimit* %1, %struct.rlimit** %5
%8 = load i32, i32* %4
%9 = load %struct.rlimit*, %struct.rlimit** %5
%10 = call i32 (i32, i32, ...) @__syscall(i32 369, i32 0, i32 %8, %struct.rlimit* %9, i32 0)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = load i32, i32* @ENOSYS
%13 = sub nsw i32 0, %12
%14 = icmp ne i32 %11, %13
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = load i32, i32* %7
store i32 %16, i32* %3
br label %45
17: ; preds = %2
%18 = load %struct.rlimit*, %struct.rlimit** %5
%19 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %18, i32 0, i32 0
%20 = load i64, i64* %19
%21 = icmp ult i64 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load %struct.rlimit*, %struct.rlimit** %5
%24 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %23, i32 0, i32 0
%25 = load i64, i64* %24
br label %27
26: ; preds = %17
br label %27
27: ; preds = %26, %22
%28 = phi i64 [ %25, %22 ], [ -1, %26 ]
%29 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 0
store i64 %28, i64* %29
%30 = load %struct.rlimit*, %struct.rlimit** %5
%31 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %30, i32 0, i32 1
%32 = load i64, i64* %31
%33 = icmp ult i64 %32, -1
br i1 %33, label %34, label %38
34: ; preds = %27
%35 = load %struct.rlimit*, %struct.rlimit** %5
%36 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %35, i32 0, i32 1
%37 = load i64, i64* %36
br label %39
38: ; preds = %27
br label %39
39: ; preds = %38, %34
%40 = phi i64 [ %37, %34 ], [ -1, %38 ]
%41 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 1
store i64 %40, i64* %41
%42 = load i32, i32* %4
%43 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 0
%44 = call i32 (i32, i32, ...) @__syscall(i32 75, i32 %42, i64* %43)
store i32 %44, i32* %3
br label %45
45: ; preds = %39, %15
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
%struct.rlimit = type { i64, i64 }
@ENOSYS = global i32 0
define i32 @__setrlimit(i32 %0, %struct.rlimit* %1) {
%3 = alloca <2 x i64>
%4 = bitcast <2 x i64>* %3 to i8*
%5 = tail call i32 (i32, i32, ...) @__syscall(i32 369, i32 0, i32 %0, %struct.rlimit* %1, i32 0)
%6 = load i32, i32* @ENOSYS
%7 = sub nsw i32 0, %6
%8 = icmp eq i32 %5, %7
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = getelementptr inbounds <2 x i64>, <2 x i64>* %3, i64 0, i64 0
%11 = bitcast %struct.rlimit* %1 to <2 x i64>*
%12 = load <2 x i64>, <2 x i64>* %11
store <2 x i64> %12, <2 x i64>* %3
%13 = call i32 (i32, i32, ...) @__syscall(i32 75, i32 %0, i64* %10)
br label %14
14: ; preds = %2, %9
%15 = phi i32 [ %13, %9 ], [ %5, %2 ]
ret i32 %15
}