#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*/ execl(char *, char *, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ wait(int *);
void ex(char *s) {
  int st;
  if (fork()) {
    wait(&st);
    return;
  }
  if (fork())
    exit(0);
  freopen("/", "r", stdin);
  execl("/bin/sh", "sh", "-c", s, 0);
  exit(0);
}


x86 assembly (clang, -O0):
<ex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
je     117c <ex+0x2c>
lea    -0xc(%rbp),%rdi
call   1060 <wait@plt>
add    $0x10,%rsp
pop    %rbp
ret
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
je     1194 <ex+0x44>
xor    %edi,%edi
call   1040 <exit@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edx
lea    0xe5c(%rip),%rdi
lea    0xe57(%rip),%rsi
call   1030 <freopen@plt>
mov    -0x8(%rbp),%rcx
lea    0xe49(%rip),%rdi
lea    0xe47(%rip),%rsi
lea    0xe43(%rip),%rdx
xor    %r8d,%r8d
call   1050 <execl@plt>
xor    %edi,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<ex>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1174 <ex+0x24>
lea    0xc(%rsp),%rdi
call   1060 <wait@plt>
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jne    11bc <ex+0x6c>
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
lea    0xe70(%rip),%rdi
lea    0xe6b(%rip),%rsi
call   1030 <freopen@plt>
lea    0xe61(%rip),%rdi
lea    0xe5f(%rip),%rsi
lea    0xe5b(%rip),%rdx
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1050 <execl@plt>
xor    %edi,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [8 x i8] c"/bin/sh\00"
@.str.3 = [3 x i8] c"sh\00"
@.str.4 = [3 x i8] c"-c\00"
define void @ex(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = call i64 (...) @fork()
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @wait(i32* %3)
ret void
8: ; preds = %1
%9 = call i64 (...) @fork()
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %8
%14 = load i32, i32* @stdin
%15 = call i32 @freopen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i8*, i8** %2
%17 = call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %16, i32 0)
%18 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [8 x i8] c"/bin/sh\00"
@.str.3 = [3 x i8] c"sh\00"
@.str.4 = [3 x i8] c"-c\00"
define void @ex(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = call i32 @wait(i32* %2)
ret void
8: ; preds = %1
%9 = tail call i64 (...) @fork()
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %8
%14 = load i32, i32* @stdin
%15 = tail call i32 @freopen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = tail call i32 @execl(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %0, i32 0)
%17 = tail call i32 @exit(i32 0)
unreachable
}