#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 ETXTBSY;
int O_APPEND;
int O_WRONLY;
int errno;
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int fd;
  char *nv_argv[] = {"./exemple_execvp", NULL};
  fprintf(stdout, "Essai d'ouverture de %s ... ", argv[0]);
  if ((fd = open(argv[0], O_WRONLY | O_APPEND)) < 0) {
    if (errno != ETXTBSY) {
      fprintf(stdout, "impossible, errno %d\n", errno);
      exit(1);
    }
    fprintf(stdout, "échec ETXTBSY, fichier déjà utilisé\n");
  }
  fprintf(stdout, "Ouverture de exemple_exevp en écriture ... ");
  if ((fd = open("exemple_execvp", O_WRONLY | O_APPEND)) < 0) {
    fprintf(stdout, "impossible, errno %d\n", errno);
    exit(1);
  }
  fprintf(stdout, "ok\nTentative d'exécution de exemple_execvp ... ");
  execv("./exemple_execvp", nv_argv);
  if (errno == ETXTBSY)
    fprintf(stdout, "échec ETXTBSY fichier déjà utilisé\n");
  else
    fprintf(stdout, "errno = %d\n", errno);
  return (1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2c83(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c80(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe8e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
mov    0x2e0f(%rip),%rax
or     (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    120d <main+0xcd>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    0x2e14(%rip),%rcx
cmp    (%rcx),%eax
je     11f6 <main+0xb6>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%esi
mov    0x2d7c(%rip),%rax
or     (%rax),%esi
lea    0xdc5(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1278 <main+0x138>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
mov    0x2d72(%rip),%rax
mov    (%rax),%edx
lea    0xdc7(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
lea    -0x30(%rbp),%rsi
lea    0xd66(%rip),%rdi
call   1060 <execv@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    0x2d29(%rip),%rcx
cmp    (%rcx),%eax
jne    12d3 <main+0x193>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    12f3 <main+0x1b3>
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
mov    0x2ced(%rip),%rax
mov    (%rax),%edx
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movaps 0x2c8d(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    0x2e6a(%rip),%r14
mov    (%r14),%edi
mov    (%rsi),%rdx
lea    0xea6(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%rbx),%rdi
mov    0x2e3c(%rip),%r15
mov    0x2e2d(%rip),%rbx
mov    (%rbx),%esi
or     (%r15),%esi
call   1040 <open@plt>
test   %eax,%eax
jns    11ba <main+0x7a>
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
mov    0x2e37(%rip),%rax
mov    (%r14),%edi
cmp    (%rax),%edx
jne    124d <main+0x10d>
lea    0xe91(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%edi
lea    0xea9(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%rbx),%esi
or     (%r15),%esi
lea    0xe2b(%rip),%rdi
call   1040 <open@plt>
mov    (%r14),%edi
test   %eax,%eax
js     1244 <main+0x104>
lea    0xeb0(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xe08(%rip),%rdi
mov    %rsp,%rsi
call   1060 <execv@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edx
mov    0x2dc8(%rip),%rax
mov    (%r14),%edi
cmp    (%rax),%edx
jne    1227 <main+0xe7>
lea    0xead(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1235 <main+0xf5>
lea    0xec5(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d85(%rip),%rax
mov    (%rax),%edx
lea    0xdda(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"./exemple_execvp\00"
@__const.main.nv_argv = [2 x i8*] [i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i32 0, i32 0), i8* null]
@stdout = global i32 0
@.str.1 = [29 x i8] c"Essai d'ouverture de %s ... \00"
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@errno = global i32 0
@ETXTBSY = global i32 0
@.str.2 = [22 x i8] c"impossible, errno %d\0A\00"
@.str.3 = [41 x i8] c"\C3\A9chec ETXTBSY, fichier d\C3\A9j\C3\A0 utilis\C3\A9\0A\00"
@.str.4 = [45 x i8] c"Ouverture de exemple_exevp en \C3\A9criture ... \00"
@.str.5 = [15 x i8] c"exemple_execvp\00"
@.str.6 = [49 x i8] c"ok\0ATentative d'ex\C3\A9cution de exemple_execvp ... \00"
@.str.7 = [40 x i8] c"\C3\A9chec ETXTBSY fichier d\C3\A9j\C3\A0 utilis\C3\A9\0A\00"
@.str.8 = [12 x i8] c"errno = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [2 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [2 x i8*]* %7 to i8*
%9 = load i32, i32* @stdout
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_WRONLY
%18 = load i32, i32* @O_APPEND
%19 = or i32 %17, %18
%20 = call i32 @open(i8* %16, i32 %19)
store i32 %20, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %2
%23 = load i32, i32* @errno
%24 = load i32, i32* @ETXTBSY
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i32, i32* @stdout
%28 = load i32, i32* @errno
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %22
%32 = load i32, i32* @stdout
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %31, %2
%35 = load i32, i32* @stdout
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%37 = load i32, i32* @O_WRONLY
%38 = load i32, i32* @O_APPEND
%39 = or i32 %37, %38
%40 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %39)
store i32 %40, i32* %6
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %34
%43 = load i32, i32* @stdout
%44 = load i32, i32* @errno
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %34
%48 = load i32, i32* @stdout
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0))
%50 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%51 = call i32 @execv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %50)
%52 = load i32, i32* @errno
%53 = load i32, i32* @ETXTBSY
%54 = icmp eq i32 %52, %53
br i1 %54, label %55, label %58
55: ; preds = %47
%56 = load i32, i32* @stdout
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0))
br label %62
58: ; preds = %47
%59 = load i32, i32* @stdout
%60 = load i32, i32* @errno
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %58, %55
ret i32 1
}

LLVM IR (-O2):
@.str = [17 x i8] c"./exemple_execvp\00"
@__const.main.nv_argv = [2 x i8*] [i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i32 0, i32 0), i8* null]
@stdout = global i32 0
@.str.1 = [29 x i8] c"Essai d'ouverture de %s ... \00"
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@errno = global i32 0
@ETXTBSY = global i32 0
@.str.2 = [22 x i8] c"impossible, errno %d\0A\00"
@.str.3 = [41 x i8] c"\C3\A9chec ETXTBSY, fichier d\C3\A9j\C3\A0 utilis\C3\A9\0A\00"
@.str.4 = [45 x i8] c"Ouverture de exemple_exevp en \C3\A9criture ... \00"
@.str.5 = [15 x i8] c"exemple_execvp\00"
@.str.6 = [49 x i8] c"ok\0ATentative d'ex\C3\A9cution de exemple_execvp ... \00"
@.str.7 = [40 x i8] c"\C3\A9chec ETXTBSY fichier d\C3\A9j\C3\A0 utilis\C3\A9\0A\00"
@.str.8 = [12 x i8] c"errno = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i8*]
%4 = bitcast [2 x i8*]* %3 to i8*
%5 = load i32, i32* @stdout
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %1
%9 = load i32, i32* @O_WRONLY
%10 = load i32, i32* @O_APPEND
%11 = or i32 %10, %9
%12 = tail call i32 @open(i8* %8, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %2
%15 = load i32, i32* @errno
%16 = load i32, i32* @ETXTBSY
%17 = icmp eq i32 %15, %16
%18 = load i32, i32* @stdout
br i1 %17, label %22, label %19
19: ; preds = %14
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %14
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %2
%25 = load i32, i32* @stdout
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0))
%27 = load i32, i32* @O_WRONLY
%28 = load i32, i32* @O_APPEND
%29 = or i32 %28, %27
%30 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = icmp slt i32 %30, 0
%32 = load i32, i32* @stdout
br i1 %31, label %33, label %37
33: ; preds = %24
%34 = load i32, i32* @errno
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = tail call i32 @exit(i32 1)
unreachable
37: ; preds = %24
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0))
%39 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%40 = call i32 @execv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %39)
%41 = load i32, i32* @errno
%42 = load i32, i32* @ETXTBSY
%43 = icmp eq i32 %41, %42
%44 = load i32, i32* @stdout
br i1 %43, label %45, label %47
45: ; preds = %37
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0))
br label %49
47: ; preds = %37
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %41)
br label %49
49: ; preds = %47, %45
ret i32 1
}