#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;
};
typedef int /*<<< orphan*/ mode_t;

/* Variables and functions */
scalar_t__ S_ISLNK(int /*<<< orphan*/);
int chmod(char const *, int /*<<< orphan*/);
scalar_t__ lstat(char const *, struct stat *);
int lchmod(const char *path, mode_t mode) {
  struct stat st;
  if (lstat(path, &st))
    return -1;
  if (S_ISLNK(st.st_mode))
    return 0;
  return chmod(path, mode);
}


x86 assembly (clang, -O0):
<lchmod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0x0,%rax
je     1162 <lchmod+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    118f <lchmod+0x5f>
mov    -0x18(%rbp),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%rax
je     1180 <lchmod+0x50>
movl   $0x0,-0x4(%rbp)
jmp    118f <lchmod+0x5f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <chmod@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lchmod>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1040 <lstat@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    115f <lchmod+0x2f>
mov    (%rsp),%edi
call   1030 <S_ISLNK@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     1166 <lchmod+0x36>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %rbx,%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <chmod@plt>

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

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @lchmod(i8* nocapture %0, i32 %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i64 @lstat(i8* %0, %struct.stat* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %2
%8 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i64 @S_ISLNK(i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @chmod(i8* %0, i32 %1)
br label %14
14: ; preds = %7, %2, %12
%15 = phi i32 [ %13, %12 ], [ -1, %2 ], [ 0, %7 ]
ret i32 %15
}