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

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_NOFILE;
scalar_t__ getrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, int /*<<< orphan*/);
void show_nofile() {
  struct rlimit rl;
  if (getrlimit(RLIMIT_NOFILE, &rl)) {
    perror("getrlimit");
  }
  printf("rlim_cur = %ld, rlim_max =%ld\n", rl.rlim_cur, rl.rlim_max);
}


x86 assembly (clang, -O0):
<show_nofile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1050 <getrlimit@plt>
cmp    $0x0,%rax
je     1160 <show_nofile+0x30>
lea    0xea5(%rip),%rdi
call   1040 <perror@plt>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_nofile>:
push   %rax
mov    0x2eb0(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1050 <getrlimit@plt>
test   %rax,%rax
jne    115c <show_nofile+0x2c>
mov    (%rsp),%edx
mov    0x4(%rsp),%esi
lea    0xeb5(%rip),%rdi
call   1030 <printf@plt>
pop    %rax
ret
lea    0xe9d(%rip),%rdi
call   1040 <perror@plt>
jmp    1147 <show_nofile+0x17>

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@RLIMIT_NOFILE = global i32 0
@.str = [10 x i8] c"getrlimit\00"
@.str.1 = [31 x i8] c"rlim_cur = %ld, rlim_max =%ld\0A\00"
define void @show_nofile() {
%1 = alloca %struct.rlimit
%2 = load i32, i32* @RLIMIT_NOFILE
%3 = call i64 @getrlimit(i32 %2, %struct.rlimit* %1)
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 1
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
%11 = load i32, i32* %10
%12 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %11)
ret void
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@RLIMIT_NOFILE = global i32 0
@.str = [10 x i8] c"getrlimit\00"
@.str.1 = [31 x i8] c"rlim_cur = %ld, rlim_max =%ld\0A\00"
define void @show_nofile() {
%1 = alloca %struct.rlimit
%2 = bitcast %struct.rlimit* %1 to i8*
%3 = load i32, i32* @RLIMIT_NOFILE
%4 = call i64 @getrlimit(i32 %3, %struct.rlimit* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 1
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %12)
ret void
}