#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*/ execv(char *, char **);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int wait(int *);
int main(int argc, char *argv[], char **env) {
  char **myargv;
  int i;
  int pid, pidended;
  int status;
  if ((pid = fork()) == 0) {
    printf("chez le fils... avant execvp %d", getpid());
    execvp(argv[1], argv + 1);
    perror("\n--------------si ici pas OK---\n");
    exit(1);
  }
  pidended = wait(&status);
  printf("le fils %d est terminé son status est %d\n", pidended, status);
  printf("\n%d mon fils est %d\n", getpid(), pid);
  execv(argv[1], argv + 1);
  perror("\n execv du père...");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jne    11e8 <main+0x68>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1060 <execvp@plt>
lea    0xe47(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    -0x30(%rbp),%rdi
call   1080 <wait@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x28(%rbp),%edx
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1090 <execv@plt>
lea    0xe43(%rip),%rdi
call   1050 <perror@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     11ef <main+0x6f>
mov    %eax,%ebp
lea    0x4(%rsp),%rdi
call   1080 <wait@plt>
mov    0x4(%rsp),%edx
lea    0xe99(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xead(%rip),%rdi
mov    %eax,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    %rbx,%rsi
call   1090 <execv@plt>
lea    0xea0(%rip),%rdi
call   1050 <perror@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe03(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    %rbx,%rsi
call   1060 <execvp@plt>
lea    0xe03(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"chez le fils... avant execvp %d\00"
@.str.1 = [33 x i8] c"\0A--------------si ici pas OK---\0A\00"
@.str.2 = [43 x i8] c"le fils %d est termin\C3\A9 son status est %d\0A\00"
@.str.3 = [21 x i8] c"\0A%d mon fils est %d\0A\00"
@.str.4 = [20 x i8] c"\0A execv du p\C3\A8re...\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
%12 = call i32 (...) @fork()
store i32 %12, i32* %9
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %3
%15 = call i32 (...) @getpid()
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = call i32 @execvp(i8* %19, i8** %21)
%23 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %3
%26 = call i32 @wait(i32* %11)
store i32 %26, i32* %10
%27 = load i32, i32* %10
%28 = load i32, i32* %11
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 %28)
%30 = call i32 (...) @getpid()
%31 = load i32, i32* %9
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 %31)
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = call i32 @execv(i8* %35, i8** %37)
%39 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"chez le fils... avant execvp %d\00"
@.str.1 = [33 x i8] c"\0A--------------si ici pas OK---\0A\00"
@.str.2 = [43 x i8] c"le fils %d est termin\C3\A9 son status est %d\0A\00"
@.str.3 = [21 x i8] c"\0A%d mon fils est %d\0A\00"
@.str.4 = [20 x i8] c"\0A execv du p\C3\A8re...\00"
define i32 @main(i32 %0, i8** %1, i8** nocapture readnone %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 (...) @fork()
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %3
%9 = tail call i32 (...) @getpid()
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @execvp(i8* %12, i8** %11)
%14 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %3
%17 = call i32 @wait(i32* %4)
%18 = load i32, i32* %4
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %18)
%20 = call i32 (...) @getpid()
%21 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %20, i32 %6)
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @execv(i8* %23, i8** %22)
%25 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}