#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;
};

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int chmod(char const *, int const);
int enum_opt_dir(int /*<<< orphan*/, char *, int, int /*<<< orphan*/, int const,
                 int /*<<< orphan*/);
int /*<<< orphan*/ stat(char const *, struct stat *);
int optChmod(const char *src, const int mode, const int isEnum) {
  int ret = 0;
  struct stat info;
  stat(src, &info);
  ret = chmod(src, mode);
  ;
  if (0 == ret) {
    if (S_ISDIR(info.st_mode)) {
      if (isEnum) {
        ret = enum_opt_dir(0, (char *)src, 3, 0, mode, 0);
      }
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<optChmod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <chmod@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    11c4 <optChmod+0x84>
mov    -0x18(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11bf <optChmod+0x7f>
cmpl   $0x0,-0x10(%rbp)
je     11ba <optChmod+0x7a>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x3,%edx
mov    %r9d,%edi
mov    %r9d,%ecx
call   1060 <enum_opt_dir@plt>
mov    %eax,-0x14(%rbp)
jmp    11bf <optChmod+0x7f>
jmp    11c4 <optChmod+0x84>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<optChmod>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <chmod@plt>
test   %eax,%eax
je     1171 <optChmod+0x31>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x8(%rsp),%edi
call   1030 <S_ISDIR@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %r14d,%r14d
je     1168 <optChmod+0x28>
test   %rcx,%rcx
je     1168 <optChmod+0x28>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
mov    %ebp,%r8d
xor    %r9d,%r9d
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <enum_opt_dir@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @optChmod(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.stat
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%9 = load i8*, i8** %4
%10 = call i32 @stat(i8* %9, %struct.stat* %8)
%11 = load i8*, i8** %4
%12 = load i32, i32* %5
%13 = call i32 @chmod(i8* %11, i32 %12)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp eq i32 0, %14
br i1 %15, label %16, label %30
16: ; preds = %3
%17 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i64 @S_ISDIR(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %16
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i8*, i8** %4
%26 = load i32, i32* %5
%27 = call i32 @enum_opt_dir(i32 0, i8* %25, i32 3, i32 0, i32 %26, i32 0)
store i32 %27, i32* %7
br label %28
28: ; preds = %24, %21
br label %29
29: ; preds = %28, %16
br label %30
30: ; preds = %29, %3
%31 = load i32, i32* %7
ret i32 %31
}

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