#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 */

/* Variables and functions */
unsigned long long RLIM_INFINITY;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ testChildStackLimit(unsigned long long, char *);
int main(int argc, char *argv[]) {
  if (argc == 2) {
    fprintf(stderr, "Testing child with infinite stack\n");
    testChildStackLimit(RLIM_INFINITY, argv[1]);
    fprintf(stderr, "Testing child with 1TB stack\n");
    testChildStackLimit(1ULL << 40, argv[1]);
  }
  fprintf(stderr, "done\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1198 <main+0x78>
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
lea    0xeb0(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e7c(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <testChildStackLimit@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xea7(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
movabs $0x10000000000,%rdi
call   1040 <testChildStackLimit@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1177 <main+0x57>
mov    %rsi,%rbx
mov    0x2ead(%rip),%r14
mov    (%r14),%edi
lea    0xec3(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e8f(%rip),%rax
mov    (%rax),%rdi
mov    0x8(%rbx),%rsi
call   1040 <testChildStackLimit@plt>
mov    (%r14),%edi
lea    0xec4(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x8(%rbx),%rsi
movabs $0x10000000000,%rdi
call   1040 <testChildStackLimit@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xeba(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"Testing child with infinite stack\0A\00"
@RLIM_INFINITY = global i64 0
@.str.1 = [30 x i8] c"Testing child with 1TB stack\0A\00"
@.str.2 = [6 x i8] c"done\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 2
br i1 %7, label %8, label %22
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%11 = load i64, i64* @RLIM_INFINITY
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @testChildStackLimit(i64 %11, i8* %14)
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @testChildStackLimit(i64 1099511627776, i8* %20)
br label %22
22: ; preds = %8, %2
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"Testing child with infinite stack\0A\00"
@RLIM_INFINITY = global i64 0
@.str.1 = [30 x i8] c"Testing child with 1TB stack\0A\00"
@.str.2 = [6 x i8] c"done\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %15
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%7 = load i64, i64* @RLIM_INFINITY
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @testChildStackLimit(i64 %7, i8* %9)
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%13 = load i8*, i8** %8
%14 = tail call i32 @testChildStackLimit(i64 1099511627776, i8* %13)
br label %15
15: ; preds = %4, %2
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}