#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 */

/* Variables and functions */
scalar_t__ ERANGE;
scalar_t__ errno;
int strlen(char *);
long long strtoll(char *, int /*<<< orphan*/ *, int);
long long strtot(char *ptr) {
  long long retval;
  int len;
  errno = 0;
  if ((retval = strtoll(ptr, NULL, 10))) {
    if (errno == ERANGE)
      return (0);
    if ((len = strlen(ptr)) >= 10 && len < 13)
      retval *= 1000;
    else if (len < 10 || len > 15)
      retval = 0;
  }
  return retval;
}


x86 assembly (clang, -O0):
<strtot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ea5(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtoll@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11d7 <strtot+0xb7>
mov    0x2e77(%rip),%rax
mov    (%rax),%rax
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%rax
jne    1181 <strtot+0x61>
movq   $0x0,-0x8(%rbp)
jmp    11df <strtot+0xbf>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xa,%eax
jl     11b1 <strtot+0x91>
cmpl   $0xd,-0x1c(%rbp)
jge    11b1 <strtot+0x91>
imul   $0x3e8,-0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11d2 <strtot+0xb2>
cmpl   $0xa,-0x1c(%rbp)
jl     11c5 <strtot+0xa5>
cmpl   $0xf,-0x1c(%rbp)
jle    11cd <strtot+0xad>
movq   $0x0,-0x18(%rbp)
jmp    11d2 <strtot+0xb2>
jmp    11d7 <strtot+0xb7>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtot>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2ea6(%rip),%r12
movq   $0x0,(%r12)
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtoll@plt>
test   %rax,%rax
je     118c <strtot+0x6c>
mov    %rax,%r15
mov    (%r12),%rax
mov    0x2e8d(%rip),%rcx
cmp    (%rcx),%rax
jne    1164 <strtot+0x44>
xor    %ebx,%ebx
jmp    118c <strtot+0x6c>
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    -0xa(%rax),%ecx
cmp    $0x2,%ecx
ja     117d <strtot+0x5d>
imul   $0x3e8,%r15,%rbx
jmp    118c <strtot+0x6c>
add    $0xfffffff0,%eax
xor    %ecx,%ecx
cmp    $0xfffffffa,%eax
cmovb  %rcx,%r15
mov    %r15,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
define i64 @strtot(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %3
store i64 0, i64* @errno
%6 = load i8*, i8** %3
%7 = call i64 @strtoll(i8* %6, i32* null, i32 10)
store i64 %7, i64* %4
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %33
9: ; preds = %1
%10 = load i64, i64* @errno
%11 = load i64, i64* @ERANGE
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %9
store i64 0, i64* %2
br label %35
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %5
%17 = icmp sge i32 %16, 10
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 13
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i64, i64* %4
%23 = mul nsw i64 %22, 1000
store i64 %23, i64* %4
br label %32
24: ; preds = %18, %14
%25 = load i32, i32* %5
%26 = icmp slt i32 %25, 10
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load i32, i32* %5
%29 = icmp sgt i32 %28, 15
br i1 %29, label %30, label %31
30: ; preds = %27, %24
store i64 0, i64* %4
br label %31
31: ; preds = %30, %27
br label %32
32: ; preds = %31, %21
br label %33
33: ; preds = %32, %1
%34 = load i64, i64* %4
store i64 %34, i64* %2
br label %35
35: ; preds = %33, %13
%36 = load i64, i64* %2
ret i64 %36
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
define i64 @strtot(i8* %0) {
store i64 0, i64* @errno
%2 = tail call i64 @strtoll(i8* nocapture %0, i32* null, i32 10)
%3 = icmp eq i64 %2, 0
br i1 %3, label %18, label %4
4: ; preds = %1
%5 = load i64, i64* @errno
%6 = load i64, i64* @ERANGE
%7 = icmp eq i64 %5, %6
br i1 %7, label %18, label %8
8: ; preds = %4
%9 = tail call i32 @strlen(i8* %0)
%10 = add i32 %9, -10
%11 = icmp ult i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = mul nsw i64 %2, 1000
br label %18
14: ; preds = %8
%15 = add i32 %9, -16
%16 = icmp ult i32 %15, -6
%17 = select i1 %16, i64 0, i64 %2
br label %18
18: ; preds = %14, %1, %12, %4
%19 = phi i64 [ 0, %4 ], [ %13, %12 ], [ 0, %1 ], [ %17, %14 ]
ret i64 %19
}