#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__ isdigit(int);
int /*<<< orphan*/ strtol(char const *, int /*<<< orphan*/ *, int);
int _mode_digit(char const *mode, mode_t *mask) {
  char const *p;
  int i;
  for (p = mode; (i = *p) != '\0' && isdigit(i) && i < '8'; p++)
    ;
  if (*p == '\0') {
    *mask = strtol(mode, NULL, 8);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<_mode_digit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
mov    %ecx,-0x24(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x25(%rbp)
je     1174 <_mode_digit+0x54>
mov    -0x24(%rbp),%edi
call   1030 <isdigit@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x25(%rbp)
je     1174 <_mode_digit+0x54>
cmpl   $0x38,-0x24(%rbp)
setl   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1184 <_mode_digit+0x64>
jmp    119a <_mode_digit+0x7a>
jmp    1189 <_mode_digit+0x69>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1138 <_mode_digit+0x18>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d0 <_mode_digit+0xb0>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x8,%edx
call   1040 <strtol@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11d7 <_mode_digit+0xb7>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_mode_digit>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%bpl
test   %bpl,%bpl
je     116e <_mode_digit+0x4e>
lea    0x1(%r15),%rbx
nopw   0x0(%rax,%rax,1)
movsbl %bpl,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1162 <_mode_digit+0x42>
cmp    $0x37,%bpl
jg     1162 <_mode_digit+0x42>
movzbl (%rbx),%ebp
add    $0x1,%rbx
test   %bpl,%bpl
jne    1140 <_mode_digit+0x20>
jmp    116e <_mode_digit+0x4e>
mov    $0x1,%r12d
cmpb   $0x0,-0x1(%rbx)
jne    1183 <_mode_digit+0x63>
xor    %r12d,%r12d
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <strtol@plt>
mov    %eax,(%r14)
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @_mode_digit(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
store i8* %8, i8** %6
br label %9
9: ; preds = %24, %2
%10 = load i8*, i8** %6
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
store i32 %12, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %9
%15 = load i32, i32* %7
%16 = call i64 @isdigit(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 56
br label %21
21: ; preds = %18, %14, %9
%22 = phi i1 [ false, %14 ], [ false, %9 ], [ %20, %18 ]
br i1 %22, label %23, label %27
23: ; preds = %21
br label %24
24: ; preds = %23
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %6
br label %9
27: ; preds = %21
%28 = load i8*, i8** %6
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = load i8*, i8** %4
%34 = call i32 @strtol(i8* %33, i32* null, i32 8)
%35 = load i32*, i32** %5
store i32 %34, i32* %35
store i32 0, i32* %3
br label %37
36: ; preds = %27
store i32 1, i32* %3
br label %37
37: ; preds = %36, %32
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @_mode_digit(i8* nocapture %0, i32* nocapture writeonly %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %20, label %5
5: ; preds = %2, %13
%6 = phi i8 [ %15, %13 ], [ %3, %2 ]
%7 = phi i8* [ %14, %13 ], [ %0, %2 ]
%8 = sext i8 %6 to i32
%9 = tail call i64 @isdigit(i32 %8)
%10 = icmp ne i64 %9, 0
%11 = icmp slt i8 %6, 56
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %17
13: ; preds = %5
%14 = getelementptr inbounds i8, i8* %7, i64 1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %20, label %5
17: ; preds = %5
%18 = load i8, i8* %7
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %13, %2, %17
%21 = tail call i32 @strtol(i8* nocapture %0, i32* null, i32 8)
store i32 %21, i32* %1
br label %22
22: ; preds = %17, %20
%23 = phi i32 [ 0, %20 ], [ 1, %17 ]
ret i32 %23
}