#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};
struct TYPE_3__ {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};
struct rusage {
  TYPE_2__ ru_stime;
  TYPE_1__ ru_utime;
};
struct rlimit {
  int rlim_cur;
  int rlim_max;
};

/* Variables and functions */
int /*<<< orphan*/ PRIO_PROCESS;
int /*<<< orphan*/ RLIMIT_FSIZE;
int /*<<< orphan*/ RUSAGE_SELF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ getpid();
int getpriority(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ getrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ getrusage(int /*<<< orphan*/, struct rusage *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ work();
int main() {
  struct rusage r_usage;
  struct rlimit r_limit;
  int priority;
  work();
  getrusage(RUSAGE_SELF, &r_usage);
  printf("CPU usage: User = %ld.%06ld, System = %ld.%06ld\n",
         r_usage.ru_utime.tv_sec, r_usage.ru_utime.tv_usec,
         r_usage.ru_stime.tv_sec, r_usage.ru_stime.tv_usec);
  priority = getpriority(PRIO_PROCESS, getpid());
  printf("Current priority = %d\n", priority);
  getrlimit(RLIMIT_FSIZE, &r_limit);
  printf("Current FSIZE limit: soft = %ld, hard = %ld\n", r_limit.rlim_cur,
         r_limit.rlim_max);
  r_limit.rlim_cur = 2048;
  r_limit.rlim_max = 4096;
  printf("Setting a 2K file size limit\n");
  setrlimit(RLIMIT_FSIZE, &r_limit);
  work();
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <work@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1080 <getrusage@plt>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x28(%rbp),%edi
mov    %eax,%esi
call   1030 <getpriority@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   10a0 <getrlimit@plt>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x800,-0x20(%rbp)
movl   $0x1000,-0x1c(%rbp)
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1070 <setrlimit@plt>
mov    $0x0,%al
call   1040 <work@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1050 <work@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1090 <getrusage@plt>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
mov    0x8(%rsp),%r8d
mov    0xc(%rsp),%ecx
lea    0xe37(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <getpriority@plt>
lea    0xe41(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2dc8(%rip),%r14
mov    (%r14),%edi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   10b0 <getrlimit@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xe2c(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
movabs $0x100000000800,%rax
mov    %rax,(%rsp)
lea    0xe3d(%rip),%rdi
call   1040 <puts@plt>
mov    (%r14),%edi
mov    %rbx,%rsi
call   1080 <setrlimit@plt>
xor    %eax,%eax
call   1050 <work@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.rusage = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i32 }
%struct.TYPE_3__ = type { i32, i32 }
%struct.rlimit = type { i32, i32 }
@RUSAGE_SELF = global i32 0
@.str = [49 x i8] c"CPU usage: User = %ld.%06ld, System = %ld.%06ld\0A\00"
@PRIO_PROCESS = global i32 0
@.str.1 = [23 x i8] c"Current priority = %d\0A\00"
@RLIMIT_FSIZE = global i32 0
@.str.2 = [45 x i8] c"Current FSIZE limit: soft = %ld, hard = %ld\0A\00"
@.str.3 = [30 x i8] c"Setting a 2K file size limit\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.rusage
%3 = alloca %struct.rlimit
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (...) @work()
%6 = load i32, i32* @RUSAGE_SELF
%7 = call i32 @getrusage(i32 %6, %struct.rusage* %2)
%8 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 1
%9 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i32 0, i32 1
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 1
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %14, i32 0, i32 1
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 0
%18 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %13, i32 %16, i32 %19)
%21 = load i32, i32* @PRIO_PROCESS
%22 = call i32 (...) @getpid()
%23 = call i32 @getpriority(i32 %21, i32 %22)
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = load i32, i32* @RLIMIT_FSIZE
%27 = call i32 @getrlimit(i32 %26, %struct.rlimit* %3)
%28 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i32 0, i32 0
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i32 0, i32 1
%31 = load i32, i32* %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %31)
%33 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i32 0, i32 0
store i32 2048, i32* %33
%34 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i32 0, i32 1
store i32 4096, i32* %34
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%36 = load i32, i32* @RLIMIT_FSIZE
%37 = call i32 @setrlimit(i32 %36, %struct.rlimit* %3)
%38 = call i32 (...) @work()
%39 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.rusage = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i32 }
%struct.TYPE_3__ = type { i32, i32 }
%struct.rlimit = type { i32, i32 }
@RUSAGE_SELF = global i32 0
@.str = [49 x i8] c"CPU usage: User = %ld.%06ld, System = %ld.%06ld\0A\00"
@PRIO_PROCESS = global i32 0
@.str.1 = [23 x i8] c"Current priority = %d\0A\00"
@RLIMIT_FSIZE = global i32 0
@.str.2 = [45 x i8] c"Current FSIZE limit: soft = %ld, hard = %ld\0A\00"
@str = [29 x i8] c"Setting a 2K file size limit\00"
define i32 @main() {
%1 = alloca %struct.rusage
%2 = alloca %struct.rlimit
%3 = bitcast %struct.rusage* %1 to i8*
%4 = bitcast %struct.rlimit* %2 to i8*
%5 = tail call i32 (...) @work()
%6 = load i32, i32* @RUSAGE_SELF
%7 = call i32 @getrusage(i32 %6, %struct.rusage* %1)
%8 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 1, i32 1
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 1, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 0, i32 1
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %11, i32 %13, i32 %15)
%17 = load i32, i32* @PRIO_PROCESS
%18 = call i32 (...) @getpid()
%19 = call i32 @getpriority(i32 %17, i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @RLIMIT_FSIZE
%22 = call i32 @getrlimit(i32 %21, %struct.rlimit* %2)
%23 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 0
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i64 0, i32 1
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %26)
store i32 2048, i32* %23
store i32 4096, i32* %25
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%29 = load i32, i32* @RLIMIT_FSIZE
%30 = call i32 @setrlimit(i32 %29, %struct.rlimit* %2)
%31 = call i32 (...) @work()
%32 = call i32 @exit(i32 0)
unreachable
}