#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 */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ do_exec(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fix_fds(int, int, int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ read_all_vchan_ext(char *, int);
int /*<<< orphan*/ stderr;
void handle_just_exec(int client_id, int len) {
  char buf[len];
  int fdn, pid;
  read_all_vchan_ext(buf, len);
  switch (pid = fork()) {
  case -1:
    perror("fork");
    exit(1);
  case 0:
    fdn = open("/dev/null", O_RDWR);
    fix_fds(fdn, fdn, fdn);
    do_exec(buf);
    perror("execl");
    exit(1);
  default:;
  }
  fprintf(stderr, "executed (nowait) %s pid %d\n", buf, pid);
}


x86 assembly (clang, -O0):
<handle_just_exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
call   1050 <read_all_vchan_ext@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
mov    %eax,-0x20(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
sub    $0xffffffff,%eax
je     11e9 <handle_just_exec+0x69>
jmp    11d9 <handle_just_exec+0x59>
mov    -0x24(%rbp),%eax
test   %eax,%eax
je     11ff <handle_just_exec+0x7f>
jmp    1244 <handle_just_exec+0xc4>
lea    0xe10(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
lea    0xdf6(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1040 <fix_fds@plt>
mov    -0x30(%rbp),%rdi
call   1030 <do_exec@plt>
lea    0xdda(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1249 <handle_just_exec+0xc9>
mov    -0x30(%rbp),%rdx
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%ecx
lea    0xdb5(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_just_exec>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    %esi,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1050 <read_all_vchan_ext@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     11d2 <handle_just_exec+0x52>
cmp    $0xffffffff,%eax
je     1203 <handle_just_exec+0x83>
mov    0x2e20(%rip),%rcx
mov    (%rcx),%edi
lea    0xe54(%rip),%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1060 <fprintf@plt>
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
lea    0xe23(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%edi
mov    %eax,%esi
mov    %eax,%edx
call   1040 <fix_fds@plt>
mov    %rbx,%rdi
call   1030 <do_exec@plt>
lea    0xe0e(%rip),%rdi
jmp    120a <handle_just_exec+0x8a>
lea    0xdf6(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
@.str.2 = [6 x i8] c"execl\00"
@stderr = global i32 0
@.str.3 = [29 x i8] c"executed (nowait) %s pid %d\0A\00"
define void @handle_just_exec(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %5
%12 = alloca i8, i64 %10
store i64 %10, i64* %6
%13 = load i32, i32* %4
%14 = call i32 @read_all_vchan_ext(i8* %12, i32 %13)
%15 = call i32 (...) @fork()
store i32 %15, i32* %8
switch i32 %15, label %29 [
i32 -1, label %16
i32 0, label %19
]
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i32, i32* @O_RDWR
%21 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = load i32, i32* %7
%24 = load i32, i32* %7
%25 = call i32 @fix_fds(i32 %22, i32 %23, i32 %24)
%26 = call i32 @do_exec(i8* %12)
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %2
br label %30
30: ; preds = %29
%31 = load i32, i32* @stderr
%32 = load i32, i32* %8
%33 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %12, i32 %32)
%34 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
@.str.2 = [6 x i8] c"execl\00"
@stderr = global i32 0
@.str.3 = [29 x i8] c"executed (nowait) %s pid %d\0A\00"
define void @handle_just_exec(i32 %0, i32 %1) {
%3 = zext i32 %1 to i64
%4 = alloca i8, i64 %3
%5 = call i32 @read_all_vchan_ext(i8* %4, i32 %1)
%6 = call i32 (...) @fork()
switch i32 %6, label %17 [
i32 -1, label %7
i32 0, label %10
]
7: ; preds = %2
%8 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = load i32, i32* @O_RDWR
%12 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = call i32 @fix_fds(i32 %12, i32 %12, i32 %12)
%14 = call i32 @do_exec(i8* %4)
%15 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %4, i32 %6)
ret void
}