#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 {
  scalar_t__ rlim_max;
  scalar_t__ rlim_cur;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ RLIMIT_CPU;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ getrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ printf(char *, int, int);
int prlimit(scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/ *,
            struct rlimit *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main(void) {
  struct rlimit res_lim;
  pid_t pid;
  if (getrlimit(RLIMIT_CPU, &res_lim) != 0) {
    fprintf(stderr, "Err. getrlimit(): %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  pid = fork();
  if (pid < 0) {
    fprintf(stderr, "Err.(%d) - fork - %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  } else if (pid == 0) {
    if (prlimit(pid, RLIMIT_CPU, NULL, &res_lim) == -1) {
      fprintf(stderr, "Err. prlimit(): %s\n", strerror(errno));
      exit(EXIT_FAILURE);
    }
    printf("Limits: soft=%d; hard=%d\n", (int)res_lim.rlim_cur,
           (int)res_lim.rlim_max);
  } else {
    if (prlimit(pid, RLIMIT_CPU, NULL, &res_lim) == -1) {
      fprintf(stderr, "Err. prlimit(): %s\n", strerror(errno));
      exit(EXIT_FAILURE);
    }
    printf("Limits: soft=%d; hard=%d\n", (int)res_lim.rlim_cur,
           (int)res_lim.rlim_max);
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1060 <getrlimit@plt>
cmp    $0x0,%rax
je     11d7 <main+0x67>
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1238 <main+0xc8>
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%edx
mov    %rax,%rcx
lea    0xdf3(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jne    12bf <main+0x14f>
mov    -0x20(%rbp),%rdi
mov    0x2d6a(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x18(%rbp),%rcx
call   1080 <prlimit@plt>
cmp    $0xffffffff,%eax
jne    12a2 <main+0x132>
mov    0x2d73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%rdx
lea    0xd9f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
lea    0xd8b(%rip),%rdi
call   1030 <printf@plt>
jmp    1336 <main+0x1c6>
mov    -0x20(%rbp),%rdi
mov    0x2cee(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x18(%rbp),%rcx
call   1080 <prlimit@plt>
cmp    $0xffffffff,%eax
jne    131e <main+0x1ae>
mov    0x2cf7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xd23(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2cb9(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
lea    0xd0f(%rip),%rdi
call   1030 <printf@plt>
jmp    133b <main+0x1cb>
mov    0x2c86(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    0x2e3b(%rip),%rbx
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
call   1060 <getrlimit@plt>
test   %rax,%rax
jne    11dc <main+0x6c>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
js     11fc <main+0x8c>
mov    (%rbx),%esi
lea    0x8(%rsp),%rcx
je     11a8 <main+0x38>
mov    %rax,%rdi
jmp    11aa <main+0x3a>
xor    %edi,%edi
xor    %edx,%edx
call   1080 <prlimit@plt>
cmp    $0xffffffff,%eax
je     122c <main+0xbc>
mov    0x8(%rsp),%rdx
mov    0x10(%rsp),%rsi
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2dfd(%rip),%rax
mov    (%rax),%ebx
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe06(%rip),%rsi
jmp    124a <main+0xda>
mov    0x2ddd(%rip),%rax
mov    (%rax),%ebx
mov    0x2dcc(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1070 <strerror@plt>
lea    0xdfa(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1256 <main+0xe6>
mov    0x2dad(%rip),%rax
mov    (%rax),%ebx
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xde2(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.rlimit = type { i64, i64 }
@RLIMIT_CPU = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"Err. getrlimit(): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [22 x i8] c"Err.(%d) - fork - %s\0A\00"
@.str.2 = [20 x i8] c"Err. prlimit(): %s\0A\00"
@.str.3 = [26 x i8] c"Limits: soft=%d; hard=%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.rlimit
%3 = alloca i64
store i32 0, i32* %1
%4 = load i32, i32* @RLIMIT_CPU
%5 = call i64 @getrlimit(i32 %4, %struct.rlimit* %2)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
%15 = call i64 (...) @fork()
store i64 %15, i64* %3
%16 = load i64, i64* %3
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %20, i8* %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %14
%27 = load i64, i64* %3
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %49
29: ; preds = %26
%30 = load i64, i64* %3
%31 = load i32, i32* @RLIMIT_CPU
%32 = call i32 @prlimit(i64 %30, i32 %31, i32* null, %struct.rlimit* %2)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %41
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %29
%42 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 1
%43 = load i64, i64* %42
%44 = trunc i64 %43 to i32
%45 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 0
%46 = load i64, i64* %45
%47 = trunc i64 %46 to i32
%48 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %44, i32 %47)
br label %69
49: ; preds = %26
%50 = load i64, i64* %3
%51 = load i32, i32* @RLIMIT_CPU
%52 = call i32 @prlimit(i64 %50, i32 %51, i32* null, %struct.rlimit* %2)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %61
54: ; preds = %49
%55 = load i32, i32* @stderr
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %57)
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %49
%62 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 1
%63 = load i64, i64* %62
%64 = trunc i64 %63 to i32
%65 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 0
%66 = load i64, i64* %65
%67 = trunc i64 %66 to i32
%68 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %64, i32 %67)
br label %69
69: ; preds = %61, %41
br label %70
70: ; preds = %69
%71 = load i32, i32* @EXIT_SUCCESS
ret i32 %71
}

LLVM IR (-O2):
%struct.rlimit = type { i64, i64 }
@RLIMIT_CPU = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"Err. getrlimit(): %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [22 x i8] c"Err.(%d) - fork - %s\0A\00"
@.str.2 = [20 x i8] c"Err. prlimit(): %s\0A\00"
@.str.3 = [26 x i8] c"Limits: soft=%d; hard=%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.rlimit
%2 = bitcast %struct.rlimit* %1 to i8*
%3 = load i32, i32* @RLIMIT_CPU
%4 = call i64 @getrlimit(i32 %3, %struct.rlimit* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = call i64 (...) @fork()
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %18, i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %13
%24 = icmp eq i64 %14, 0
%25 = load i32, i32* @RLIMIT_CPU
br i1 %24, label %26, label %41
26: ; preds = %23
%27 = call i32 @prlimit(i64 0, i32 %25, i32* null, %struct.rlimit* %1)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %26
%37 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 1
%38 = load i64, i64* %37
%39 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 0
%40 = load i64, i64* %39
br label %56
41: ; preds = %23
%42 = call i32 @prlimit(i64 %14, i32 %25, i32* null, %struct.rlimit* %1)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %51
44: ; preds = %41
%45 = load i32, i32* @stderr
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %41
%52 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 1
%53 = load i64, i64* %52
%54 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 0
%55 = load i64, i64* %54
br label %56
56: ; preds = %36, %51
%57 = phi i64 [ %40, %36 ], [ %55, %51 ]
%58 = phi i64 [ %38, %36 ], [ %53, %51 ]
%59 = trunc i64 %58 to i32
%60 = trunc i64 %57 to i32
%61 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %59, i32 %60)
%62 = load i32, i32* @EXIT_SUCCESS
ret i32 %62
}