#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_gid;
  int /*<<< orphan*/ st_uid;
};

/* Variables and functions */
scalar_t__ EPERM;
scalar_t__ errno;
scalar_t__ lchown(char const *, int /*<<< orphan*/, int /*<<< orphan*/);
int setlink(const char *path, struct stat *fs) {
  ;
  ;
  if (lchown(path, fs->st_uid, fs->st_gid)) {
    if (errno != EPERM) {
      do {
      } while (0);
      return (1);
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<setlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   1030 <lchown@plt>
cmp    $0x0,%rax
je     1175 <setlink+0x65>
mov    0x2e99(%rip),%rax
mov    (%rax),%rax
mov    0x2e7f(%rip),%rcx
cmp    (%rcx),%rax
je     1170 <setlink+0x60>
jmp    115f <setlink+0x4f>
jmp    1164 <setlink+0x54>
movl   $0x1,-0x4(%rbp)
jmp    117c <setlink+0x6c>
jmp    1175 <setlink+0x65>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setlink>:
push   %rax
mov    (%rsi),%edx
mov    0x4(%rsi),%esi
call   1030 <lchown@plt>
test   %rax,%rax
je     113b <setlink+0x2b>
mov    0x2eb9(%rip),%rax
mov    (%rax),%rcx
mov    0x2e9f(%rip),%rdx
mov    $0x1,%eax
cmp    (%rdx),%rcx
jne    113d <setlink+0x2d>
xor    %eax,%eax
pop    %rcx
ret

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

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