#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__ calloc(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ isdigit(unsigned char);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
size_t sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int fsReadNumber(unsigned char *buffer, long fileSize, long *contentOffset,
                 int *i) {
  int length = 0;
  for (;; length++) {
    long offset = *contentOffset + length;
    unsigned char c = buffer[offset];
    if (!isdigit(c)) {
      break;
    }
    if (offset >= fileSize) {
      fprintf(stderr,
              "Error: Going out of bounds (offset(%ld) >= fileSize(%ld)).\n",
              offset, fileSize);
      return -1;
    }
  }
  if (length == 0) {
    fprintf(stderr, "Error: length of number string is 0.\n");
    return -1;
  }
  unsigned char *_buffer =
      (unsigned char *)calloc(length + 1, sizeof(unsigned char));
  if (!_buffer) {
    fprintf(stderr, "Error: not enough memory.\n");
    return -1;
  }
  memcpy(_buffer, &(buffer[*contentOffset]), length);
  int number = 0;
  size_t readSize = sscanf((char *)_buffer, "%d", &number);
  if (readSize != 1) {
    fprintf(stderr, "Error: Couldn't read number at offset %ld.\n",
            *contentOffset);
    return -1;
  }
  free(_buffer);
  *contentOffset += length;
  *i = number;
  return 0;
}


x86 assembly (clang, -O0):
<fsReadNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x2c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x39(%rbp)
movzbl -0x39(%rbp),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    11b6 <fsReadNumber+0x56>
jmp    1202 <fsReadNumber+0xa2>
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jl     11ef <fsReadNumber+0x8f>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1303 <fsReadNumber+0x1a3>
jmp    11f4 <fsReadNumber+0x94>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    117f <fsReadNumber+0x1f>
cmpl   $0x0,-0x2c(%rbp)
jne    122f <fsReadNumber+0xcf>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1303 <fsReadNumber+0x1a3>
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1271 <fsReadNumber+0x111>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1303 <fsReadNumber+0x1a3>
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
add    (%rax),%rsi
mov    -0x2c(%rbp),%edx
call   1070 <memcpy@plt>
movl   $0x0,-0x4c(%rbp)
mov    -0x48(%rbp),%rdi
lea    0xde3(%rip),%rsi
lea    -0x4c(%rbp),%rdx
call   1080 <sscanf@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x1,-0x58(%rbp)
je     12dc <fsReadNumber+0x17c>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
lea    0xdb7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1303 <fsReadNumber+0x1a3>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movslq -0x2c(%rbp),%rcx
mov    -0x20(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x4c(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsReadNumber>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%r15
mov    (%rdx),%rbp
movzbl (%rdi,%rbp,1),%edi
call   1040 <isdigit@plt>
test   %eax,%eax
je     123a <fsReadNumber+0xda>
mov    %rbx,0x10(%rsp)
lea    0x1(%r15),%r14
xor    %ecx,%ecx
nopl   0x0(%rax)
cmp    %r13,%rbp
jge    1253 <fsReadNumber+0xf3>
lea    0x1(%rcx),%rbx
mov    (%r12),%rax
lea    (%rcx,%rax,1),%rbp
add    $0x1,%rbp
add    %r14,%rax
movzbl (%rcx,%rax,1),%edi
call   1040 <isdigit@plt>
mov    %rbx,%rcx
test   %eax,%eax
jne    11a0 <fsReadNumber+0x40>
test   %ebx,%ebx
mov    0x10(%rsp),%r14
je     123a <fsReadNumber+0xda>
lea    0x1(%rbx),%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     1284 <fsReadNumber+0x124>
mov    %rax,%rbp
add    (%r12),%r15
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1070 <memcpy@plt>
movl   $0x0,0xc(%rsp)
lea    0xe6f(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbp,%rdi
call   1080 <sscanf@plt>
cmp    $0x1,%rax
jne    1296 <fsReadNumber+0x136>
mov    %ebx,%ebx
mov    %rbp,%rdi
call   1030 <free@plt>
add    %rbx,(%r12)
mov    0xc(%rsp),%eax
mov    %eax,(%r14)
xor    %eax,%eax
jmp    1275 <fsReadNumber+0x115>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1270 <fsReadNumber+0x110>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
lea    0xd9d(%rip),%rsi
mov    %rbp,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
lea    0xdce(%rip),%rsi
jmp    124a <fsReadNumber+0xea>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xdd6(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1270 <fsReadNumber+0x110>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [60 x i8] c"Error: Going out of bounds (offset(%ld) >= fileSize(%ld)).\0A\00"
@.str.1 = [38 x i8] c"Error: length of number string is 0.\0A\00"
@.str.2 = [27 x i8] c"Error: not enough memory.\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [44 x i8] c"Error: Couldn't read number at offset %ld.\0A\00"
define i32 @fsReadNumber(i8* %0, i64 %1, i64* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i64
%12 = alloca i8
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64* %2, i64** %8
store i32* %3, i32** %9
store i32 0, i32* %10
br label %16
16: ; preds = %40, %4
%17 = load i64*, i64** %8
%18 = load i64, i64* %17
%19 = load i32, i32* %10
%20 = sext i32 %19 to i64
%21 = add nsw i64 %18, %20
store i64 %21, i64* %11
%22 = load i8*, i8** %6
%23 = load i64, i64* %11
%24 = getelementptr inbounds i8, i8* %22, i64 %23
%25 = load i8, i8* %24
store i8 %25, i8* %12
%26 = load i8, i8* %12
%27 = call i32 @isdigit(i8 zeroext %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %16
br label %43
30: ; preds = %16
%31 = load i64, i64* %11
%32 = load i64, i64* %7
%33 = icmp sge i64 %31, %32
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = load i64, i64* %11
%37 = load i64, i64* %7
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i64 %36, i64 %37)
store i32 -1, i32* %5
br label %86
39: ; preds = %30
br label %40
40: ; preds = %39
%41 = load i32, i32* %10
%42 = add nsw i32 %41, 1
store i32 %42, i32* %10
br label %16
43: ; preds = %29
%44 = load i32, i32* %10
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %5
br label %86
49: ; preds = %43
%50 = load i32, i32* %10
%51 = add nsw i32 %50, 1
%52 = call i64 @calloc(i32 %51, i32 1)
%53 = inttoptr i64 %52 to i8*
store i8* %53, i8** %13
%54 = load i8*, i8** %13
%55 = icmp ne i8* %54, null
br i1 %55, label %59, label %56
56: ; preds = %49
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %5
br label %86
59: ; preds = %49
%60 = load i8*, i8** %13
%61 = load i8*, i8** %6
%62 = load i64*, i64** %8
%63 = load i64, i64* %62
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i32, i32* %10
%66 = call i32 @memcpy(i8* %60, i8* %64, i32 %65)
store i32 0, i32* %14
%67 = load i8*, i8** %13
%68 = call i64 @sscanf(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %14)
store i64 %68, i64* %15
%69 = load i64, i64* %15
%70 = icmp ne i64 %69, 1
br i1 %70, label %71, label %76
71: ; preds = %59
%72 = load i32, i32* @stderr
%73 = load i64*, i64** %8
%74 = load i64, i64* %73
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i64 %74)
store i32 -1, i32* %5
br label %86
76: ; preds = %59
%77 = load i8*, i8** %13
%78 = call i32 @free(i8* %77)
%79 = load i32, i32* %10
%80 = sext i32 %79 to i64
%81 = load i64*, i64** %8
%82 = load i64, i64* %81
%83 = add nsw i64 %82, %80
store i64 %83, i64* %81
%84 = load i32, i32* %14
%85 = load i32*, i32** %9
store i32 %84, i32* %85
store i32 0, i32* %5
br label %86
86: ; preds = %76, %71, %56, %46, %34
%87 = load i32, i32* %5
ret i32 %87
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [60 x i8] c"Error: Going out of bounds (offset(%ld) >= fileSize(%ld)).\0A\00"
@.str.1 = [38 x i8] c"Error: length of number string is 0.\0A\00"
@.str.2 = [27 x i8] c"Error: not enough memory.\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [44 x i8] c"Error: Couldn't read number at offset %ld.\0A\00"
define i32 @fsReadNumber(i8* %0, i64 %1, i64* nocapture %2, i32* nocapture writeonly %3) {
%5 = alloca i32
%6 = load i64, i64* %2
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = tail call i32 @isdigit(i8 zeroext %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %30, label %11
11: ; preds = %4, %18
%12 = phi i64 [ %19, %18 ], [ 0, %4 ]
%13 = phi i64 [ %21, %18 ], [ %6, %4 ]
%14 = icmp slt i64 %13, %1
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i64 %13, i64 %1)
br label %59
18: ; preds = %11
%19 = add nuw i64 %12, 1
%20 = load i64, i64* %2
%21 = add nsw i64 %20, %19
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = tail call i32 @isdigit(i8 zeroext %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %11
26: ; preds = %18
%27 = trunc i64 %19 to i32
%28 = and i64 %19, 4294967295
%29 = icmp eq i32 %27, 0
br i1 %29, label %30, label %33
30: ; preds = %4, %26
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %59
33: ; preds = %26
%34 = add nuw nsw i32 %27, 1
%35 = tail call i64 @calloc(i32 %34, i32 1)
%36 = inttoptr i64 %35 to i8*
%37 = icmp eq i64 %35, 0
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %59
41: ; preds = %33
%42 = load i64, i64* %2
%43 = getelementptr inbounds i8, i8* %0, i64 %42
%44 = tail call i32 @memcpy(i8* %36, i8* %43, i32 %27)
%45 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%46 = call i64 @sscanf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%47 = icmp eq i64 %46, 1
br i1 %47, label %52, label %48
48: ; preds = %41
%49 = load i32, i32* @stderr
%50 = load i64, i64* %2
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i64 %50)
br label %57
52: ; preds = %41
%53 = call i32 @free(i8* %36)
%54 = load i64, i64* %2
%55 = add nsw i64 %54, %28
store i64 %55, i64* %2
%56 = load i32, i32* %5
store i32 %56, i32* %3
br label %57
57: ; preds = %52, %48
%58 = phi i32 [ -1, %48 ], [ 0, %52 ]
br label %59
59: ; preds = %15, %38, %57, %30
%60 = phi i32 [ -1, %30 ], [ %58, %57 ], [ -1, %38 ], [ -1, %15 ]
ret i32 %60
}