#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_AS;
int /*<<< orphan*/ assert(int);
int setrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ test_malloc(int);
int runtests_malloc_fail(void) {
  struct rlimit mem_lim;
  mem_lim.rlim_cur = 128 * 1024 * 1024;
  mem_lim.rlim_max = mem_lim.rlim_cur;
  int err = setrlimit(RLIMIT_AS, &mem_lim);
  assert(!err);
  test_malloc(128 * 1024);
  test_malloc(mem_lim.rlim_cur);
  return 0;
}


x86 assembly (clang, -O0):
<runtests_malloc_fail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x8000000,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1050 <setrlimit@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x20000,%edi
call   1030 <test_malloc@plt>
mov    -0x8(%rbp),%edi
call   1030 <test_malloc@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runtests_malloc_fail>:
push   %rax
movabs $0x800000008000000,%rax
mov    %rax,(%rsp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1050 <setrlimit@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    $0x20000,%edi
call   1030 <test_malloc@plt>
mov    (%rsp),%edi
call   1030 <test_malloc@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.rlimit = type { i32, i32 }
@RLIMIT_AS = global i32 0
define i32 @runtests_malloc_fail() {
%1 = alloca %struct.rlimit
%2 = alloca i32
%3 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
store i32 134217728, i32* %3
%4 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
%5 = load i32, i32* %4
%6 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 1
store i32 %5, i32* %6
%7 = load i32, i32* @RLIMIT_AS
%8 = call i32 @setrlimit(i32 %7, %struct.rlimit* %1)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = call i32 @test_malloc(i32 131072)
%15 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @test_malloc(i32 %16)
ret i32 0
}

LLVM IR (-O2):
%struct.rlimit = type { i32, i32 }
@RLIMIT_AS = global i32 0
define i32 @runtests_malloc_fail() {
%1 = alloca %struct.rlimit
%2 = bitcast %struct.rlimit* %1 to i8*
%3 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 0
store i32 134217728, i32* %3
%4 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %1, i64 0, i32 1
store i32 134217728, i32* %4
%5 = load i32, i32* @RLIMIT_AS
%6 = call i32 @setrlimit(i32 %5, %struct.rlimit* %1)
%7 = icmp eq i32 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = call i32 @test_malloc(i32 131072)
%11 = load i32, i32* %3
%12 = call i32 @test_malloc(i32 %11)
ret i32 0
}