#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 */
scalar_t__ exec_builtin_cmd(char const *);
int exec_elf(char const *);
char *getenv(char *);
scalar_t__ is_a_path(char const *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char const *);
int /*<<< orphan*/ wait();
void exec(const char *buffer) {
  if (exec_builtin_cmd(buffer) != 0) {
    int pid;
    if (is_a_path(buffer)) {
      if ((pid = exec_elf(buffer)) < 0)
        printf("%s: commande introuvable.\n", buffer);
      else
        wait();
    } else {
      char temp[278];
      char *path = getenv("PATH");
      sprintf(temp, "%s/%s", path, buffer);
      if ((pid = exec_elf(temp)) < 0)
        printf("%s: commande introuvable.\n", buffer);
      else
        wait();
    }
  }
}


x86 assembly (clang, -O0):
<exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <exec_builtin_cmd@plt>
cmp    $0x0,%rax
je     124a <exec+0xda>
mov    -0x8(%rbp),%rdi
call   1040 <is_a_path@plt>
cmp    $0x0,%rax
je     11db <exec+0x6b>
mov    -0x8(%rbp),%rdi
call   1050 <exec_elf@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11cf <exec+0x5f>
mov    -0x8(%rbp),%rsi
lea    0xe3b(%rip),%rdi
call   1070 <printf@plt>
jmp    11d6 <exec+0x66>
mov    $0x0,%al
call   1090 <wait@plt>
jmp    1245 <exec+0xd5>
lea    0xe39(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x138(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x138(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe19(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x130(%rbp),%rdi
call   1050 <exec_elf@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1239 <exec+0xc9>
mov    -0x8(%rbp),%rsi
lea    0xdd1(%rip),%rdi
call   1070 <printf@plt>
jmp    1240 <exec+0xd0>
mov    $0x0,%al
call   1090 <wait@plt>
jmp    1245 <exec+0xd5>
jmp    124a <exec+0xda>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec>:
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%rbx
call   1060 <exec_builtin_cmd@plt>
test   %rax,%rax
je     1216 <exec+0xa6>
mov    %rbx,%rdi
call   1040 <is_a_path@plt>
test   %rax,%rax
je     11b5 <exec+0x45>
mov    %rbx,%rdi
call   1050 <exec_elf@plt>
test   %eax,%eax
js     11ee <exec+0x7e>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
jmp    1090 <wait@plt>
lea    0xe5f(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe58(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1080 <sprintf@plt>
mov    %r14,%rdi
call   1050 <exec_elf@plt>
test   %eax,%eax
js     1207 <exec+0x97>
xor    %eax,%eax
call   1090 <wait@plt>
jmp    1216 <exec+0xa6>
lea    0xe0b(%rip),%rdi
mov    %rbx,%rsi
add    $0x118,%rsp
pop    %rbx
pop    %r14
jmp    1070 <printf@plt>
lea    0xdf2(%rip),%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [27 x i8] c"%s: commande introuvable.\0A\00"
@.str.1 = [5 x i8] c"PATH\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define void @exec(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [278 x i8]
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @exec_builtin_cmd(i8* %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %39
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i64 @is_a_path(i8* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %9
%14 = load i8*, i8** %2
%15 = call i32 @exec_elf(i8* %14)
store i32 %15, i32* %3
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i8*, i8** %2
%19 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %22
20: ; preds = %13
%21 = call i32 (...) @wait()
br label %22
22: ; preds = %20, %17
br label %38
23: ; preds = %9
%24 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %24, i8** %5
%25 = getelementptr inbounds [278 x i8], [278 x i8]* %4, i64 0, i64 0
%26 = load i8*, i8** %5
%27 = load i8*, i8** %2
%28 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %26, i8* %27)
%29 = getelementptr inbounds [278 x i8], [278 x i8]* %4, i64 0, i64 0
%30 = call i32 @exec_elf(i8* %29)
store i32 %30, i32* %3
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %23
%33 = load i8*, i8** %2
%34 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %33)
br label %37
35: ; preds = %23
%36 = call i32 (...) @wait()
br label %37
37: ; preds = %35, %32
br label %38
38: ; preds = %37, %22
br label %39
39: ; preds = %38, %1
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"%s: commande introuvable.\0A\00"
@.str.1 = [5 x i8] c"PATH\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define void @exec(i8* %0) {
%2 = alloca [278 x i8]
%3 = tail call i64 @exec_builtin_cmd(i8* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %26, label %5
5: ; preds = %1
%6 = tail call i64 @is_a_path(i8* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %5
%9 = tail call i32 @exec_elf(i8* %0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %26
13: ; preds = %8
%14 = tail call i32 (...) @wait()
br label %26
15: ; preds = %5
%16 = getelementptr inbounds [278 x i8], [278 x i8]* %2, i64 0, i64 0
%17 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @sprintf(i8* %16, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %17, i8* %0)
%19 = call i32 @exec_elf(i8* %16)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %25
23: ; preds = %15
%24 = call i32 (...) @wait()
br label %25
25: ; preds = %23, %21
br label %26
26: ; preds = %25, %13, %11, %1
ret void
}