#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 {
  void *rlim_max;
  void *rlim_cur;
};

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_DATA;
void *atoi(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
char *malloc(int);
scalar_t__ setrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  if (argc > 1) {
    struct rlimit data;
    data.rlim_cur = atoi(argv[1]);
    data.rlim_max = atoi(argv[1]);
    if (setrlimit(RLIMIT_DATA, &data) < 0) {
      fprintf(stderr, "%s: could not set limit: %s\n", argv[0],
              strerror(errno));
      return 0;
    }
  }
  for (;;) {
    char *x = malloc(1 << 16);
    if (x == (char *)0) {
      write(1, "Z\n", 2);
      return 1;
    } else {
      write(1, "X", 1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    120a <main+0xaa>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1060 <setrlimit@plt>
cmp    $0x0,%rax
jge    1205 <main+0xa5>
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xe0c(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1262 <main+0x102>
jmp    120a <main+0xaa>
jmp    120f <main+0xaf>
mov    $0x10000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    124a <main+0xea>
mov    $0x1,%edi
lea    0xde9(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
movl   $0x1,-0x4(%rbp)
jmp    1262 <main+0x102>
mov    $0x1,%edx
lea    0xdca(%rip),%rsi
mov    %edx,%edi
call   1030 <write@plt>
jmp    120f <main+0xaf>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     1189 <main+0x39>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
mov    %rax,0x10(%rsp)
mov    %rax,0x8(%rsp)
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1050 <setrlimit@plt>
test   %rax,%rax
js     11a4 <main+0x54>
lea    0xe8d(%rip),%rbx
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1190 <main+0x40>
mov    0x2e2d(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rbx
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe3b(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.rlimit = type { i8*, i8* }
@RLIMIT_DATA = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"%s: could not set limit: %s\0A\00"
@errno = global i32 0
@.str.1 = [3 x i8] c"Z\0A\00"
@.str.2 = [2 x i8] c"X\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.rlimit
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %33
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i8* @atoi(i8* %13)
%15 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 1
store i8* %14, i8** %15
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i8* @atoi(i8* %18)
%20 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i32 0, i32 0
store i8* %19, i8** %20
%21 = load i32, i32* @RLIMIT_DATA
%22 = call i64 @setrlimit(i32 %21, %struct.rlimit* %6)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %10
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %28, i8* %30)
store i32 0, i32* %3
br label %43
32: ; preds = %10
br label %33
33: ; preds = %32, %2
br label %34
34: ; preds = %42, %33
%35 = call i8* @malloc(i32 65536)
store i8* %35, i8** %7
%36 = load i8*, i8** %7
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @write(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
store i32 1, i32* %3
br label %43
40: ; preds = %34
%41 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %42
42: ; preds = %40
br label %34
43: ; preds = %38, %24
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
%struct.rlimit = type { i8*, i8* }
@RLIMIT_DATA = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"%s: could not set limit: %s\0A\00"
@errno = global i32 0
@.str.2 = [2 x i8] c"X\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.rlimit
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %16
5: ; preds = %2
%6 = bitcast %struct.rlimit* %3 to i8*
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i8* @atoi(i8* %8)
%10 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 1
store i8* %9, i8** %10
%11 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %3, i64 0, i32 0
store i8* %9, i8** %11
%12 = load i32, i32* @RLIMIT_DATA
%13 = call i64 @setrlimit(i32 %12, %struct.rlimit* %3)
%14 = icmp slt i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %5
br label %16
16: ; preds = %15, %2
br label %17
17: ; preds = %16, %17
%18 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %17
19: ; preds = %5
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %1
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %23)
ret i32 0
}