#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 scalar_t__ time_t;

/* Variables and functions */
scalar_t__ EINVAL;
scalar_t__ errno;
int /*<<< orphan*/ isdigit(char const);
scalar_t__ strtol(char const *, char **, int);
scalar_t__ strtoll(char const *, char **, int);
time_t strtotime(const char *str, const char **end) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-qual"
  time_t rc;
  do {
    if (!(isdigit(*str)))
      return errno = (EINVAL), -1;
  } while (0);
  errno = 0;
  if (sizeof(time_t) == sizeof(long long int))
    rc = (time_t)strtoll(str, (char **)end, 10);
  else
    rc = (time_t)strtol(str, (char **)end, 10);
  return errno ? 0 : rc;
#pragma GCC diagnostic pop
}


x86 assembly (clang, -O0):
<strtotime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1166 <strtotime+0x46>
mov    0x2e8c(%rip),%rax
mov    (%rax),%rcx
mov    0x2e8a(%rip),%rax
mov    %rcx,(%rax)
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11bb <strtotime+0x9b>
jmp    116b <strtotime+0x4b>
mov    0x2e6e(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoll@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e4a(%rip),%rax
cmpq   $0x0,(%rax)
je     11ab <strtotime+0x8b>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    11b3 <strtotime+0x93>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtotime>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     1164 <strtotime+0x44>
mov    0x2ea2(%rip),%r15
movq   $0x0,(%r15)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1040 <strtoll@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmpq   $0x0,(%r15)
cmove  %rcx,%rax
jmp    117f <strtotime+0x5f>
mov    0x2e6d(%rip),%rax
mov    (%rax),%rax
mov    0x2e6b(%rip),%rcx
mov    %rax,(%rcx)
mov    $0xffffffffffffffff,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@EINVAL = global i64 0
@errno = global i64 0
define i64 @strtotime(i8* %0, i8** nocapture %1) {
%3 = load i8, i8* %0
%4 = tail call i32 @isdigit(i8 signext %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = load i64, i64* @EINVAL
store i64 %7, i64* @errno
br label %13
8: ; preds = %2
store i64 0, i64* @errno
%9 = tail call i64 @strtoll(i8* %0, i8** %1, i32 10)
%10 = load i64, i64* @errno
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i64 %9, i64 0
br label %13
13: ; preds = %8, %6
%14 = phi i64 [ %12, %8 ], [ -1, %6 ]
ret i64 %14
}