#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*/ do_child(char *);
int fork();
int /*<<< orphan*/ tcpd_warn(char *);
int wait(int *);
void shell_cmd(char *command) {
  int child_pid;
  int wait_pid;
  switch (child_pid = fork()) {
  case -1:
    tcpd_warn("cannot fork: %m");
    break;
  case 00:
    do_child(command);
  default:
    while ((wait_pid = wait((int *)0)) != -1 && wait_pid != child_pid)
      ;
  }
}


x86 assembly (clang, -O0):
<shell_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,-0xc(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
sub    $0xffffffff,%eax
je     1179 <shell_cmd+0x39>
jmp    1169 <shell_cmd+0x29>
mov    -0x14(%rbp),%eax
test   %eax,%eax
je     118a <shell_cmd+0x4a>
jmp    1193 <shell_cmd+0x53>
lea    0xe80(%rip),%rdi
call   1040 <tcpd_warn@plt>
jmp    11da <shell_cmd+0x9a>
mov    -0x8(%rbp),%rdi
call   1030 <do_child@plt>
jmp    1198 <shell_cmd+0x58>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <wait@plt>
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x15(%rbp)
je     11c0 <shell_cmd+0x80>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    11d0 <shell_cmd+0x90>
jmp    11d5 <shell_cmd+0x95>
jmp    1198 <shell_cmd+0x58>
jmp    11da <shell_cmd+0x9a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shell_cmd>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,%ebx
test   %eax,%eax
je     116c <shell_cmd+0x2c>
cmp    $0xffffffff,%ebx
jne    1180 <shell_cmd+0x40>
lea    0xea0(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <tcpd_warn@plt>
mov    %r14,%rdi
call   1030 <do_child@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edi,%edi
call   1050 <wait@plt>
cmp    $0xffffffff,%eax
je     1190 <shell_cmd+0x50>
cmp    %ebx,%eax
jne    1180 <shell_cmd+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"cannot fork: %m\00"
define void @shell_cmd(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 (...) @fork()
store i32 %5, i32* %3
switch i32 %5, label %11 [
i32 -1, label %6
i32 0, label %8
]
6: ; preds = %1
%7 = call i32 @tcpd_warn(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %23
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i32 @do_child(i8* %9)
br label %11
11: ; preds = %1, %8
br label %12
12: ; preds = %21, %11
%13 = call i32 @wait(i32* null)
store i32 %13, i32* %4
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* %4
%17 = load i32, i32* %3
%18 = icmp ne i32 %16, %17
br label %19
19: ; preds = %15, %12
%20 = phi i1 [ false, %12 ], [ %18, %15 ]
br i1 %20, label %21, label %22
21: ; preds = %19
br label %12
22: ; preds = %19
br label %23
23: ; preds = %22, %6
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"cannot fork: %m\00"
define void @shell_cmd(i8* %0) {
%2 = tail call i32 (...) @fork()
switch i32 %2, label %7 [
i32 -1, label %3
i32 0, label %5
]
3: ; preds = %1
%4 = tail call i32 @tcpd_warn(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %13
5: ; preds = %1
%6 = tail call i32 @do_child(i8* %0)
br label %7
7: ; preds = %1, %5
br label %8
8: ; preds = %7, %8
%9 = tail call i32 @wait(i32* null)
%10 = icmp ne i32 %9, -1
%11 = icmp ne i32 %9, %2
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %8, label %13
13: ; preds = %8, %3
ret void
}