#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 */
unsigned char fgetc(int /*<<< orphan*/ *);
int readval(FILE *f) {
  int x = 0;
  unsigned char c;
  while (-1) {
    c = fgetc(f);
    if (c > '9' || c < '0')
      break;
    x *= 10;
    x += (c - '0');
  }
  if (c == '"' || c == ',' || c == ']') {
    return x;
  } else
    return -1;
}


x86 assembly (clang, -O0):
<readval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x15(%rbp)
movzbl -0x15(%rbp),%eax
cmp    $0x39,%eax
jg     1149 <readval+0x39>
movzbl -0x15(%rbp),%eax
cmp    $0x30,%eax
jge    114e <readval+0x3e>
jmp    1167 <readval+0x57>
imul   $0xa,-0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
movzbl -0x15(%rbp),%eax
sub    $0x30,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1123 <readval+0x13>
movzbl -0x15(%rbp),%eax
cmp    $0x22,%eax
je     118e <readval+0x7e>
movzbl -0x15(%rbp),%eax
cmp    $0x2c,%eax
je     118e <readval+0x7e>
movzbl -0x15(%rbp),%eax
cmp    $0x5d,%eax
jne    1199 <readval+0x89>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a0 <readval+0x90>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readval>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <fgetc@plt>
mov    %eax,%ecx
add    $0xc6,%cl
xor    %ebx,%ebx
cmp    $0xf6,%cl
jb     114e <readval+0x3e>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl %al,%eax
lea    (%rbx,%rbx,4),%ecx
lea    (%rax,%rcx,2),%ebx
add    $0xffffffd0,%ebx
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ecx
add    $0xc6,%cl
cmp    $0xf5,%cl
ja     1130 <readval+0x20>
add    $0xde,%al
cmp    $0x3b,%al
ja     1167 <readval+0x57>
movzbl %al,%eax
movabs $0x800000000000401,%rcx
bt     %rax,%rcx
jb     116c <readval+0x5c>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @readval(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8
store i32* %0, i32** %3
store i32 0, i32* %4
br label %6
6: ; preds = %1, %17
%7 = load i32*, i32** %3
%8 = call zeroext i8 @fgetc(i32* %7)
store i8 %8, i8* %5
%9 = load i8, i8* %5
%10 = zext i8 %9 to i32
%11 = icmp sgt i32 %10, 57
br i1 %11, label %16, label %12
12: ; preds = %6
%13 = load i8, i8* %5
%14 = zext i8 %13 to i32
%15 = icmp slt i32 %14, 48
br i1 %15, label %16, label %17
16: ; preds = %12, %6
br label %25
17: ; preds = %12
%18 = load i32, i32* %4
%19 = mul nsw i32 %18, 10
store i32 %19, i32* %4
%20 = load i8, i8* %5
%21 = zext i8 %20 to i32
%22 = sub nsw i32 %21, 48
%23 = load i32, i32* %4
%24 = add nsw i32 %23, %22
store i32 %24, i32* %4
br label %6
25: ; preds = %16
%26 = load i8, i8* %5
%27 = zext i8 %26 to i32
%28 = icmp eq i32 %27, 34
br i1 %28, label %37, label %29
29: ; preds = %25
%30 = load i8, i8* %5
%31 = zext i8 %30 to i32
%32 = icmp eq i32 %31, 44
br i1 %32, label %37, label %33
33: ; preds = %29
%34 = load i8, i8* %5
%35 = zext i8 %34 to i32
%36 = icmp eq i32 %35, 93
br i1 %36, label %37, label %39
37: ; preds = %33, %29, %25
%38 = load i32, i32* %4
store i32 %38, i32* %2
br label %40
39: ; preds = %33
store i32 -1, i32* %2
br label %40
40: ; preds = %39, %37
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
define i32 @readval(i32* nocapture %0) {
%2 = tail call zeroext i8 @fgetc(i32* %0)
%3 = add i8 %2, -58
%4 = icmp ult i8 %3, -10
br i1 %4, label %15, label %5
5: ; preds = %1, %5
%6 = phi i8 [ %12, %5 ], [ %2, %1 ]
%7 = phi i32 [ %11, %5 ], [ 0, %1 ]
%8 = zext i8 %6 to i32
%9 = mul nsw i32 %7, 10
%10 = add i32 %9, -48
%11 = add i32 %10, %8
%12 = tail call zeroext i8 @fgetc(i32* %0)
%13 = add i8 %12, -58
%14 = icmp ult i8 %13, -10
br i1 %14, label %15, label %5
15: ; preds = %5, %1
%16 = phi i32 [ 0, %1 ], [ %11, %5 ]
%17 = phi i8 [ %2, %1 ], [ %12, %5 ]
switch i8 %17, label %18 [
i8 93, label %19
i8 44, label %19
i8 34, label %19
]
18: ; preds = %15
br label %19
19: ; preds = %15, %15, %15, %18
%20 = phi i32 [ -1, %18 ], [ %16, %15 ], [ %16, %15 ], [ %16, %15 ]
ret i32 %20
}