#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 {
  scalar_t__ rlim_cur;
  scalar_t__ rlim_max;
};
typedef int /*<<< orphan*/ __rlimit_resource_t;

/* Variables and functions */
scalar_t__ RLIM_INFINITY;
int __getrlimit(int /*<<< orphan*/, struct rlimit *);
int getrlimit(__rlimit_resource_t resource, struct rlimit *rlimits) {
  int result;
  result = __getrlimit(resource, rlimits);
  if (result == -1)
    return result;
  if (rlimits->rlim_cur == RLIM_INFINITY >> 1)
    rlimits->rlim_cur = RLIM_INFINITY;
  if (rlimits->rlim_max == RLIM_INFINITY >> 1)
    rlimits->rlim_max = RLIM_INFINITY;
  return result;
}


x86 assembly (clang, -O0):
<getrlimit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <__getrlimit@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1143 <getrlimit+0x33>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a9 <getrlimit+0x99>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e8f(%rip),%rcx
mov    (%rcx),%rcx
sar    $0x1,%rcx
cmp    %rcx,%rax
jne    1172 <getrlimit+0x62>
mov    0x2e78(%rip),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2e5f(%rip),%rcx
mov    (%rcx),%rcx
sar    $0x1,%rcx
cmp    %rcx,%rax
jne    11a3 <getrlimit+0x93>
mov    0x2e48(%rip),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getrlimit>:
push   %rbx
mov    %rsi,%rbx
call   1030 <__getrlimit@plt>
cmp    $0xffffffff,%eax
je     1149 <getrlimit+0x39>
mov    0x2ebb(%rip),%rsi
mov    (%rsi),%rcx
mov    %rcx,%rdx
sar    %rdx
cmp    %rdx,(%rbx)
jne    113f <getrlimit+0x2f>
mov    %rcx,(%rbx)
mov    (%rsi),%rcx
mov    %rcx,%rdx
sar    %rdx
cmp    %rdx,0x8(%rbx)
jne    1149 <getrlimit+0x39>
mov    %rcx,0x8(%rbx)
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.rlimit = type { i64, i64 }
@RLIM_INFINITY = global i64 0
define i32 @getrlimit(i32 %0, %struct.rlimit* %1) {
%3 = tail call i32 @__getrlimit(i32 %0, %struct.rlimit* %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %21, label %5
5: ; preds = %2
%6 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 0
%7 = load i64, i64* %6
%8 = load i64, i64* @RLIM_INFINITY
%9 = ashr i64 %8, 1
%10 = icmp eq i64 %7, %9
br i1 %10, label %11, label %14
11: ; preds = %5
store i64 %8, i64* %6
%12 = load i64, i64* @RLIM_INFINITY
%13 = ashr i64 %12, 1
br label %14
14: ; preds = %11, %5
%15 = phi i64 [ %13, %11 ], [ %9, %5 ]
%16 = phi i64 [ %12, %11 ], [ %8, %5 ]
%17 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 1
%18 = load i64, i64* %17
%19 = icmp eq i64 %18, %15
br i1 %19, label %20, label %21
20: ; preds = %14
store i64 %16, i64* %17
br label %21
21: ; preds = %14, %20, %2
ret i32 %3
}