#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int PATH_MAX;
scalar_t__ S_ISLNK(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int lstat(char const *, struct stat *);
int /*<<< orphan*/ printf(char *, ...);
int readlink(char const *, char *, int);
int stat(char *, struct stat *);
int /*<<< orphan*/ strcpy(char *, char const *);
int unlink(char const *);
int main(int argc, char const *argv[]) {
  if (argc != 2) {
    printf("Arg !!");
    exit(-1);
  }
  struct stat st;
  char buf[PATH_MAX];
  if (lstat(argv[1], &st) == -1) {
    printf("pour info %s invalide", argv[1]);
    exit(0);
  }
  if (S_ISLNK(st.st_mode)) {
    printf("pour info %s pas lien symbolique", argv[1]);
    exit(0);
  }
  if (readlink(argv[1], buf, PATH_MAX) == -1) {
    printf("readlink echoue sur %s", argv[1]);
    exit(-1);
  }
  if (stat(buf, &st) == -1) {
    printf("lien vers %s inexistant donc %s supprime", buf, argv[1]);
    char buf1[PATH_MAX], buf2[PATH_MAX];
    strcpy(buf1, argv[1]);
    while (1) {
      if (readlink(buf1, buf2, PATH_MAX) == -1)
        break;
      unlink(buf1);
      strcpy(buf1, buf2);
    }
    if (unlink(argv[1]) == -1) {
      printf("je n'arrive pas a supprimer %s", argv[1]);
    }
    exit(-1);
  } else {
    printf("pour info %s lien valide vers %s", argv[1], buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b8 <main+0x38>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <lstat@plt>
cmp    $0xffffffff,%eax
jne    121b <main+0x9b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1050 <S_ISLNK@plt>
cmp    $0x0,%rax
je     124a <main+0xca>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x48(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d93(%rip),%rax
mov    (%rax),%edx
call   1060 <readlink@plt>
cmp    $0xffffffff,%eax
jne    128d <main+0x10d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x48(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0xffffffff,%eax
jne    138e <main+0x20e>
mov    -0x48(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd9f(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2d2c(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x30(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rdi
sub    %rdx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rcx,-0x38(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
jmp    1319 <main+0x199>
mov    -0x50(%rbp),%rsi
mov    -0x58(%rbp),%rdi
mov    0x2cc8(%rip),%rax
mov    (%rax),%edx
call   1060 <readlink@plt>
cmp    $0xffffffff,%eax
jne    133d <main+0x1bd>
jmp    1358 <main+0x1d8>
mov    -0x58(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    1314 <main+0x194>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    1384 <main+0x204>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd01(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x48(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xcfc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    122c <main+0xac>
mov    %rsi,%r14
mov    %rsp,%r15
mov    0x2e4b(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x8(%rsi),%rdi
lea    -0x28(%rbp),%rsi
call   1080 <lstat@plt>
cmp    $0xffffffff,%eax
je     1244 <main+0xc4>
mov    -0x28(%rbp),%edi
call   1050 <S_ISLNK@plt>
mov    0x8(%r14),%rsi
test   %rax,%rax
jne    1251 <main+0xd1>
mov    (%r12),%edx
mov    %rsi,%rdi
mov    %rbx,%rsi
call   1060 <readlink@plt>
cmp    $0xffffffff,%eax
je     1266 <main+0xe6>
lea    -0x28(%rbp),%rsi
mov    %rbx,%rdi
call   1090 <stat@plt>
mov    0x8(%r14),%rdx
cmp    $0xffffffff,%eax
je     1282 <main+0x102>
lea    0xe90(%rip),%rdi
mov    %rdx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rsp
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdcd(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    0x8(%r14),%rsi
lea    0xdb8(%rip),%rdi
jmp    1258 <main+0xd8>
lea    0xdc5(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    0x8(%r14),%rsi
lea    0xdcd(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xdcc(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%r12),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
nopl   0x0(%rax,%rax,1)
call   1040 <strcpy@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <readlink@plt>
cmp    $0xffffffff,%eax
je     12e9 <main+0x169>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
jmp    12c0 <main+0x140>
mov    0x8(%r14),%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    1309 <main+0x189>
mov    0x8(%r14),%rsi
lea    0xd7c(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [7 x i8] c"Arg !!\00"
@PATH_MAX = global i32 0
@.str.1 = [22 x i8] c"pour info %s invalide\00"
@.str.2 = [33 x i8] c"pour info %s pas lien symbolique\00"
@.str.3 = [23 x i8] c"readlink echoue sur %s\00"
@.str.4 = [41 x i8] c"lien vers %s inexistant donc %s supprime\00"
@.str.5 = [31 x i8] c"je n'arrive pas a supprimer %s\00"
@.str.6 = [33 x i8] c"pour info %s lien valide vers %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2
%18 = load i32, i32* @PATH_MAX
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %7
%21 = alloca i8, i64 %19
store i64 %19, i64* %8
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @lstat(i8* %24, %struct.stat* %6)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %33
27: ; preds = %17
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %17
%34 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i64 @S_ISLNK(i32 %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %33
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %41)
%43 = call i32 @exit(i32 0)
unreachable
44: ; preds = %33
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = load i32, i32* @PATH_MAX
%49 = call i32 @readlink(i8* %47, i8* %21, i32 %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %57
51: ; preds = %44
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %54)
%56 = call i32 @exit(i32 -1)
unreachable
57: ; preds = %44
%58 = call i32 @stat(i8* %21, %struct.stat* %6)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %98
60: ; preds = %57
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 1
%63 = load i8*, i8** %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %21, i8* %63)
%65 = load i32, i32* @PATH_MAX
%66 = zext i32 %65 to i64
%67 = call i8* @llvm.stacksave()
store i8* %67, i8** %9
%68 = alloca i8, i64 %66
store i64 %66, i64* %10
%69 = load i32, i32* @PATH_MAX
%70 = zext i32 %69 to i64
%71 = alloca i8, i64 %70
store i64 %70, i64* %11
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 1
%74 = load i8*, i8** %73
%75 = call i32 @strcpy(i8* %68, i8* %74)
br label %76
76: ; preds = %82, %60
br label %77
77: ; preds = %76
%78 = load i32, i32* @PATH_MAX
%79 = call i32 @readlink(i8* %68, i8* %71, i32 %78)
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %82
81: ; preds = %77
br label %85
82: ; preds = %77
%83 = call i32 @unlink(i8* %68)
%84 = call i32 @strcpy(i8* %68, i8* %71)
br label %76
85: ; preds = %81
%86 = load i8**, i8*** %5
%87 = getelementptr inbounds i8*, i8** %86, i64 1
%88 = load i8*, i8** %87
%89 = call i32 @unlink(i8* %88)
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %96
91: ; preds = %85
%92 = load i8**, i8*** %5
%93 = getelementptr inbounds i8*, i8** %92, i64 1
%94 = load i8*, i8** %93
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %94)
br label %96
96: ; preds = %91, %85
%97 = call i32 @exit(i32 -1)
unreachable
98: ; preds = %57
%99 = load i8**, i8*** %5
%100 = getelementptr inbounds i8*, i8** %99, i64 1
%101 = load i8*, i8** %100
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %101, i8* %21)
br label %103
103: ; preds = %98
store i32 0, i32* %3
%104 = load i8*, i8** %7
%105 = load i32, i32* %3
ret i32 %105
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [7 x i8] c"Arg !!\00"
@PATH_MAX = global i32 0
@.str.1 = [22 x i8] c"pour info %s invalide\00"
@.str.2 = [33 x i8] c"pour info %s pas lien symbolique\00"
@.str.3 = [23 x i8] c"readlink echoue sur %s\00"
@.str.4 = [41 x i8] c"lien vers %s inexistant donc %s supprime\00"
@.str.5 = [31 x i8] c"je n'arrive pas a supprimer %s\00"
@.str.6 = [33 x i8] c"pour info %s lien valide vers %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = icmp eq i32 %0, 2
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = bitcast %struct.stat* %3 to i8*
%10 = load i32, i32* @PATH_MAX
%11 = zext i32 %10 to i64
%12 = tail call i8* @llvm.stacksave()
%13 = alloca i8, i64 %11
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @lstat(i8* %15, %struct.stat* %3)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %8
%19 = load i8*, i8** %14
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = tail call i32 @exit(i32 0)
unreachable
22: ; preds = %8
%23 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%24 = load i32, i32* %23
%25 = tail call i64 @S_ISLNK(i32 %24)
%26 = icmp eq i64 %25, 0
%27 = load i8*, i8** %14
br i1 %26, label %31, label %28
28: ; preds = %22
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%30 = tail call i32 @exit(i32 0)
unreachable
31: ; preds = %22
%32 = load i32, i32* @PATH_MAX
%33 = call i32 @readlink(i8* %27, i8* %13, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = load i8*, i8** %14
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = tail call i32 @exit(i32 -1)
unreachable
39: ; preds = %31
%40 = call i32 @stat(i8* %13, %struct.stat* %3)
%41 = icmp eq i32 %40, -1
%42 = load i8*, i8** %14
br i1 %41, label %43, label %69
43: ; preds = %39
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %13, i8* %42)
%45 = load i32, i32* @PATH_MAX
%46 = zext i32 %45 to i64
%47 = alloca i8, i64 %46
%48 = alloca i8, i64 %46
%49 = load i8*, i8** %14
%50 = call i32 @strcpy(i8* %47, i8* %49)
%51 = load i32, i32* @PATH_MAX
%52 = call i32 @readlink(i8* %47, i8* %48, i32 %51)
%53 = icmp eq i32 %52, -1
br i1 %53, label %60, label %54
54: ; preds = %43, %54
%55 = call i32 @unlink(i8* %47)
%56 = call i32 @strcpy(i8* %47, i8* %48)
%57 = load i32, i32* @PATH_MAX
%58 = call i32 @readlink(i8* %47, i8* %48, i32 %57)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %54
60: ; preds = %54, %43
%61 = load i8*, i8** %14
%62 = call i32 @unlink(i8* %61)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %67
64: ; preds = %60
%65 = load i8*, i8** %14
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %65)
br label %67
67: ; preds = %64, %60
%68 = call i32 @exit(i32 -1)
unreachable
69: ; preds = %39
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %42, i8* %13)
ret i32 0
}