#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 */
int /*<<< orphan*/ RLIMIT_NOFILE;
int errno;
scalar_t__ getrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ setrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  struct rlimit limit;
  limit.rlim_cur = 65535;
  limit.rlim_max = 65535;
  if (setrlimit(RLIMIT_NOFILE, &limit) != 0) {
    printf("setrlimit() failed with errno=%d\n", errno);
    return 1;
  }
  if (getrlimit(RLIMIT_NOFILE, &limit) != 0) {
    printf("getrlimit() failed with errno=%d\n", errno);
    return 1;
  }
  printf("The soft limit is %llu\n", limit.rlim_cur);
  printf("The hard limit is %llu\n", limit.rlim_max);
  system("bash -c 'ulimit -a'");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffff,-0x18(%rbp)
movl   $0xffff,-0x14(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1050 <setrlimit@plt>
cmp    $0x0,%rax
je     11a1 <main+0x61>
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    120f <main+0xcf>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1060 <getrlimit@plt>
cmp    $0x0,%rax
je     11de <main+0x9e>
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    120f <main+0xcf>
mov    -0x18(%rbp),%esi
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
lea    0xe71(%rip),%rdi
call   1030 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movabs $0xffff0000ffff,%rax
mov    %rax,0x8(%rsp)
mov    0x2e8d(%rip),%rbx
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
call   1050 <setrlimit@plt>
test   %rax,%rax
je     117e <main+0x3e>
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
lea    0xe84(%rip),%rdi
jmp    119f <main+0x5f>
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
call   1060 <getrlimit@plt>
test   %rax,%rax
je     11af <main+0x6f>
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x8(%rsp),%esi
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
lea    0xe9e(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
jmp    11a9 <main+0x69>

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@RLIMIT_NOFILE = global i32 0
@.str = [34 x i8] c"setrlimit() failed with errno=%d\0A\00"
@errno = global i32 0
@.str.1 = [34 x i8] c"getrlimit() failed with errno=%d\0A\00"
@.str.2 = [24 x i8] c"The soft limit is %llu\0A\00"
@.str.3 = [24 x i8] c"The hard limit is %llu\0A\00"
@.str.4 = [20 x i8] c"bash -c 'ulimit -a'\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.rlimit
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 0
store i32 65535, i32* %7
%8 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 1
store i32 65535, i32* %8
%9 = load i32, i32* @RLIMIT_NOFILE
%10 = call i64 @setrlimit(i32 %9, %struct.rlimit* %6)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @errno
%14 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 1, i32* %3
br label %30
15: ; preds = %2
%16 = load i32, i32* @RLIMIT_NOFILE
%17 = call i64 @getrlimit(i32 %16, %struct.rlimit* %6)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* @errno
%21 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %20)
store i32 1, i32* %3
br label %30
22: ; preds = %15
%23 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 1
%27 = load i32, i32* %26
%28 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = call i32 @system(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %30
30: ; preds = %22, %19, %12
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@RLIMIT_NOFILE = global i32 0
@.str = [34 x i8] c"setrlimit() failed with errno=%d\0A\00"
@errno = global i32 0
@.str.1 = [34 x i8] c"getrlimit() failed with errno=%d\0A\00"
@.str.2 = [24 x i8] c"The soft limit is %llu\0A\00"
@.str.3 = [24 x i8] c"The hard limit is %llu\0A\00"
@.str.4 = [20 x i8] c"bash -c 'ulimit -a'\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.rlimit
%4 = bitcast %struct.rlimit* %3 to i8*
%5 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 0
store i32 65535, i32* %5
%6 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 1
store i32 65535, i32* %6
%7 = load i32, i32* @RLIMIT_NOFILE
%8 = call i64 @setrlimit(i32 %7, %struct.rlimit* %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i32, i32* @errno
%12 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %26
13: ; preds = %2
%14 = load i32, i32* @RLIMIT_NOFILE
%15 = call i64 @getrlimit(i32 %14, %struct.rlimit* %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = load i32, i32* @errno
%19 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %26
20: ; preds = %13
%21 = load i32, i32* %5
%22 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %6
%24 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = call i32 @system(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %26
26: ; preds = %20, %17, %10
%27 = phi i32 [ 1, %10 ], [ 1, %17 ], [ 0, %20 ]
ret i32 %27
}