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

/* Variables and functions */
scalar_t__ syscall(int, int, long *);
int getrlimit(int resource, struct rlimit *rlim) {
  long k_rlim[2];
  if (syscall(191, resource, k_rlim) < 0)
    return -1;
  rlim->rlim_cur = k_rlim[0] == -1 ? -1 : (unsigned long)k_rlim[0];
  rlim->rlim_max = k_rlim[1] == -1 ? -1 : (unsigned long)k_rlim[1];
  return 0;
}


x86 assembly (clang, -O0):
<getrlimit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%esi
lea    -0x20(%rbp),%rdx
mov    $0xbf,%edi
call   1030 <syscall@plt>
cmp    $0x0,%rax
jge    1146 <getrlimit+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <getrlimit+0x9c>
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    1161 <getrlimit+0x51>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    1169 <getrlimit+0x59>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    1190 <getrlimit+0x80>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
jmp    1198 <getrlimit+0x88>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getrlimit>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%esi
mov    %rsp,%rdx
mov    $0xbf,%edi
call   1030 <syscall@plt>
test   %rax,%rax
js     113a <getrlimit+0x2a>
pshufd $0xe8,(%rsp),%xmm0
movq   %xmm0,(%rbx)
xor    %eax,%eax
jmp    113f <getrlimit+0x2f>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
define i32 @getrlimit(i32 %0, %struct.rlimit* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.rlimit*
%6 = alloca [2 x i64]
store i32 %0, i32* %4
store %struct.rlimit* %1, %struct.rlimit** %5
%7 = load i32, i32* %4
%8 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 0
%9 = call i64 @syscall(i32 191, i32 %7, i64* %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %37
12: ; preds = %2
%13 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 0
%14 = load i64, i64* %13
%15 = icmp eq i64 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %12
br label %20
17: ; preds = %12
%18 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 0
%19 = load i64, i64* %18
br label %20
20: ; preds = %17, %16
%21 = phi i64 [ -1, %16 ], [ %19, %17 ]
%22 = trunc i64 %21 to i32
%23 = load %struct.rlimit*, %struct.rlimit** %5
%24 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %23, i32 0, i32 0
store i32 %22, i32* %24
%25 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 1
%26 = load i64, i64* %25
%27 = icmp eq i64 %26, -1
br i1 %27, label %28, label %29
28: ; preds = %20
br label %32
29: ; preds = %20
%30 = getelementptr inbounds [2 x i64], [2 x i64]* %6, i64 0, i64 1
%31 = load i64, i64* %30
br label %32
32: ; preds = %29, %28
%33 = phi i64 [ -1, %28 ], [ %31, %29 ]
%34 = trunc i64 %33 to i32
%35 = load %struct.rlimit*, %struct.rlimit** %5
%36 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %35, i32 0, i32 1
store i32 %34, i32* %36
store i32 0, i32* %3
br label %37
37: ; preds = %32, %11
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
define i32 @getrlimit(i32 %0, %struct.rlimit* nocapture writeonly %1) {
%3 = alloca <2 x i64>
%4 = bitcast <2 x i64>* %3 to i8*
%5 = getelementptr inbounds <2 x i64>, <2 x i64>* %3, i64 0, i64 0
%6 = call i64 @syscall(i32 191, i32 %0, i64* %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load <2 x i64>, <2 x i64>* %3
%10 = trunc <2 x i64> %9 to <2 x i32>
%11 = bitcast %struct.rlimit* %1 to <2 x i32>*
store <2 x i32> %10, <2 x i32>* %11
br label %12
12: ; preds = %2, %8
%13 = phi i32 [ 0, %8 ], [ -1, %2 ]
ret i32 %13
}