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

/* Variables and functions */
int errno;
int prlimit(long, int, struct rlimit *, struct rlimit *);
int set_rlimit(long pid, int resource, long long soft, long long hard) {
  struct rlimit before;
  struct rlimit after;
  after.rlim_cur = soft;
  after.rlim_max = hard;
  if (prlimit(pid, resource, &after, &before) == -1) {
    return errno;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_rlimit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x48(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1030 <prlimit@plt>
cmp    $0xffffffff,%eax
jne    1165 <set_rlimit+0x55>
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    116c <set_rlimit+0x5c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_rlimit>:
sub    $0x28,%rsp
mov    %rdx,0x8(%rsp)
mov    %rcx,0x10(%rsp)
lea    0x8(%rsp),%rdx
lea    0x18(%rsp),%rcx
call   1030 <prlimit@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    113f <set_rlimit+0x2f>
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.rlimit = type { i64, i64 }
@errno = global i32 0
define i32 @set_rlimit(i64 %0, i32 %1, i64 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca %struct.rlimit
%11 = alloca %struct.rlimit
store i64 %0, i64* %6
store i32 %1, i32* %7
store i64 %2, i64* %8
store i64 %3, i64* %9
%12 = load i64, i64* %8
%13 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %11, i32 0, i32 0
store i64 %12, i64* %13
%14 = load i64, i64* %9
%15 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %11, i32 0, i32 1
store i64 %14, i64* %15
%16 = load i64, i64* %6
%17 = load i32, i32* %7
%18 = call i32 @prlimit(i64 %16, i32 %17, %struct.rlimit* %11, %struct.rlimit* %10)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %4
%21 = load i32, i32* @errno
store i32 %21, i32* %5
br label %23
22: ; preds = %4
store i32 0, i32* %5
br label %23
23: ; preds = %22, %20
%24 = load i32, i32* %5
ret i32 %24
}

LLVM IR (-O2):
%struct.rlimit = type { i64, i64 }
@errno = global i32 0
define i32 @set_rlimit(i64 %0, i32 %1, i64 %2, i64 %3) {
%5 = alloca %struct.rlimit
%6 = alloca %struct.rlimit
%7 = bitcast %struct.rlimit* %5 to i8*
%8 = bitcast %struct.rlimit* %6 to i8*
%9 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i64 0, i32 0
store i64 %2, i64* %9
%10 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i64 0, i32 1
store i64 %3, i64* %10
%11 = call i32 @prlimit(i64 %0, i32 %1, %struct.rlimit* %6, %struct.rlimit* %5)
%12 = icmp eq i32 %11, -1
%13 = load i32, i32* @errno
%14 = select i1 %12, i32 %13, i32 0
ret i32 %14
}