#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*/ mode_t;

/* Variables and functions */
int chmod(char *, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ free(char *);
int jfs_util_get_datapath(char const *, char **);
int jfs_security_chmod(const char *path, mode_t mode) {
  char *datapath;
  int rc;
  rc = jfs_util_get_datapath(path, &datapath);
  if (rc) {
    return rc;
  }
  rc = chmod(datapath, mode);
  free(datapath);
  if (rc) {
    return -errno;
  }
  return 0;
}


x86 assembly (clang, -O0):
<jfs_security_chmod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%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     1164 <jfs_security_chmod+0x34>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a0 <jfs_security_chmod+0x70>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <chmod@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x24(%rbp)
je     1199 <jfs_security_chmod+0x69>
xor    %eax,%eax
mov    0x2e51(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11a0 <jfs_security_chmod+0x70>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jfs_security_chmod>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
lea    0x8(%rsp),%rsi
call   1050 <jfs_util_get_datapath@plt>
test   %eax,%eax
jne    1170 <jfs_security_chmod+0x40>
mov    0x8(%rsp),%rdi
mov    %ebx,%esi
call   1040 <chmod@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
test   %ebx,%ebx
je     116e <jfs_security_chmod+0x3e>
mov    0x2e78(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
jmp    1170 <jfs_security_chmod+0x40>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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