#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 off_t;

/* Variables and functions */
int /*<<< orphan*/ die(int, char *, ...);
off_t string_to_off(char *p, char **endp) {
  off_t v = 0;
  for (; *p; p++) {
    int digit = *p - '0';
    off_t x = v * 10;
    if (9 < (unsigned)digit) {
      if (endp) {
        *endp = p;
        break;
      }
      die(1, "number parse error near %s", p);
    } else if (x / 10 != v)
      die(1, "number out of allowed range, near %s", p);
    v = x + digit;
    if (v < 0)
      die(1, "negative number");
  }
  if (endp)
    *endp = p;
  return v;
}


x86 assembly (clang, -O0):
<string_to_off>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11f9 <string_to_off+0xe9>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x18(%rbp)
imul   $0xa,-0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x9,%eax
cmp    -0x18(%rbp),%eax
jae    118d <string_to_off+0x7d>
cmpq   $0x0,-0x10(%rbp)
je     1171 <string_to_off+0x61>
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    11f9 <string_to_off+0xe9>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xe7f(%rip),%rsi
mov    $0x0,%al
call   1030 <die@plt>
jmp    11bd <string_to_off+0xad>
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    -0x14(%rbp),%eax
je     11b8 <string_to_off+0xa8>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1030 <die@plt>
jmp    11bd <string_to_off+0xad>
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11e3 <string_to_off+0xd3>
mov    $0x1,%edi
lea    0xe64(%rip),%rsi
mov    $0x0,%al
call   1030 <die@plt>
jmp    11e8 <string_to_off+0xd8>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1127 <string_to_off+0x17>
cmpq   $0x0,-0x10(%rbp)
je     120f <string_to_off+0xff>
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_to_off>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r13
mov    (%rdi),%al
test   %al,%al
je     1191 <string_to_off+0x81>
lea    0xed2(%rip),%r15
lea    0xee6(%rip),%r12
xor    %ebx,%ebx
jmp    116a <string_to_off+0x5a>
nopl   0x0(%rax)
mov    $0x1,%edi
mov    %r15,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1030 <die@plt>
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%eax
add    %eax,%ebp
js     1180 <string_to_off+0x70>
movzbl 0x1(%r13),%eax
add    $0x1,%r13
mov    %ebp,%ebx
test   %al,%al
je     1193 <string_to_off+0x83>
movsbl %al,%ebp
add    $0xffffffd0,%ebp
cmp    $0xa,%ebp
jb     1152 <string_to_off+0x42>
test   %r14,%r14
je     1140 <string_to_off+0x30>
jmp    119a <string_to_off+0x8a>
nopl   0x0(%rax)
mov    $0x1,%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <die@plt>
jmp    115b <string_to_off+0x4b>
xor    %ebp,%ebp
mov    %ebp,%ebx
test   %r14,%r14
je     119f <string_to_off+0x8f>
mov    %r13,(%r14)
mov    %ebx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"number parse error near %s\00"
@.str.1 = [37 x i8] c"number out of allowed range, near %s\00"
@.str.2 = [16 x i8] c"negative number\00"
define i32 @string_to_off(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32 0, i32* %5
br label %8
8: ; preds = %48, %2
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %51
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = sub nsw i32 %15, 48
store i32 %16, i32* %6
%17 = load i32, i32* %5
%18 = mul nsw i32 %17, 10
store i32 %18, i32* %7
%19 = load i32, i32* %6
%20 = icmp ult i32 9, %19
br i1 %20, label %21, label %30
21: ; preds = %12
%22 = load i8**, i8*** %4
%23 = icmp ne i8** %22, null
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i8*, i8** %3
%26 = load i8**, i8*** %4
store i8* %25, i8** %26
br label %51
27: ; preds = %21
%28 = load i8*, i8** %3
%29 = call i32 (i32, i8*, ...) @die(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %39
30: ; preds = %12
%31 = load i32, i32* %7
%32 = sdiv i32 %31, 10
%33 = load i32, i32* %5
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i8*, i8** %3
%37 = call i32 (i32, i8*, ...) @die(i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %35, %30
br label %39
39: ; preds = %38, %27
%40 = load i32, i32* %7
%41 = load i32, i32* %6
%42 = add nsw i32 %40, %41
store i32 %42, i32* %5
%43 = load i32, i32* %5
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %39
%46 = call i32 (i32, i8*, ...) @die(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %47
47: ; preds = %45, %39
br label %48
48: ; preds = %47
%49 = load i8*, i8** %3
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %3
br label %8
51: ; preds = %24, %8
%52 = load i8**, i8*** %4
%53 = icmp ne i8** %52, null
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i8*, i8** %3
%56 = load i8**, i8*** %4
store i8* %55, i8** %56
br label %57
57: ; preds = %54, %51
%58 = load i32, i32* %5
ret i32 %58
}

LLVM IR (-O2):
@.str = [27 x i8] c"number parse error near %s\00"
@.str.2 = [16 x i8] c"negative number\00"
define i32 @string_to_off(i8* %0, i8** writeonly %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %27, label %5
5: ; preds = %2
%6 = icmp eq i8** %1, null
br label %7
7: ; preds = %5, %23
%8 = phi i8 [ %3, %5 ], [ %25, %23 ]
%9 = phi i8* [ %0, %5 ], [ %24, %23 ]
%10 = phi i32 [ 0, %5 ], [ %19, %23 ]
%11 = sext i8 %8 to i32
%12 = add nsw i32 %11, -48
%13 = mul nsw i32 %10, 10
%14 = icmp ugt i32 %12, 9
br i1 %14, label %15, label %18
15: ; preds = %7
br i1 %6, label %16, label %31
16: ; preds = %15
%17 = tail call i32 (i32, i8*, ...) @die(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %18
18: ; preds = %7, %16
%19 = add nsw i32 %12, %13
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 (i32, i8*, ...) @die(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = getelementptr inbounds i8, i8* %9, i64 1
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %7
27: ; preds = %23, %2
%28 = phi i32 [ 0, %2 ], [ %19, %23 ]
%29 = phi i8* [ %0, %2 ], [ %24, %23 ]
%30 = icmp eq i8** %1, null
br i1 %30, label %34, label %31
31: ; preds = %15, %27
%32 = phi i32 [ %28, %27 ], [ %10, %15 ]
%33 = phi i8* [ %29, %27 ], [ %9, %15 ]
store i8* %33, i8** %1
br label %34
34: ; preds = %31, %27
%35 = phi i32 [ %32, %31 ], [ %28, %27 ]
ret i32 %35
}