#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*/ add_history(char **, int);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int proc_redirection(char **, int);
int ultimo(int, char **);
int wait(int *);
void execute(char **args, int numargs) {
  int pid, status;
  int code = ultimo(numargs, args);
  if ((pid = fork()) < 0) {
    perror("forks");
    exit(1);
  }
  if (pid == 0) {
    if (proc_redirection(args, numargs) == 1)
      exit(1);
    add_history(args, numargs);
    execvp(*args, args);
    perror(*args);
    exit(1);
  }
  if (1 == code)
    while (wait(&status) != pid)
      ;
  return;
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1090 <ultimo@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    11c7 <execute+0x47>
lea    0xe48(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x10(%rbp)
jne    1222 <execute+0xa2>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <proc_redirection@plt>
cmp    $0x1,%eax
jne    11f0 <execute+0x70>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <add_history@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <execvp@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0x1,%eax
cmp    -0x18(%rbp),%eax
jne    1251 <execute+0xd1>
jmp    1235 <execute+0xb5>
lea    -0x14(%rbp),%rdi
call   1080 <wait@plt>
cmp    -0x10(%rbp),%eax
je     124c <execute+0xcc>
jmp    1235 <execute+0xb5>
jmp    1251 <execute+0xd1>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
mov    %esi,%edi
mov    %r14,%rsi
call   1090 <ultimo@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
js     11d7 <execute+0x57>
je     11e0 <execute+0x60>
cmp    $0x1,%ebp
jne    11cc <execute+0x4c>
mov    %eax,%ebx
lea    0x4(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1080 <wait@plt>
cmp    %ebx,%eax
jne    11c0 <execute+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe22(%rip),%rdi
jmp    1213 <execute+0x93>
mov    %r14,%rdi
mov    %r15d,%esi
call   1030 <proc_redirection@plt>
cmp    $0x1,%eax
jne    11fa <execute+0x7a>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    %r14,%rdi
mov    %r15d,%esi
call   1040 <add_history@plt>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1060 <execvp@plt>
mov    (%r14),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"forks\00"
define void @execute(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8** %0, i8*** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = load i8**, i8*** %3
%10 = call i32 @ultimo(i32 %8, i8** %9)
store i32 %10, i32* %7
%11 = call i32 (...) @fork()
store i32 %11, i32* %5
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %38
19: ; preds = %16
%20 = load i8**, i8*** %3
%21 = load i32, i32* %4
%22 = call i32 @proc_redirection(i8** %20, i32 %21)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %19
%27 = load i8**, i8*** %3
%28 = load i32, i32* %4
%29 = call i32 @add_history(i8** %27, i32 %28)
%30 = load i8**, i8*** %3
%31 = load i8*, i8** %30
%32 = load i8**, i8*** %3
%33 = call i32 @execvp(i8* %31, i8** %32)
%34 = load i8**, i8*** %3
%35 = load i8*, i8** %34
%36 = call i32 @perror(i8* %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %16
%39 = load i32, i32* %7
%40 = icmp eq i32 1, %39
br i1 %40, label %41, label %48
41: ; preds = %38
br label %42
42: ; preds = %46, %41
%43 = call i32 @wait(i32* %6)
%44 = load i32, i32* %5
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %42
br label %42
47: ; preds = %42
br label %48
48: ; preds = %47, %38
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"forks\00"
define void @execute(i8** %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @ultimo(i32 %1, i8** %0)
%6 = tail call i32 (...) @fork()
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = icmp eq i32 %6, 0
br i1 %12, label %13, label %25
13: ; preds = %11
%14 = tail call i32 @proc_redirection(i8** %0, i32 %1)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %13
%19 = tail call i32 @add_history(i8** %0, i32 %1)
%20 = load i8*, i8** %0
%21 = tail call i32 @execvp(i8* %20, i8** %0)
%22 = load i8*, i8** %0
%23 = tail call i32 @perror(i8* %22)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %11
%26 = icmp eq i32 %5, 1
br i1 %26, label %27, label %30
27: ; preds = %25, %27
%28 = call i32 @wait(i32* %3)
%29 = icmp eq i32 %28, %6
br i1 %29, label %30, label %27
30: ; preds = %27, %25
ret void
}