#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*/ RLIMIT_FSIZE;
scalar_t__ WIFEXITED(int);
int WTERMSIG(int);
int /*<<< orphan*/ execl(char *, char *, int /*<<< orphan*/ *);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main() {
  struct rlimit limit;
  pid_t child;
  child = fork();
  if (child == 0) {
    limit.rlim_cur = limit.rlim_max = 0;
    setrlimit(RLIMIT_FSIZE, &limit);
    execl("/root/test", "test", NULL);
  } else {
    int status = 0;
    waitpid(child, &status, 0);
    if (WIFEXITED(status))
      printf("exited normally\n");
    else
      printf("%d\n", WTERMSIG(status));
    printf("exited expected\n");
    printf("end\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d3 <main+0x63>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1050 <setrlimit@plt>
lea    0xe42(%rip),%rdi
lea    0xe41(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <execl@plt>
jmp    1242 <main+0xd2>
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x24(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    -0x24(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     120e <main+0x9e>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1226 <main+0xb6>
mov    -0x24(%rbp),%edi
call   1040 <WTERMSIG@plt>
mov    %eax,%esi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
je     11bf <main+0x3f>
movl   $0x0,(%rsp)
mov    %rsp,%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1070 <waitpid@plt>
mov    (%rsp),%edi
call   1080 <WIFEXITED@plt>
test   %rax,%rax
je     11ee <main+0x6e>
lea    0xe6b(%rip),%rdi
call   1030 <puts@plt>
jmp    1206 <main+0x86>
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1060 <setrlimit@plt>
lea    0xe22(%rip),%rdi
lea    0xe21(%rip),%rsi
xor    %edx,%edx
call   1090 <execl@plt>
jmp    121e <main+0x9e>
mov    (%rsp),%edi
call   1050 <WTERMSIG@plt>
lea    0xe0e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe02(%rip),%rdi
call   1030 <puts@plt>
lea    0xe06(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.rlimit = type { i64, i64 }
@RLIMIT_FSIZE = global i32 0
@.str = [11 x i8] c"/root/test\00"
@.str.1 = [5 x i8] c"test\00"
@.str.2 = [17 x i8] c"exited normally\0A\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [17 x i8] c"exited expected\0A\00"
@.str.5 = [5 x i8] c"end\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.rlimit
%3 = alloca i64
%4 = alloca i32
store i32 0, i32* %1
%5 = call i64 (...) @fork()
store i64 %5, i64* %3
%6 = load i64, i64* %3
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %0
%9 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 0
store i64 0, i64* %9
%10 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %2, i32 0, i32 1
store i64 0, i64* %10
%11 = load i32, i32* @RLIMIT_FSIZE
%12 = call i32 @setrlimit(i32 %11, %struct.rlimit* %2)
%13 = call i32 @execl(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* null)
br label %29
14: ; preds = %0
store i32 0, i32* %4
%15 = load i64, i64* %3
%16 = call i32 @waitpid(i64 %15, i32* %4, i32 0)
%17 = load i32, i32* %4
%18 = call i64 @WIFEXITED(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %26
22: ; preds = %14
%23 = load i32, i32* %4
%24 = call i32 @WTERMSIG(i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %22, %20
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %29
29: ; preds = %26, %8
ret i32 0
}

LLVM IR (-O2):
%struct.rlimit = type { i64, i64 }
@RLIMIT_FSIZE = global i32 0
@.str = [11 x i8] c"/root/test\00"
@.str.1 = [5 x i8] c"test\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@str = [16 x i8] c"exited expected\00"
@str.6 = [4 x i8] c"end\00"
@str.7 = [16 x i8] c"exited normally\00"
define i32 @main() {
%1 = alloca %struct.rlimit
%2 = alloca i32
%3 = bitcast %struct.rlimit* %1 to i8*
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = bitcast %struct.rlimit* %1 to i8*
%8 = load i32, i32* @RLIMIT_FSIZE
%9 = call i32 @setrlimit(i32 %8, %struct.rlimit* %1)
%10 = call i32 @execl(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* null)
br label %26
11: ; preds = %0
%12 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%13 = call i32 @waitpid(i64 %4, i32* %2, i32 0)
%14 = load i32, i32* %2
%15 = call i64 @WIFEXITED(i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %11
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
br label %23
19: ; preds = %11
%20 = load i32, i32* %2
%21 = call i32 @WTERMSIG(i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %19, %17
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.6, i64 0, i64 0))
br label %26
26: ; preds = %23, %6
ret i32 0
}