#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 */
typedef int /*<<< orphan*/ uid_t;
typedef int /*<<< orphan*/ gid_t;

/* Variables and functions */
int errno;
int /*<<< orphan*/ free(char *);
int jfs_util_get_datapath(char const *, char **);
int lchown(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int jfs_security_chown(const char *path, uid_t uid, gid_t gid) {
  char *datapath;
  int rc;
  rc = jfs_util_get_datapath(path, &datapath);
  if (rc) {
    return rc;
  }
  rc = lchown(datapath, uid, gid);
  free(datapath);
  if (rc) {
    return -errno;
  }
  return 0;
}


x86 assembly (clang, -O0):
<jfs_security_chown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <jfs_util_get_datapath@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1167 <jfs_security_chown+0x37>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a6 <jfs_security_chown+0x76>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <lchown@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x24(%rbp)
je     119f <jfs_security_chown+0x6f>
xor    %eax,%eax
mov    0x2e4b(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11a6 <jfs_security_chown+0x76>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jfs_security_chown>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rsp,%rsi
call   1050 <jfs_util_get_datapath@plt>
test   %eax,%eax
jne    116e <jfs_security_chown+0x3e>
mov    (%rsp),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1040 <lchown@plt>
mov    %eax,%ebx
mov    (%rsp),%rdi
call   1030 <free@plt>
test   %ebx,%ebx
je     116c <jfs_security_chown+0x3c>
mov    0x2e7a(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
jmp    116e <jfs_security_chown+0x3e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
define i32 @jfs_security_chown(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
%11 = call i32 @jfs_util_get_datapath(i8* %10, i8** %8)
store i32 %11, i32* %9
%12 = load i32, i32* %9
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = load i32, i32* %9
store i32 %15, i32* %4
br label %29
16: ; preds = %3
%17 = load i8*, i8** %8
%18 = load i32, i32* %6
%19 = load i32, i32* %7
%20 = call i32 @lchown(i8* %17, i32 %18, i32 %19)
store i32 %20, i32* %9
%21 = load i8*, i8** %8
%22 = call i32 @free(i8* %21)
%23 = load i32, i32* %9
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %16
%26 = load i32, i32* @errno
%27 = sub nsw i32 0, %26
store i32 %27, i32* %4
br label %29
28: ; preds = %16
store i32 0, i32* %4
br label %29
29: ; preds = %28, %25, %14
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @jfs_security_chown(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call i32 @jfs_util_get_datapath(i8* %0, i8** %4)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %3
%9 = load i8*, i8** %4
%10 = call i32 @lchown(i8* %9, i32 %1, i32 %2)
%11 = load i8*, i8** %4
%12 = call i32 @free(i8* %11)
%13 = icmp eq i32 %10, 0
br i1 %13, label %17, label %14
14: ; preds = %8
%15 = load i32, i32* @errno
%16 = sub nsw i32 0, %15
br label %17
17: ; preds = %8, %3, %14
%18 = phi i32 [ %16, %14 ], [ %6, %3 ], [ 0, %8 ]
ret i32 %18
}