#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 */
scalar_t__ chmod(char *, int /*<<< orphan*/);
int /*<<< orphan*/ cm_recurse(char *, char *, int (*)(char *, char *, int));
int errno;
int /*<<< orphan*/ strtol(char *, char **, int);
int cm_set_mode(char *path, char *mode, int recurse) {
  if (recurse) {
    cm_recurse(path, mode, cm_set_mode);
  }
  char *e;
  mode_t m = strtol(mode, &e, 8);
  errno = 0;
  if (chmod(path, m) != 0) {
    return -errno;
  }
  return 0;
}


x86 assembly (clang, -O0):
<cm_set_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1161 <cm_set_mode+0x31>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e8c(%rip),%rdx
call   1040 <cm_recurse@plt>
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x8,%edx
call   1030 <strtol@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2e5b(%rip),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1050 <chmod@plt>
cmp    $0x0,%rax
je     11ac <cm_set_mode+0x7c>
xor    %eax,%eax
mov    0x2e36(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11b3 <cm_set_mode+0x83>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cm_set_mode>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
test   %edx,%edx
je     1150 <cm_set_mode+0x20>
mov    0x2ea3(%rip),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <cm_recurse@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1030 <strtol@plt>
mov    0x2e71(%rip),%rbx
movl   $0x0,(%rbx)
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <chmod@plt>
xor    %ecx,%ecx
sub    (%rbx),%ecx
xor    %edx,%edx
test   %rax,%rax
cmove  %edx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@errno = global i32 0
define i32 @cm_set_mode(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = icmp eq i32 %2, 0
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @cm_recurse(i8* %0, i8* %1, i32 (i8*, i8*, i32)* @cm_set_mode)
br label %8
8: ; preds = %6, %3
%9 = bitcast i8** %4 to i8*
%10 = call i32 @strtol(i8* %1, i8** %4, i32 8)
store i32 0, i32* @errno
%11 = tail call i64 @chmod(i8* %0, i32 %10)
%12 = icmp eq i64 %11, 0
%13 = load i32, i32* @errno
%14 = sub nsw i32 0, %13
%15 = select i1 %12, i32 0, i32 %14
ret i32 %15
}