#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 */
typedef struct TYPE_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  int fts_info;
  int /*<<< orphan*/ fts_accpath;
  TYPE_1__ *fts_statp;
};
struct TYPE_4__ {
  int st_uid;
  int st_gid;
};
typedef TYPE_2__ FTSENT;
typedef int /*<<< orphan*/ FTS;

/* Variables and functions */
#define FTS_D 133
#define FTS_DNR 132
#define FTS_ERR 131
#define FTS_NS 130
int /*<<< orphan*/ FTS_PHYSICAL;
#define FTS_SL 129
#define FTS_SLNONE 128
int chown(int /*<<< orphan*/, int, int);
scalar_t__ errno;
int /*<<< orphan*/ fts_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fts_open(char **, int /*<<< orphan*/, int /*<<< orphan*/);
TYPE_2__ *fts_read(int /*<<< orphan*/ *);
int PBChown(int uid, int gid, const char *inPath) {
  FTS *ftsp;
  FTSENT *tFile;
  char *tPath[2] = {(char *)inPath, NULL};
  if ((ftsp = fts_open(tPath, FTS_PHYSICAL, 0)) == NULL) {
    return 1;
  }
  while ((tFile = fts_read(ftsp)) != NULL) {
    switch (tFile->fts_info) {
    case FTS_D:
    case FTS_SL:
    case FTS_SLNONE:
      continue;
    case FTS_DNR:
    case FTS_ERR:
    case FTS_NS:
      fts_close(ftsp);
      return 1;
    default:
      break;
    }
    if (uid == tFile->fts_statp->st_uid && gid == tFile->fts_statp->st_gid) {
      continue;
    }
    if (chown(tFile->fts_accpath, uid, gid) == -1) {
      fts_close(ftsp);
      return 1;
    }
  }
  fts_close(ftsp);
  if (errno) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<PBChown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
lea    -0x40(%rbp),%rdi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <fts_open@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1190 <PBChown+0x50>
movl   $0x1,-0x4(%rbp)
jmp    129c <PBChown+0x15c>
jmp    1195 <PBChown+0x55>
mov    -0x20(%rbp),%rdi
call   1040 <fts_read@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     126f <PBChown+0x12f>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
add    $0xffffff80,%eax
sub    $0x2,%eax
jb     11ef <PBChown+0xaf>
jmp    11c6 <PBChown+0x86>
mov    -0x44(%rbp),%eax
add    $0xffffff7e,%eax
sub    $0x3,%eax
jb     11f4 <PBChown+0xb4>
jmp    11dc <PBChown+0x9c>
mov    -0x44(%rbp),%eax
sub    $0x85,%eax
jne    1209 <PBChown+0xc9>
jmp    11ef <PBChown+0xaf>
jmp    1195 <PBChown+0x55>
mov    -0x20(%rbp),%rdi
call   1030 <fts_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    129c <PBChown+0x15c>
jmp    120e <PBChown+0xce>
mov    -0x8(%rbp),%eax
mov    -0x28(%rbp),%rcx
mov    0x8(%rcx),%rcx
cmp    (%rcx),%eax
jne    123a <PBChown+0xfa>
mov    -0xc(%rbp),%eax
mov    -0x28(%rbp),%rcx
mov    0x8(%rcx),%rcx
cmp    0x4(%rcx),%eax
jne    123a <PBChown+0xfa>
jmp    1195 <PBChown+0x55>
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1060 <chown@plt>
cmp    $0xffffffff,%eax
jne    126a <PBChown+0x12a>
mov    -0x20(%rbp),%rdi
call   1030 <fts_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    129c <PBChown+0x15c>
jmp    1195 <PBChown+0x55>
mov    -0x20(%rbp),%rdi
call   1030 <fts_close@plt>
mov    0x2d59(%rip),%rax
cmpq   $0x0,(%rax)
je     1295 <PBChown+0x155>
movl   $0x1,-0x4(%rbp)
jmp    129c <PBChown+0x15c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PBChown>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
mov    %rdx,(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
xor    %edx,%edx
call   1050 <fts_open@plt>
mov    $0x1,%r15d
test   %rax,%rax
je     1201 <PBChown+0xc1>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <fts_read@plt>
test   %rax,%rax
je     11e7 <PBChown+0xa7>
mov    $0x23,%r12d
jmp    11b3 <PBChown+0x73>
nopl   0x0(%rax,%rax,1)
bt     %ecx,%r12d
jae    11dd <PBChown+0x9d>
mov    %rbx,%rdi
call   1040 <fts_read@plt>
test   %rax,%rax
je     11e7 <PBChown+0xa7>
mov    (%rax),%ecx
add    $0xffffff80,%ecx
cmp    $0x5,%ecx
jbe    11a0 <PBChown+0x60>
mov    0x8(%rax),%rcx
cmp    %ebp,(%rcx)
jne    11cb <PBChown+0x8b>
cmp    %r14d,0x4(%rcx)
je     11a6 <PBChown+0x66>
mov    0x4(%rax),%edi
mov    %ebp,%esi
mov    %r14d,%edx
call   1060 <chown@plt>
cmp    $0xffffffff,%eax
jne    11a6 <PBChown+0x66>
mov    %rbx,%rdi
call   1030 <fts_close@plt>
jmp    1201 <PBChown+0xc1>
mov    %rbx,%rdi
call   1030 <fts_close@plt>
mov    0x2de2(%rip),%rax
xor    %r15d,%r15d
cmpq   $0x0,(%rax)
setne  %r15b
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, i32, %struct.TYPE_4__* }
%struct.TYPE_4__ = type { i32, i32 }
@FTS_PHYSICAL = global i32 0
@errno = global i64 0
define i32 @PBChown(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca %struct.TYPE_5__*
%10 = alloca [2 x i8*]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%11 = getelementptr inbounds [2 x i8*], [2 x i8*]* %10, i64 0, i64 0
%12 = load i8*, i8** %7
store i8* %12, i8** %11
%13 = getelementptr inbounds i8*, i8** %11, i64 1
store i8* null, i8** %13
%14 = getelementptr inbounds [2 x i8*], [2 x i8*]* %10, i64 0, i64 0
%15 = load i32, i32* @FTS_PHYSICAL
%16 = call i32* @fts_open(i8** %14, i32 %15, i32 0)
store i32* %16, i32** %8
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %3
store i32 1, i32* %4
br label %69
19: ; preds = %3
br label %20
20: ; preds = %61, %49, %28, %19
%21 = load i32*, i32** %8
%22 = call %struct.TYPE_5__* @fts_read(i32* %21)
store %struct.TYPE_5__* %22, %struct.TYPE_5__** %9
%23 = icmp ne %struct.TYPE_5__* %22, null
br i1 %23, label %24, label %62
24: ; preds = %20
%25 = load %struct.TYPE_5__*, %struct.TYPE_5__** %9
%26 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %25, i32 0, i32 0
%27 = load i32, i32* %26
switch i32 %27, label %32 [
i32 133, label %28
i32 129, label %28
i32 128, label %28
i32 132, label %29
i32 131, label %29
i32 130, label %29
]
28: ; preds = %24, %24, %24
br label %20
29: ; preds = %24, %24, %24
%30 = load i32*, i32** %8
%31 = call i32 @fts_close(i32* %30)
store i32 1, i32* %4
br label %69
32: ; preds = %24
br label %33
33: ; preds = %32
%34 = load i32, i32* %5
%35 = load %struct.TYPE_5__*, %struct.TYPE_5__** %9
%36 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %35, i32 0, i32 2
%37 = load %struct.TYPE_4__*, %struct.TYPE_4__** %36
%38 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %37, i32 0, i32 0
%39 = load i32, i32* %38
%40 = icmp eq i32 %34, %39
br i1 %40, label %41, label %50
41: ; preds = %33
%42 = load i32, i32* %6
%43 = load %struct.TYPE_5__*, %struct.TYPE_5__** %9
%44 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %43, i32 0, i32 2
%45 = load %struct.TYPE_4__*, %struct.TYPE_4__** %44
%46 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %45, i32 0, i32 1
%47 = load i32, i32* %46
%48 = icmp eq i32 %42, %47
br i1 %48, label %49, label %50
49: ; preds = %41
br label %20
50: ; preds = %41, %33
%51 = load %struct.TYPE_5__*, %struct.TYPE_5__** %9
%52 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %51, i32 0, i32 1
%53 = load i32, i32* %52
%54 = load i32, i32* %5
%55 = load i32, i32* %6
%56 = call i32 @chown(i32 %53, i32 %54, i32 %55)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %61
58: ; preds = %50
%59 = load i32*, i32** %8
%60 = call i32 @fts_close(i32* %59)
store i32 1, i32* %4
br label %69
61: ; preds = %50
br label %20
62: ; preds = %20
%63 = load i32*, i32** %8
%64 = call i32 @fts_close(i32* %63)
%65 = load i64, i64* @errno
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %68
67: ; preds = %62
store i32 1, i32* %4
br label %69
68: ; preds = %62
store i32 0, i32* %4
br label %69
69: ; preds = %68, %67, %58, %29, %18
%70 = load i32, i32* %4
ret i32 %70
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, i32, %struct.TYPE_4__* }
%struct.TYPE_4__ = type { i32, i32 }
@FTS_PHYSICAL = global i32 0
@errno = global i64 0
define i32 @PBChown(i32 %0, i32 %1, i8* %2) {
%4 = alloca [2 x i8*]
%5 = bitcast [2 x i8*]* %4 to i8*
%6 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
store i8* %2, i8** %6
%7 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 1
store i8* null, i8** %7
%8 = load i32, i32* @FTS_PHYSICAL
%9 = call i32* @fts_open(i8** %6, i32 %8, i32 0)
%10 = icmp eq i32* %9, null
br i1 %10, label %45, label %11
11: ; preds = %3
%12 = call %struct.TYPE_5__* @fts_read(i32* %9)
%13 = icmp eq %struct.TYPE_5__* %12, null
br i1 %13, label %40, label %14
14: ; preds = %11, %18
%15 = phi %struct.TYPE_5__* [ %19, %18 ], [ %12, %11 ]
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %15, i64 0, i32 0
%17 = load i32, i32* %16
switch i32 %17, label %23 [
i32 133, label %18
i32 129, label %18
i32 128, label %18
i32 132, label %21
i32 131, label %21
i32 130, label %21
]
18: ; preds = %14, %14, %14, %29, %33
%19 = call %struct.TYPE_5__* @fts_read(i32* %9)
%20 = icmp eq %struct.TYPE_5__* %19, null
br i1 %20, label %40, label %14
21: ; preds = %14, %14, %14
%22 = call i32 @fts_close(i32* %9)
br label %45
23: ; preds = %14
%24 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %15, i64 0, i32 2
%25 = load %struct.TYPE_4__*, %struct.TYPE_4__** %24
%26 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %25, i64 0, i32 0
%27 = load i32, i32* %26
%28 = icmp eq i32 %27, %0
br i1 %28, label %29, label %33
29: ; preds = %23
%30 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %25, i64 0, i32 1
%31 = load i32, i32* %30
%32 = icmp eq i32 %31, %1
br i1 %32, label %18, label %33
33: ; preds = %29, %23
%34 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %15, i64 0, i32 1
%35 = load i32, i32* %34
%36 = call i32 @chown(i32 %35, i32 %0, i32 %1)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %18
38: ; preds = %33
%39 = call i32 @fts_close(i32* %9)
br label %45
40: ; preds = %18, %11
%41 = call i32 @fts_close(i32* %9)
%42 = load i64, i64* @errno
%43 = icmp ne i64 %42, 0
%44 = zext i1 %43 to i32
br label %45
45: ; preds = %40, %3, %38, %21
%46 = phi i32 [ 1, %38 ], [ 1, %21 ], [ 1, %3 ], [ %44, %40 ]
ret i32 %46
}