#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*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
scalar_t__ ft_strcmp(char *, char *);
int /*<<< orphan*/ join_spe_tab(char **, int, int);
int /*<<< orphan*/ pre_exec(int /*<<< orphan*/);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int sub_shell(char **tab, int i) {
  int v;
  v = i;
  while (tab[i] && ft_strcmp(tab[i], ")"))
    ++i;
  if (!fork())
    pre_exec(join_spe_tab(tab, v + 1, i));
  wait(0);
  _exit(0);
  return (i);
}


x86 assembly (clang, -O0):
<sub_shell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rcx
movslq -0xc(%rbp),%rdx
xor    %eax,%eax
cmpq   $0x0,(%rcx,%rdx,8)
mov    %al,-0x11(%rbp)
je     11af <sub_shell+0x4f>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe60(%rip),%rsi
call   1060 <ft_strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11bf <sub_shell+0x5f>
jmp    11cd <sub_shell+0x6d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1175 <sub_shell+0x15>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%eax
jne    11f6 <sub_shell+0x96>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
add    $0x1,%esi
mov    -0xc(%rbp),%edx
call   1050 <join_spe_tab@plt>
mov    %eax,%edi
call   1030 <pre_exec@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1040 <_exit@plt>

x86 assembly (clang, -O2):
<sub_shell>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
movslq %esi,%rbp
mov    (%rdi,%rbp,8),%rdi
mov    %esi,%r15d
test   %rdi,%rdi
je     11ae <sub_shell+0x4e>
lea    0xe7d(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rsi
call   1060 <ft_strcmp@plt>
test   %rax,%rax
je     11ab <sub_shell+0x4b>
mov    0x8(%rbx,%rbp,8),%rdi
add    $0x1,%rbp
test   %rdi,%rdi
jne    1190 <sub_shell+0x30>
mov    %ebp,%r15d
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
jne    11d2 <sub_shell+0x72>
add    $0x1,%r14d
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15d,%edx
call   1050 <join_spe_tab@plt>
mov    %eax,%edi
call   1030 <pre_exec@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1040 <_exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c")\00"
define i32 @sub_shell(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
store i8** %0, i8*** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
store i32 %6, i32* %5
br label %7
7: ; preds = %24, %2
%8 = load i8**, i8*** %3
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8*, i8** %8, i64 %10
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %22
14: ; preds = %7
%15 = load i8**, i8*** %3
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = call i64 @ft_strcmp(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = icmp ne i64 %20, 0
br label %22
22: ; preds = %14, %7
%23 = phi i1 [ false, %7 ], [ %21, %14 ]
br i1 %23, label %24, label %27
24: ; preds = %22
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %7
27: ; preds = %22
%28 = call i32 (...) @fork()
%29 = icmp ne i32 %28, 0
br i1 %29, label %37, label %30
30: ; preds = %27
%31 = load i8**, i8*** %3
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
%34 = load i32, i32* %4
%35 = call i32 @join_spe_tab(i8** %31, i32 %33, i32 %34)
%36 = call i32 @pre_exec(i32 %35)
br label %37
37: ; preds = %30, %27
%38 = call i32 @wait(i32 0)
%39 = call i32 @_exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c")\00"
define i32 @sub_shell(i8** %0, i32 %1) {
%3 = sext i32 %1 to i64
%4 = getelementptr inbounds i8*, i8** %0, i64 %3
%5 = load i8*, i8** %4
%6 = icmp eq i8* %5, null
br i1 %6, label %20, label %7
7: ; preds = %2, %12
%8 = phi i64 [ %13, %12 ], [ %3, %2 ]
%9 = phi i8* [ %15, %12 ], [ %5, %2 ]
%10 = tail call i64 @ft_strcmp(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = add i64 %8, 1
%14 = getelementptr inbounds i8*, i8** %0, i64 %13
%15 = load i8*, i8** %14
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %7
17: ; preds = %12, %7
%18 = phi i64 [ %8, %7 ], [ %13, %12 ]
%19 = trunc i64 %18 to i32
br label %20
20: ; preds = %17, %2
%21 = phi i32 [ %1, %2 ], [ %19, %17 ]
%22 = tail call i32 (...) @fork()
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = add nsw i32 %1, 1
%26 = tail call i32 @join_spe_tab(i8** %0, i32 %25, i32 %21)
%27 = tail call i32 @pre_exec(i32 %26)
br label %28
28: ; preds = %24, %20
%29 = tail call i32 @wait(i32 0)
%30 = tail call i32 @_exit(i32 0)
unreachable
}