#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 long mode_t;

/* Variables and functions */
long strtol(char const *, char **, int);
int octal_mode_to_int(const char *str, mode_t *val) {
  char *endp = NULL;
  long lval = strtol(str, &endp, 8);
  if (*endp)
    return 1;
  if (lval > 07777 || lval < 0)
    return 1;
  *val = lval;
  return 0;
}


x86 assembly (clang, -O0):
<octal_mode_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1030 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1157 <octal_mode_to_int+0x47>
movl   $0x1,-0x4(%rbp)
jmp    118e <octal_mode_to_int+0x7e>
cmpq   $0xfff,-0x28(%rbp)
jg     1170 <octal_mode_to_int+0x60>
cmpq   $0x0,-0x28(%rbp)
jge    117c <octal_mode_to_int+0x6c>
movl   $0x1,-0x4(%rbp)
jmp    118e <octal_mode_to_int+0x7e>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<octal_mode_to_int>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x8,%edx
call   1030 <strtol@plt>
mov    %rax,%rcx
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
mov    $0x1,%eax
jne    1150 <octal_mode_to_int+0x40>
cmp    $0xfff,%rcx
ja     1150 <octal_mode_to_int+0x40>
mov    %rcx,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @octal_mode_to_int(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = call i64 @strtol(i8* %0, i8** %3, i32 8)
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
%9 = icmp ugt i64 %5, 4095
%10 = select i1 %8, i1 true, i1 %9
br i1 %10, label %12, label %11
11: ; preds = %2
store i64 %5, i64* %1
br label %12
12: ; preds = %2, %11
%13 = phi i32 [ 0, %11 ], [ 1, %2 ]
ret i32 %13
}