#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_CORE;
int errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int handle_zng(int);
int /*<<< orphan*/ printf(char *, ...);
int setrlimit(int /*<<< orphan*/, struct rlimit *);
int setrlimit_test(struct rlimit *rlp) {
  int ret, save_errno;
  int passed;
  printf("setrlimit(): rlp=0x%p\n", rlp);
  printf("\t\trlim_cur = %u\n", rlp->rlim_cur);
  printf("\t\trlim_max = %u\n", rlp->rlim_max);
  fflush(NULL);
  passed = handle_zng(ret = setrlimit(RLIMIT_CORE, rlp));
  save_errno = errno;
  switch (passed) {
  case -1:
  case 0:
    printf("\t\tret = %d\n", ret);
    printf("\tSucceeded Phase 1\n");
    fflush(NULL);
    break;
  case -2:
    printf("\tFailed Phase 1: returned undefined value! "
           "ret = %d\n",
           ret);
    fflush(NULL);
    break;
  default:
    printf("Internal syscalltester error: passed = %d\n", passed);
    fflush(NULL);
    break;
  }
  errno = save_errno;
  return ret;
}


x86 assembly (clang, -O0):
<setrlimit_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xea9(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
call   1040 <printf@plt>
mov    -0x1d(%rbp),%al
mov    -0x8(%rbp),%rcx
mov    (%rcx),%esi
lea    0xea3(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1d(%rbp),%al
mov    -0x8(%rbp),%rcx
mov    0x4(%rcx),%esi
lea    0xe9e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,%edi
call   1050 <fflush@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
call   1060 <setrlimit@plt>
mov    %eax,%edi
mov    %edi,-0xc(%rbp)
call   1030 <handle_zng@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0xfffffffe,%eax
je     1219 <setrlimit_test+0xd9>
jmp    11d8 <setrlimit_test+0x98>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
sub    $0x1,%eax
ja     1238 <setrlimit_test+0xf8>
jmp    11ec <setrlimit_test+0xac>
mov    -0xc(%rbp),%esi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    1252 <setrlimit_test+0x112>
mov    -0xc(%rbp),%esi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    1252 <setrlimit_test+0x112>
mov    -0x14(%rbp),%esi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
mov    -0x10(%rbp),%ecx
mov    0x2d7c(%rip),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setrlimit_test>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xea2(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%esi
lea    0xea6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rbx),%esi
lea    0xea6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1070 <setrlimit@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <handle_zng@plt>
mov    0x2e27(%rip),%r14
mov    (%r14),%ebp
lea    0x1(%rax),%ecx
cmp    $0x2,%ecx
jae    11da <setrlimit_test+0x8a>
lea    0xe76(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed2(%rip),%rdi
call   1030 <puts@plt>
jmp    11fa <setrlimit_test+0xaa>
cmp    $0xfffffffe,%eax
jne    11ea <setrlimit_test+0x9a>
lea    0xe5f(%rip),%rdi
mov    %ebx,%esi
jmp    11f3 <setrlimit_test+0xa3>
lea    0xe89(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
mov    %ebp,(%r14)
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@.str = [23 x i8] c"setrlimit(): rlp=0x%p\0A\00"
@.str.1 = [17 x i8] c"\09\09rlim_cur = %u\0A\00"
@.str.2 = [17 x i8] c"\09\09rlim_max = %u\0A\00"
@RLIMIT_CORE = global i32 0
@errno = global i32 0
@.str.3 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.4 = [20 x i8] c"\09Succeeded Phase 1\0A\00"
@.str.5 = [53 x i8] c"\09Failed Phase 1: returned undefined value! ret = %d\0A\00"
@.str.6 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
define i32 @setrlimit_test(%struct.rlimit* %0) {
%2 = alloca %struct.rlimit*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store %struct.rlimit* %0, %struct.rlimit** %2
%6 = load %struct.rlimit*, %struct.rlimit** %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), %struct.rlimit* %6)
%8 = load %struct.rlimit*, %struct.rlimit** %2
%9 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = load %struct.rlimit*, %struct.rlimit** %2
%13 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %12, i32 0, i32 1
%14 = load i32, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = call i32 @fflush(i32* null)
%17 = load i32, i32* @RLIMIT_CORE
%18 = load %struct.rlimit*, %struct.rlimit** %2
%19 = call i32 @setrlimit(i32 %17, %struct.rlimit* %18)
store i32 %19, i32* %3
%20 = call i32 @handle_zng(i32 %19)
store i32 %20, i32* %5
%21 = load i32, i32* @errno
store i32 %21, i32* %4
%22 = load i32, i32* %5
switch i32 %22, label %32 [
i32 -1, label %23
i32 0, label %23
i32 -2, label %28
]
23: ; preds = %1, %1
%24 = load i32, i32* %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 @fflush(i32* null)
br label %36
28: ; preds = %1
%29 = load i32, i32* %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = call i32 @fflush(i32* null)
br label %36
32: ; preds = %1
%33 = load i32, i32* %5
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 %33)
%35 = call i32 @fflush(i32* null)
br label %36
36: ; preds = %32, %28, %23
%37 = load i32, i32* %4
store i32 %37, i32* @errno
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@.str = [23 x i8] c"setrlimit(): rlp=0x%p\0A\00"
@.str.1 = [17 x i8] c"\09\09rlim_cur = %u\0A\00"
@.str.2 = [17 x i8] c"\09\09rlim_max = %u\0A\00"
@RLIMIT_CORE = global i32 0
@errno = global i32 0
@.str.3 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.5 = [53 x i8] c"\09Failed Phase 1: returned undefined value! ret = %d\0A\00"
@.str.6 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
@str = [19 x i8] c"\09Succeeded Phase 1\00"
define i32 @setrlimit_test(%struct.rlimit* %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), %struct.rlimit* %0)
%3 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %0, i64 0, i32 1
%7 = load i32, i32* %6
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = tail call i32 @fflush(i32* null)
%10 = load i32, i32* @RLIMIT_CORE
%11 = tail call i32 @setrlimit(i32 %10, %struct.rlimit* %0)
%12 = tail call i32 @handle_zng(i32 %11)
%13 = load i32, i32* @errno
switch i32 %12, label %19 [
i32 -1, label %14
i32 0, label %14
i32 -2, label %17
]
14: ; preds = %1, %1
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %21
17: ; preds = %1
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0), i32 %11)
br label %21
19: ; preds = %1
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 %12)
br label %21
21: ; preds = %19, %17, %14
%22 = tail call i32 @fflush(i32* null)
store i32 %13, i32* @errno
ret i32 %11
}