#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 */
scalar_t__ S_ISLNK(int /*<<< orphan*/);
int /*<<< orphan*/ assert(char const *);
scalar_t__ lstat(char const *, struct stat *);
int is_link(const char *fname) {
  assert(fname);
  if (*fname == '\0')
    return 0;
  struct stat s;
  if (lstat(fname, &s) == 0) {
    if (S_ISLNK(s.st_mode))
      return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<is_link>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1161 <is_link+0x31>
movl   $0x0,-0x4(%rbp)
jmp    11a2 <is_link+0x72>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0x0,%rax
jne    119b <is_link+0x6b>
mov    -0x18(%rbp),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%rax
je     1196 <is_link+0x66>
movl   $0x1,-0x4(%rbp)
jmp    11a2 <is_link+0x72>
jmp    119b <is_link+0x6b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_link>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1050 <assert@plt>
cmpb   $0x0,(%rbx)
je     116a <is_link+0x3a>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <lstat@plt>
test   %rax,%rax
jne    116a <is_link+0x3a>
mov    0x8(%rsp),%edi
call   1030 <S_ISLNK@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    116c <is_link+0x3c>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @is_link(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @assert(i8* %5)
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %24
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i64 @lstat(i8* %13, %struct.stat* %4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i64 @S_ISLNK(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 1, i32* %2
br label %24
22: ; preds = %16
br label %23
23: ; preds = %22, %12
store i32 0, i32* %2
br label %24
24: ; preds = %23, %21, %11
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @is_link(i8* %0) {
%2 = alloca %struct.stat
%3 = tail call i32 @assert(i8* %0)
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %1
%7 = bitcast %struct.stat* %2 to i8*
%8 = call i64 @lstat(i8* %0, %struct.stat* %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %6
%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 %15, label %16
15: ; preds = %10, %6
br label %16
16: ; preds = %10, %15
%17 = phi i32 [ 0, %15 ], [ 1, %10 ]
br label %18
18: ; preds = %1, %16
%19 = phi i32 [ %17, %16 ], [ 0, %1 ]
ret i32 %19
}