#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 */
int atoi(char *);
scalar_t__ isdigit(char const);
int /*<<< orphan*/ skip_comment(char const **);
int scan_int(const char **document) {
  const char *cursor = *document, *end;
  int length = 0;
  char buffer[16];
  int retval;
  int i;
  while (isdigit(*cursor) || *cursor == '#' || *cursor == '-') {
    if (*cursor == '#') {
      skip_comment(&cursor);
      continue;
    }
    length++;
    cursor++;
  }
  if (length > 15)
    length = 15;
  end = cursor;
  cursor = *document;
  buffer[length] = '\0';
  for (i = 0; i < length; i++) {
    if (*cursor == '#') {
      skip_comment(&cursor);
      i--;
      continue;
    }
    buffer[i] = *cursor;
    cursor++;
  }
  retval = atoi(buffer);
  *document = end;
  return retval;
}


x86 assembly (clang, -O0):
<scan_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x39(%rbp)
jne    1191 <scan_int+0x61>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x23,%ecx
mov    %al,-0x39(%rbp)
je     1191 <scan_int+0x61>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
sete   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11a1 <scan_int+0x71>
jmp    11d9 <scan_int+0xa9>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    11bf <scan_int+0x8f>
lea    -0x10(%rbp),%rdi
call   1040 <skip_comment@plt>
jmp    114e <scan_int+0x1e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    114e <scan_int+0x1e>
cmpl   $0xf,-0x1c(%rbp)
jle    11ea <scan_int+0xba>
movl   $0xf,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1268 <scan_int+0x138>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1240 <scan_int+0x110>
lea    -0x10(%rbp),%rdi
call   1040 <skip_comment@plt>
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
jmp    125a <scan_int+0x12a>
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
movslq -0x38(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    120d <scan_int+0xdd>
lea    -0x30(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
mov    (%rdi),%rbx
mov    %rbx,0x8(%rsp)
xor    %r12d,%r12d
lea    0x8(%rsp),%r15
jmp    1172 <scan_int+0x42>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x23,%cl
jne    1191 <scan_int+0x61>
mov    %r15,%rdi
call   1040 <skip_comment@plt>
mov    0x8(%rsp),%rbx
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
mov    0x8(%rsp),%rbx
movzbl (%rbx),%ecx
test   %rax,%rax
jne    1160 <scan_int+0x30>
cmp    $0x23,%cl
je     1165 <scan_int+0x35>
cmp    $0x2d,%cl
jne    11a0 <scan_int+0x70>
add    $0x1,%r12d
add    $0x1,%rbx
mov    %rbx,0x8(%rsp)
jmp    1172 <scan_int+0x42>
cmp    $0xf,%r12d
mov    $0xf,%r13d
cmovb  %r12d,%r13d
mov    (%r14),%rax
mov    %rax,0x8(%rsp)
movb   $0x0,0x10(%rsp,%r13,1)
test   %r13d,%r13d
je     120f <scan_int+0xdf>
xor    %ebp,%ebp
lea    0x8(%rsp),%r15
nopl   0x0(%rax,%rax,1)
movzbl (%rax),%ecx
cmp    $0x23,%cl
jne    11f0 <scan_int+0xc0>
mov    %r15,%rdi
call   1040 <skip_comment@plt>
add    $0xffffffff,%ebp
jmp    1200 <scan_int+0xd0>
cs nopw 0x0(%rax,%rax,1)
nop
movslq %ebp,%rdx
mov    %cl,0x10(%rsp,%rdx,1)
add    $0x1,%rax
mov    %rax,0x8(%rsp)
add    $0x1,%ebp
cmp    %r13d,%ebp
jge    120f <scan_int+0xdf>
mov    0x8(%rsp),%rax
jmp    11d0 <scan_int+0xa0>
lea    0x10(%rsp),%rdi
call   1050 <atoi@plt>
mov    %rbx,(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @scan_int(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [16 x i8]
%7 = alloca i32
%8 = alloca i32
store i8** %0, i8*** %2
%9 = load i8**, i8*** %2
%10 = load i8*, i8** %9
store i8* %10, i8** %3
store i32 0, i32* %5
br label %11
11: ; preds = %35, %33, %1
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = call i64 @isdigit(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %26, label %16
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 35
br i1 %20, label %26, label %21
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 45
br label %26
26: ; preds = %21, %16, %11
%27 = phi i1 [ true, %16 ], [ true, %11 ], [ %25, %21 ]
br i1 %27, label %28, label %40
28: ; preds = %26
%29 = load i8*, i8** %3
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 35
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = call i32 @skip_comment(i8** %3)
br label %11
35: ; preds = %28
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
%38 = load i8*, i8** %3
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %3
br label %11
40: ; preds = %26
%41 = load i32, i32* %5
%42 = icmp sgt i32 %41, 15
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 15, i32* %5
br label %44
44: ; preds = %43, %40
%45 = load i8*, i8** %3
store i8* %45, i8** %4
%46 = load i8**, i8*** %2
%47 = load i8*, i8** %46
store i8* %47, i8** %3
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 %49
store i8 0, i8* %50
store i32 0, i32* %8
br label %51
51: ; preds = %72, %44
%52 = load i32, i32* %8
%53 = load i32, i32* %5
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %75
55: ; preds = %51
%56 = load i8*, i8** %3
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 35
br i1 %59, label %60, label %64
60: ; preds = %55
%61 = call i32 @skip_comment(i8** %3)
%62 = load i32, i32* %8
%63 = add nsw i32 %62, -1
store i32 %63, i32* %8
br label %72
64: ; preds = %55
%65 = load i8*, i8** %3
%66 = load i8, i8* %65
%67 = load i32, i32* %8
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 %68
store i8 %66, i8* %69
%70 = load i8*, i8** %3
%71 = getelementptr inbounds i8, i8* %70, i32 1
store i8* %71, i8** %3
br label %72
72: ; preds = %64, %60
%73 = load i32, i32* %8
%74 = add nsw i32 %73, 1
store i32 %74, i32* %8
br label %51
75: ; preds = %51
%76 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%77 = call i32 @atoi(i8* %76)
store i32 %77, i32* %7
%78 = load i8*, i8** %4
%79 = load i8**, i8*** %2
store i8* %78, i8** %79
%80 = load i32, i32* %7
ret i32 %80
}

LLVM IR (-O2):
define i32 @scan_int(i8** nocapture %0) {
%2 = alloca i8*
%3 = alloca [16 x i8]
%4 = bitcast i8** %2 to i8*
%5 = load i8*, i8** %0
store i8* %5, i8** %2
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
br label %7
7: ; preds = %23, %1
%8 = phi i8* [ %25, %23 ], [ %5, %1 ]
%9 = phi i32 [ %24, %23 ], [ 0, %1 ]
br label %10
10: ; preds = %7, %20
%11 = phi i8* [ %8, %7 ], [ %22, %20 ]
%12 = load i8, i8* %11
%13 = call i64 @isdigit(i8 signext %12)
%14 = icmp eq i64 %13, 0
%15 = load i8*, i8** %2
%16 = load i8, i8* %15
br i1 %14, label %17, label %18
17: ; preds = %10
switch i8 %16, label %26 [
i8 35, label %20
i8 45, label %23
]
18: ; preds = %10
%19 = icmp eq i8 %16, 35
br i1 %19, label %20, label %23
20: ; preds = %17, %18
%21 = call i32 @skip_comment(i8** %2)
%22 = load i8*, i8** %2
br label %10
23: ; preds = %17, %18
%24 = add nuw nsw i32 %9, 1
%25 = getelementptr inbounds i8, i8* %15, i64 1
store i8* %25, i8** %2
br label %7
26: ; preds = %17
%27 = icmp ult i32 %9, 15
%28 = select i1 %27, i32 %9, i32 15
%29 = load i8*, i8** %0
store i8* %29, i8** %2
%30 = zext i32 %28 to i64
%31 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %30
store i8 0, i8* %31
%32 = icmp eq i32 %28, 0
br i1 %32, label %51, label %33
33: ; preds = %26, %49
%34 = phi i8* [ %50, %49 ], [ %29, %26 ]
%35 = phi i32 [ %47, %49 ], [ 0, %26 ]
%36 = load i8, i8* %34
%37 = icmp eq i8 %36, 35
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = call i32 @skip_comment(i8** %2)
%40 = add nsw i32 %35, -1
br label %45
41: ; preds = %33
%42 = sext i32 %35 to i64
%43 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %42
store i8 %36, i8* %43
%44 = getelementptr inbounds i8, i8* %34, i64 1
store i8* %44, i8** %2
br label %45
45: ; preds = %41, %38
%46 = phi i32 [ %40, %38 ], [ %35, %41 ]
%47 = add nsw i32 %46, 1
%48 = icmp slt i32 %47, %28
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = load i8*, i8** %2
br label %33
51: ; preds = %45, %26
%52 = call i32 @atoi(i8* %6)
store i8* %15, i8** %0
ret i32 %52
}