#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 getrlimit(int /*<<< orphan*/, struct rlimit *);
int handle_zng(int);
int /*<<< orphan*/ printf(char *, ...);
int getrlimit_test(struct rlimit *rlp) {
  int ret, save_errno;
  int passed;
  printf("getrlimit(): rlimit=0x%p\n", rlp);
  fflush(NULL);
  passed = handle_zng(ret = getrlimit(RLIMIT_CORE, rlp));
  save_errno = errno;
  switch (passed) {
  case -1:
    printf("\t\tret = %d\n", ret);
    printf("\tSucceeded Phase 1\n");
    fflush(NULL);
    break;
  case 0:
    printf("\t\trlim_cur = %u\n", rlp->rlim_cur);
    printf("\t\trlim_max = %u\n", rlp->rlim_max);
    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):
<getrlimit_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)
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,%edi
call   1050 <fflush@plt>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
call   1060 <getrlimit@plt>
mov    %eax,%edi
mov    %edi,-0xc(%rbp)
call   1030 <handle_zng@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0xfffffffe,%eax
je     123d <getrlimit_test+0xfd>
jmp    11aa <getrlimit_test+0x6a>
mov    -0x18(%rbp),%eax
sub    $0xffffffff,%eax
je     11cb <getrlimit_test+0x8b>
jmp    11bb <getrlimit_test+0x7b>
mov    -0x18(%rbp),%eax
test   %eax,%eax
je     11f8 <getrlimit_test+0xb8>
jmp    125c <getrlimit_test+0x11c>
mov    -0xc(%rbp),%esi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    1276 <getrlimit_test+0x136>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    1276 <getrlimit_test+0x136>
mov    -0xc(%rbp),%esi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
jmp    1276 <getrlimit_test+0x136>
mov    -0x14(%rbp),%esi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <fflush@plt>
mov    -0x10(%rbp),%ecx
mov    0x2d58(%rip),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getrlimit_test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe9f(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1070 <getrlimit@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <handle_zng@plt>
mov    0x2e45(%rip),%r14
mov    (%r14),%r15d
cmp    $0xfffffffe,%eax
je     11af <getrlimit_test+0x5f>
test   %eax,%eax
je     11ba <getrlimit_test+0x6a>
cmp    $0xffffffff,%eax
jne    11e9 <getrlimit_test+0x99>
lea    0xe6f(%rip),%rdi
mov    %ebp,%esi
jmp    11d4 <getrlimit_test+0x84>
lea    0xe92(%rip),%rdi
mov    %ebp,%esi
jmp    11f2 <getrlimit_test+0xa2>
mov    (%rbx),%esi
lea    0xe63(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rbx),%esi
lea    0xe63(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec6(%rip),%rdi
call   1030 <puts@plt>
jmp    11f9 <getrlimit_test+0xa9>
lea    0xe8d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <fflush@plt>
mov    %r15d,(%r14)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@.str = [26 x i8] c"getrlimit(): rlimit=0x%p\0A\00"
@RLIMIT_CORE = global i32 0
@errno = global i32 0
@.str.1 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.2 = [20 x i8] c"\09Succeeded Phase 1\0A\00"
@.str.3 = [17 x i8] c"\09\09rlim_cur = %u\0A\00"
@.str.4 = [17 x i8] c"\09\09rlim_max = %u\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 @getrlimit_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 ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), %struct.rlimit* %6)
%8 = call i32 @fflush(i32* null)
%9 = load i32, i32* @RLIMIT_CORE
%10 = load %struct.rlimit*, %struct.rlimit** %2
%11 = call i32 @getrlimit(i32 %9, %struct.rlimit* %10)
store i32 %11, i32* %3
%12 = call i32 @handle_zng(i32 %11)
store i32 %12, i32* %5
%13 = load i32, i32* @errno
store i32 %13, i32* %4
%14 = load i32, i32* %5
switch i32 %14, label %35 [
i32 -1, label %15
i32 0, label %20
i32 -2, label %31
]
15: ; preds = %1
%16 = load i32, i32* %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @fflush(i32* null)
br label %39
20: ; preds = %1
%21 = load %struct.rlimit*, %struct.rlimit** %2
%22 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = load %struct.rlimit*, %struct.rlimit** %2
%26 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %25, i32 0, i32 1
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @fflush(i32* null)
br label %39
31: ; preds = %1
%32 = load i32, i32* %3
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0), i32 %32)
%34 = call i32 @fflush(i32* null)
br label %39
35: ; preds = %1
%36 = load i32, i32* %5
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 %36)
%38 = call i32 @fflush(i32* null)
br label %39
39: ; preds = %35, %31, %20, %15
%40 = load i32, i32* %4
store i32 %40, i32* @errno
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@.str = [26 x i8] c"getrlimit(): rlimit=0x%p\0A\00"
@RLIMIT_CORE = global i32 0
@errno = global i32 0
@.str.1 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.3 = [17 x i8] c"\09\09rlim_cur = %u\0A\00"
@.str.4 = [17 x i8] c"\09\09rlim_max = %u\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.7 = [19 x i8] c"\09Succeeded Phase 1\00"
define i32 @getrlimit_test(%struct.rlimit* %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), %struct.rlimit* %0)
%3 = tail call i32 @fflush(i32* null)
%4 = load i32, i32* @RLIMIT_CORE
%5 = tail call i32 @getrlimit(i32 %4, %struct.rlimit* %0)
%6 = tail call i32 @handle_zng(i32 %5)
%7 = load i32, i32* @errno
switch i32 %6, label %21 [
i32 -1, label %8
i32 0, label %11
i32 -2, label %19
]
8: ; preds = %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.7, i64 0, i64 0))
br label %23
11: ; preds = %1
%12 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %0, i64 0, i32 0
%13 = load i32, i32* %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %0, i64 0, i32 1
%16 = load i32, i32* %15
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.7, i64 0, i64 0))
br label %23
19: ; preds = %1
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0), i32 %5)
br label %23
21: ; preds = %1
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 %6)
br label %23
23: ; preds = %21, %19, %11, %8
%24 = tail call i32 @fflush(i32* null)
store i32 %7, i32* @errno
ret i32 %5
}