#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, int /*<<< orphan*/ *, struct rlimit *);
int get_rlimit(long pid, int resource, long long *soft, long long *hard) {
  struct rlimit cur;
  if (prlimit(pid, resource, NULL, &cur) == -1) {
    return errno;
  }
  *soft = cur.rlim_cur;
  *hard = cur.rlim_max;
  return 0;
}


x86 assembly (clang, -O0):
<get_rlimit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x38(%rbp),%rcx
call   1030 <prlimit@plt>
cmp    $0xffffffff,%eax
jne    1155 <get_rlimit+0x45>
mov    0x2e95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1172 <get_rlimit+0x62>
mov    -0x38(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_rlimit>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
xor    %ebx,%ebx
mov    %rsp,%rcx
xor    %edx,%edx
call   1030 <prlimit@plt>
cmp    $0xffffffff,%eax
je     1141 <get_rlimit+0x31>
mov    (%rsp),%rax
mov    %rax,(%r15)
mov    0x8(%rsp),%rax
mov    %rax,(%r14)
jmp    114a <get_rlimit+0x3a>
mov    0x2e98(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.rlimit = type { i64, i64 }
@errno = global i32 0
define i32 @get_rlimit(i64 %0, i32 %1, i64* nocapture writeonly %2, i64* nocapture writeonly %3) {
%5 = alloca %struct.rlimit
%6 = bitcast %struct.rlimit* %5 to i8*
%7 = call i32 @prlimit(i64 %0, i32 %1, i32* null, %struct.rlimit* %5)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = load i32, i32* @errno
br label %16
11: ; preds = %4
%12 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i64 0, i32 0
%13 = load i64, i64* %12
store i64 %13, i64* %2
%14 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %5, i64 0, i32 1
%15 = load i64, i64* %14
store i64 %15, i64* %3
br label %16
16: ; preds = %11, %9
%17 = phi i32 [ %10, %9 ], [ 0, %11 ]
ret i32 %17
}