#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
long INT_MAX;
long INT_MIN;
scalar_t__ errno;
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ isdigit(int);
long strtol(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int _xdg_mime_magic_read_a_number(FILE *magic_file, int *end_of_file) {
  char number_string[30 + 1];
  int pos = 0;
  int c;
  long retval = -1;
  while ((!(0))) {
    c = getc(magic_file);
    if (c == EOF) {
      *end_of_file = (!(0));
      break;
    }
    if (!isdigit(c)) {
      ungetc(c, magic_file);
      break;
    }
    number_string[pos] = (char)c;
    pos++;
    if (pos == 30)
      break;
  }
  if (pos > 0) {
    number_string[pos] = '\000';
    errno = 0;
    retval = strtol(number_string, NULL, 10);
    if ((retval < INT_MIN) || (retval > INT_MAX) || (errno != 0))
      return -1;
  }
  return retval;
}


x86 assembly (clang, -O0):
<_xdg_mime_magic_read_a_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x44(%rbp)
movq   $0xffffffffffffffff,-0x50(%rbp)
ff
mov    -0x10(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%eax
jne    118c <_xdg_mime_magic_read_a_number+0x4c>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    11d8 <_xdg_mime_magic_read_a_number+0x98>
mov    -0x48(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11ae <_xdg_mime_magic_read_a_number+0x6e>
mov    -0x48(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <ungetc@plt>
jmp    11d8 <_xdg_mime_magic_read_a_number+0x98>
mov    -0x48(%rbp),%eax
mov    %al,%cl
movslq -0x44(%rbp),%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x1e,-0x44(%rbp)
jne    11d3 <_xdg_mime_magic_read_a_number+0x93>
jmp    11d8 <_xdg_mime_magic_read_a_number+0x98>
jmp    115f <_xdg_mime_magic_read_a_number+0x1f>
cmpl   $0x0,-0x44(%rbp)
jle    1259 <_xdg_mime_magic_read_a_number+0x119>
movslq -0x44(%rbp),%rax
movb   $0x0,-0x40(%rbp,%rax,1)
mov    0x2dd6(%rip),%rax
movq   $0x0,(%rax)
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    0x2dbe(%rip),%rcx
cmp    (%rcx),%rax
jl     1248 <_xdg_mime_magic_read_a_number+0x108>
mov    -0x50(%rbp),%rax
mov    0x2dba(%rip),%rcx
cmp    (%rcx),%rax
jg     1248 <_xdg_mime_magic_read_a_number+0x108>
mov    0x2d8a(%rip),%rax
cmpq   $0x0,(%rax)
je     1254 <_xdg_mime_magic_read_a_number+0x114>
movl   $0xffffffff,-0x4(%rbp)
jmp    1260 <_xdg_mime_magic_read_a_number+0x120>
jmp    1259 <_xdg_mime_magic_read_a_number+0x119>
mov    -0x50(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_xdg_mime_magic_read_a_number>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
mov    0x2e96(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1050 <getc@plt>
cmp    (%r12),%eax
je     117c <_xdg_mime_magic_read_a_number+0x4c>
mov    %eax,%ecx
add    $0xffffffd0,%ecx
cmp    $0xa,%ecx
jae    11d2 <_xdg_mime_magic_read_a_number+0xa2>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x1e,%rbx
jne    1150 <_xdg_mime_magic_read_a_number+0x20>
mov    $0x1e,%ebx
jmp    1187 <_xdg_mime_magic_read_a_number+0x57>
movl   $0x1,(%r14)
test   %ebx,%ebx
je     11e0 <_xdg_mime_magic_read_a_number+0xb0>
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
mov    0x2e34(%rip),%rbx
movq   $0x0,(%rbx)
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,%rcx
mov    0x2e24(%rip),%rdx
mov    $0xffffffff,%eax
cmp    (%rdx),%rcx
jl     11e9 <_xdg_mime_magic_read_a_number+0xb9>
mov    0x2e23(%rip),%rdx
cmp    (%rdx),%rcx
jg     11e9 <_xdg_mime_magic_read_a_number+0xb9>
cmpq   $0x0,(%rbx)
je     11e7 <_xdg_mime_magic_read_a_number+0xb7>
jmp    11e9 <_xdg_mime_magic_read_a_number+0xb9>
mov    %eax,%edi
mov    %r15,%rsi
call   1040 <ungetc@plt>
test   %ebx,%ebx
jne    1187 <_xdg_mime_magic_read_a_number+0x57>
mov    $0xffffffffffffffff,%rcx
mov    %ecx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
@errno = global i64 0
@INT_MIN = global i64 0
@INT_MAX = global i64 0
define i32 @_xdg_mime_magic_read_a_number(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [31 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 0, i32* %7
store i64 -1, i64* %9
br label %10
10: ; preds = %2, %37
%11 = load i32*, i32** %4
%12 = call i32 @getc(i32* %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = load i32, i32* @EOF
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = load i32*, i32** %5
store i32 1, i32* %17
br label %38
18: ; preds = %10
%19 = load i32, i32* %8
%20 = call i32 @isdigit(i32 %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i32, i32* %8
%24 = load i32*, i32** %4
%25 = call i32 @ungetc(i32 %23, i32* %24)
br label %38
26: ; preds = %18
%27 = load i32, i32* %8
%28 = trunc i32 %27 to i8
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [31 x i8], [31 x i8]* %6, i64 0, i64 %30
store i8 %28, i8* %31
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = icmp eq i32 %34, 30
br i1 %35, label %36, label %37
36: ; preds = %26
br label %38
37: ; preds = %26
br label %10
38: ; preds = %36, %22, %16
%39 = load i32, i32* %7
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %59
41: ; preds = %38
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [31 x i8], [31 x i8]* %6, i64 0, i64 %43
store i8 0, i8* %44
store i64 0, i64* @errno
%45 = getelementptr inbounds [31 x i8], [31 x i8]* %6, i64 0, i64 0
%46 = call i64 @strtol(i8* %45, i32* null, i32 10)
store i64 %46, i64* %9
%47 = load i64, i64* %9
%48 = load i64, i64* @INT_MIN
%49 = icmp slt i64 %47, %48
br i1 %49, label %57, label %50
50: ; preds = %41
%51 = load i64, i64* %9
%52 = load i64, i64* @INT_MAX
%53 = icmp sgt i64 %51, %52
br i1 %53, label %57, label %54
54: ; preds = %50
%55 = load i64, i64* @errno
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %54, %50, %41
store i32 -1, i32* %3
br label %62
58: ; preds = %54
br label %59
59: ; preds = %58, %38
%60 = load i64, i64* %9
%61 = trunc i64 %60 to i32
store i32 %61, i32* %3
br label %62
62: ; preds = %59, %57
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@EOF = global i32 0
@errno = global i64 0
@INT_MIN = global i64 0
@INT_MAX = global i64 0
define i32 @_xdg_mime_magic_read_a_number(i32* nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca [31 x i8]
%4 = getelementptr inbounds [31 x i8], [31 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %16, %2
%6 = phi i64 [ %19, %16 ], [ 0, %2 ]
%7 = tail call i32 @getc(i32* %0)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %11
10: ; preds = %5
store i32 1, i32* %1
br label %21
11: ; preds = %5
%12 = add i32 %7, -48
%13 = icmp ult i32 %12, 10
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i32 @ungetc(i32 %7, i32* %0)
br label %21
16: ; preds = %11
%17 = trunc i32 %7 to i8
%18 = getelementptr inbounds [31 x i8], [31 x i8]* %3, i64 0, i64 %6
store i8 %17, i8* %18
%19 = add nuw nsw i64 %6, 1
%20 = icmp eq i64 %19, 30
br i1 %20, label %24, label %5
21: ; preds = %14, %10
%22 = trunc i64 %6 to i32
%23 = icmp eq i32 %22, 0
br i1 %23, label %37, label %24
24: ; preds = %16, %21
%25 = phi i64 [ %6, %21 ], [ 30, %16 ]
%26 = and i64 %25, 4294967295
%27 = getelementptr inbounds [31 x i8], [31 x i8]* %3, i64 0, i64 %26
store i8 0, i8* %27
store i64 0, i64* @errno
%28 = call i64 @strtol(i8* nocapture %4, i32* null, i32 10)
%29 = load i64, i64* @INT_MIN
%30 = icmp slt i64 %28, %29
br i1 %30, label %40, label %31
31: ; preds = %24
%32 = load i64, i64* @INT_MAX
%33 = icmp sgt i64 %28, %32
%34 = load i64, i64* @errno
%35 = icmp ne i64 %34, 0
%36 = select i1 %33, i1 true, i1 %35
br i1 %36, label %40, label %37
37: ; preds = %31, %21
%38 = phi i64 [ %28, %31 ], [ -1, %21 ]
%39 = trunc i64 %38 to i32
br label %40
40: ; preds = %24, %31, %37
%41 = phi i32 [ %39, %37 ], [ -1, %31 ], [ -1, %24 ]
ret i32 %41
}