#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 */
struct mtl_buffer {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int CHAR_BIT;
int strtol(char *, char **, int);
scalar_t__ wf_next_token(char *, int, int /*<<< orphan*/ *);
int parse_int(void *field, struct mtl_buffer *buffer, FILE *fp) {
  char token[sizeof(int) * CHAR_BIT + 1], *end;
  int *p;
  (void)buffer;
  if (wf_next_token(token, sizeof token, fp) == 0) {
    return -1;
  }
  p = field;
  *p = strtol(token, &end, 10);
  if (end == token || *end != '\0') {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2ea5(%rip),%rax
movslq (%rax),%rcx
lea    0x1(,%rcx,4),%rax
mov    %rsp,%rdx
mov    %rdx,-0x28(%rbp)
lea    0x10(,%rcx,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x50(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    %eax,%esi
mov    -0x20(%rbp),%rdx
call   1030 <wf_next_token@plt>
cmp    $0x0,%rax
jne    1192 <parse_int+0x72>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    11f3 <parse_int+0xd3>
mov    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,%edx
mov    -0x50(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    %edx,(%rcx)
cmp    %rax,-0x38(%rbp)
je     11d2 <parse_int+0xb2>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e5 <parse_int+0xc5>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    11f3 <parse_int+0xd3>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2eac(%rip),%rax
movslq (%rax),%rax
lea    0x0(,%rax,4),%rsi
or     $0x1,%esi
mov    %rsp,%rbx
lea    0x10(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1030 <wf_next_token@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
je     118e <parse_int+0x6e>
lea    -0x20(%rbp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,(%r14)
mov    -0x20(%rbp),%rax
cmp    %rbx,%rax
je     118e <parse_int+0x6e>
xor    %ecx,%ecx
cmp    (%rax),%cl
sbb    %r15d,%r15d
mov    %r15d,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mtl_buffer = type { i32 }
@CHAR_BIT = global i32 0
define i32 @parse_int(i8* %0, %struct.mtl_buffer* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.mtl_buffer*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i32
store i8* %0, i8** %5
store %struct.mtl_buffer* %1, %struct.mtl_buffer** %6
store i32* %2, i32** %7
%13 = load i32, i32* @CHAR_BIT
%14 = sext i32 %13 to i64
%15 = mul i64 4, %14
%16 = add i64 %15, 1
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %8
%18 = alloca i8, i64 %16
store i64 %16, i64* %9
%19 = load %struct.mtl_buffer*, %struct.mtl_buffer** %6
%20 = trunc i64 %16 to i32
%21 = load i32*, i32** %7
%22 = call i64 @wf_next_token(i8* %18, i32 %20, i32* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %3
store i32 -1, i32* %4
store i32 1, i32* %12
br label %39
25: ; preds = %3
%26 = load i8*, i8** %5
%27 = bitcast i8* %26 to i32*
store i32* %27, i32** %11
%28 = call i32 @strtol(i8* %18, i8** %10, i32 10)
%29 = load i32*, i32** %11
store i32 %28, i32* %29
%30 = load i8*, i8** %10
%31 = icmp eq i8* %30, %18
br i1 %31, label %37, label %32
32: ; preds = %25
%33 = load i8*, i8** %10
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32, %25
store i32 -1, i32* %4
store i32 1, i32* %12
br label %39
38: ; preds = %32
store i32 0, i32* %4
store i32 1, i32* %12
br label %39
39: ; preds = %38, %37, %24
%40 = load i8*, i8** %8
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
%struct.mtl_buffer = type { i32 }
@CHAR_BIT = global i32 0
define i32 @parse_int(i8* nocapture writeonly %0, %struct.mtl_buffer* nocapture readnone %1, i32* %2) {
%4 = alloca i8*
%5 = load i32, i32* @CHAR_BIT
%6 = sext i32 %5 to i64
%7 = shl nsw i64 %6, 2
%8 = or i64 %7, 1
%9 = alloca i8, i64 %8
%10 = bitcast i8** %4 to i8*
%11 = trunc i64 %8 to i32
%12 = call i64 @wf_next_token(i8* %9, i32 %11, i32* %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %3
%15 = bitcast i8* %0 to i32*
%16 = call i32 @strtol(i8* %9, i8** %4, i32 10)
store i32 %16, i32* %15
%17 = load i8*, i8** %4
%18 = icmp eq i8* %17, %9
br i1 %18, label %23, label %19
19: ; preds = %14
%20 = load i8, i8* %17
%21 = icmp ne i8 %20, 0
%22 = sext i1 %21 to i32
br label %23
23: ; preds = %19, %14, %3
%24 = phi i32 [ -1, %3 ], [ -1, %14 ], [ %22, %19 ]
ret i32 %24
}