#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 lstat(char *, struct stat *);
int readlink(char *, char *, int);
int verifie_lien(char *path) {
  struct stat st;
  char buf[PATH_MAX];
  return (lstat(path, &st) != -1) && S_ISLNK(st.st_mode) &&
         (readlink(path, buf, PATH_MAX) != -1) && (lstat(buf, &st) != -1);
}


x86 assembly (clang, -O0):
<verifie_lien>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <lstat@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x21(%rbp)
je     11db <verifie_lien+0xab>
mov    -0x10(%rbp),%edi
call   1030 <S_ISLNK@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
je     11db <verifie_lien+0xab>
mov    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
call   1040 <readlink@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x21(%rbp)
je     11db <verifie_lien+0xab>
mov    -0x30(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <lstat@plt>
cmp    $0xffffffff,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verifie_lien>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    %rsp,%r12
mov    0x2ea5(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x30(%rbp),%rsi
call   1050 <lstat@plt>
xor    %r14d,%r14d
cmp    $0xffffffff,%eax
je     11a8 <verifie_lien+0x78>
mov    -0x30(%rbp),%edi
call   1030 <S_ISLNK@plt>
test   %rax,%rax
je     11a8 <verifie_lien+0x78>
mov    0x0(%r13),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <readlink@plt>
cmp    $0xffffffff,%eax
je     11a8 <verifie_lien+0x78>
lea    -0x30(%rbp),%rsi
mov    %rbx,%rdi
call   1050 <lstat@plt>
xor    %r14d,%r14d
cmp    $0xffffffff,%eax
setne  %r14b
mov    %r12,%rsp
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
define i32 @verifie_lien(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %2
%6 = load i32, i32* @PATH_MAX
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %4
%9 = alloca i8, i64 %7
store i64 %7, i64* %5
%10 = load i8*, i8** %2
%11 = call i32 @lstat(i8* %10, %struct.stat* %3)
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %26
13: ; preds = %1
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i64 @S_ISLNK(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %13
%19 = load i8*, i8** %2
%20 = load i32, i32* @PATH_MAX
%21 = call i32 @readlink(i8* %19, i8* %9, i32 %20)
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 @lstat(i8* %9, %struct.stat* %3)
%25 = icmp ne i32 %24, -1
br label %26
26: ; preds = %23, %18, %13, %1
%27 = phi i1 [ false, %18 ], [ false, %13 ], [ false, %1 ], [ %25, %23 ]
%28 = zext i1 %27 to i32
%29 = load i8*, i8** %4
ret i32 %28
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
define i32 @verifie_lien(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = tail call i8* @llvm.stacksave()
%7 = alloca i8, i64 %5
%8 = call i32 @lstat(i8* %0, %struct.stat* %2)
%9 = icmp eq i32 %8, -1
br i1 %9, label %23, label %10
10: ; preds = %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i64 @S_ISLNK(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %10
%16 = load i32, i32* @PATH_MAX
%17 = call i32 @readlink(i8* %0, i8* %7, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = call i32 @lstat(i8* %7, %struct.stat* %2)
%21 = icmp ne i32 %20, -1
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %19, %15, %10, %1
%24 = phi i32 [ 0, %15 ], [ 0, %10 ], [ 0, %1 ], [ %22, %19 ]
tail call void @llvm.stackrestore(i8* %6)
ret i32 %24
}