int file_perms_parse_mode(const unsigned char *mode) {
  char *eptr = 0;
  int m = 0;
  if (!mode)
    return -1;
  if (is_empty_string(mode))
    return -1;
  m = strtol(mode, &eptr, 8);
  if (!is_empty_string(eptr))
    return -1;
  m &= 07777;
  return m;
}


x86 assembly (clang, -O0):
<file_perms_parse_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1152 <file_perms_parse_mode+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <file_perms_parse_mode+0x98>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1030 <is_empty_string@plt>
cmp    $0x0,%eax
je     1172 <file_perms_parse_mode+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <file_perms_parse_mode+0x98>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1040 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1030 <is_empty_string@plt>
cmp    $0x0,%eax
jne    11a7 <file_perms_parse_mode+0x87>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b8 <file_perms_parse_mode+0x98>
mov    -0x1c(%rbp),%eax
and    $0xfff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_perms_parse_mode>:
push   %rbp
push   %rbx
push   %rax
movq   $0x0,(%rsp)
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     116d <file_perms_parse_mode+0x4d>
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <is_empty_string@plt>
test   %eax,%eax
jne    116d <file_perms_parse_mode+0x4d>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1040 <strtol@plt>
mov    %rax,%rbx
mov    (%rsp),%rdi
xor    %eax,%eax
call   1030 <is_empty_string@plt>
test   %eax,%eax
je     116d <file_perms_parse_mode+0x4d>
and    $0xfff,%ebx
mov    %ebx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @file_perms_parse_mode(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* null, i8** %4
store i32 0, i32* %5
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i32 -1, i32* %2
br label %26
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 (i8*, ...) bitcast (i32 (...)* @is_empty_string to i32 (i8*, ...)*)(i8* %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 -1, i32* %2
br label %26
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = call i64 @strtol(i8* %15, i8** %4, i32 8)
%17 = trunc i64 %16 to i32
store i32 %17, i32* %5
%18 = load i8*, i8** %4
%19 = call i32 (i8*, ...) bitcast (i32 (...)* @is_empty_string to i32 (i8*, ...)*)(i8* %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %14
store i32 -1, i32* %2
br label %26
22: ; preds = %14
%23 = load i32, i32* %5
%24 = and i32 %23, 4095
store i32 %24, i32* %5
%25 = load i32, i32* %5
store i32 %25, i32* %2
br label %26
26: ; preds = %22, %21, %13, %8
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
define i32 @file_perms_parse_mode(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%4 = icmp eq i8* %0, null
br i1 %4, label %16, label %5
5: ; preds = %1
%6 = tail call i32 (i8*, ...) bitcast (i32 (...)* @is_empty_string to i32 (i8*, ...)*)(i8* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %5
%9 = call i64 @strtol(i8* %0, i8** %2, i32 8)
%10 = load i8*, i8** %2
%11 = tail call i32 (i8*, ...) bitcast (i32 (...)* @is_empty_string to i32 (i8*, ...)*)(i8* %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = trunc i64 %9 to i32
%15 = and i32 %14, 4095
br label %16
16: ; preds = %8, %5, %1, %13
%17 = phi i32 [ %15, %13 ], [ -1, %1 ], [ -1, %5 ], [ -1, %8 ]
ret i32 %17
}