#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 /*<<< orphan*/ error(char *);
char *strtok_r(char *, char *, char **);
int strtol(char *, char **, int);
int tok_int(char *line, char **lasts) {
  char *field = strtok_r(line, " ", lasts);
  if (field != NULL) {
    char *endptr;
    int i = strtol(field, &endptr, 10);
    if (*endptr == '\0')
      return i;
  }
  error("expected an integer\n");
  return 0;
}


x86 assembly (clang, -O0):
<tok_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xeb1(%rip),%rsi
call   1030 <strtok_r@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1198 <tok_int+0x68>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1193 <tok_int+0x63>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <tok_int+0x7b>
jmp    1198 <tok_int+0x68>
lea    0xe63(%rip),%rdi
call   1050 <error@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tok_int>:
push   %rax
mov    %rsi,%rdx
lea    0xec5(%rip),%rsi
call   1030 <strtok_r@plt>
test   %rax,%rax
je     115e <tok_int+0x2e>
mov    %rsp,%rsi
mov    %rax,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
je     116c <tok_int+0x3c>
lea    0xe9d(%rip),%rdi
call   1050 <error@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [21 x i8] c"expected an integer\0A\00"
define i32 @tok_int(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
%9 = load i8*, i8** %4
%10 = load i8**, i8*** %5
%11 = call i8* @strtok_r(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %24
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = call i32 @strtol(i8* %15, i8** %7, i32 10)
store i32 %16, i32* %8
%17 = load i8*, i8** %7
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = load i32, i32* %8
store i32 %22, i32* %3
br label %26
23: ; preds = %14
br label %24
24: ; preds = %23, %2
%25 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %26
26: ; preds = %24, %21
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [21 x i8] c"expected an integer\0A\00"
define i32 @tok_int(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = tail call i8* @strtok_r(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = bitcast i8** %3 to i8*
%8 = call i32 @strtol(i8* %4, i8** %3, i32 10)
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %6, %2
%13 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %6, %12
%15 = phi i32 [ 0, %12 ], [ %8, %6 ]
ret i32 %15
}