#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 */
scalar_t__ errno;
int /*<<< orphan*/ send_status(int /*<<< orphan*/ *, int, char *);
char *strerror(scalar_t__);
char *strtok_r(int /*<<< orphan*/ *, char *, char **);
long strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int exec_next(FILE *fout, char **sptr, int *ni) {
  char *s;
  long n;
  if ((s = strtok_r(NULL, " ", sptr)) == NULL) {
    *ni = 0;
    return 0;
  }
  errno = 0;
  n = strtol(s, NULL, 0);
  if (errno) {
    send_status(fout, 400, strerror(errno));
    return -1;
  }
  if (n < -128 || n > 127) {
    send_status(fout, 400, "-128 <= n <= 127");
    return -1;
  }
  *ni = n;
  return 0;
}


x86 assembly (clang, -O0):
<exec_next>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
lea    0xe9d(%rip),%rsi
call   1040 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    118c <exec_next+0x4c>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    123c <exec_next+0xfc>
mov    0x2e4d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,-0x30(%rbp)
mov    0x2e2c(%rip),%rax
cmpq   $0x0,(%rax)
je     11f2 <exec_next+0xb2>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rdx
mov    $0x190,%esi
call   1030 <send_status@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123c <exec_next+0xfc>
cmpq   $0xffffffffffffff80,-0x30(%rbp)
jl     1208 <exec_next+0xc8>
cmpq   $0x7f,-0x30(%rbp)
jle    1229 <exec_next+0xe9>
mov    -0x10(%rbp),%rdi
mov    $0x190,%esi
lea    0xdea(%rip),%rdx
call   1030 <send_status@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123c <exec_next+0xfc>
mov    -0x30(%rbp),%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_next>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rdx
mov    %rdi,%r14
lea    0xeab(%rip),%rsi
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <strtok_r@plt>
test   %rax,%rax
je     1197 <exec_next+0x57>
mov    0x2e76(%rip),%rbx
movq   $0x0,(%rbx)
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    (%rbx),%rdi
test   %rdi,%rdi
je     11a0 <exec_next+0x60>
call   1060 <strerror@plt>
mov    %r14,%rdi
mov    $0x190,%esi
mov    %rax,%rdx
jmp    11b8 <exec_next+0x78>
movl   $0x0,(%r15)
jmp    11c9 <exec_next+0x89>
movsbq %al,%rcx
cmp    %rax,%rcx
je     11c4 <exec_next+0x84>
lea    0xe52(%rip),%rdx
mov    %r14,%rdi
mov    $0x190,%esi
call   1030 <send_status@plt>
mov    $0xffffffff,%ebx
jmp    11c9 <exec_next+0x89>
mov    %eax,(%r15)
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@errno = global i64 0
@.str.1 = [17 x i8] c"-128 <= n <= 127\00"
define i32 @exec_next(i32* %0, i8** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
store i32* %0, i32** %5
store i8** %1, i8*** %6
store i32* %2, i32** %7
%10 = load i8**, i8*** %6
%11 = call i8* @strtok_r(i32* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %10)
store i8* %11, i8** %8
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load i32*, i32** %7
store i32 0, i32* %14
store i32 0, i32* %4
br label %38
15: ; preds = %3
store i64 0, i64* @errno
%16 = load i8*, i8** %8
%17 = call i64 @strtol(i8* %16, i32* null, i32 0)
store i64 %17, i64* %9
%18 = load i64, i64* @errno
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i32*, i32** %5
%22 = load i64, i64* @errno
%23 = call i8* @strerror(i64 %22)
%24 = call i32 @send_status(i32* %21, i32 400, i8* %23)
store i32 -1, i32* %4
br label %38
25: ; preds = %15
%26 = load i64, i64* %9
%27 = icmp slt i64 %26, -128
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = load i64, i64* %9
%30 = icmp sgt i64 %29, 127
br i1 %30, label %31, label %34
31: ; preds = %28, %25
%32 = load i32*, i32** %5
%33 = call i32 @send_status(i32* %32, i32 400, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %38
34: ; preds = %28
%35 = load i64, i64* %9
%36 = trunc i64 %35 to i32
%37 = load i32*, i32** %7
store i32 %36, i32* %37
store i32 0, i32* %4
br label %38
38: ; preds = %34, %31, %20, %13
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@errno = global i64 0
@.str.1 = [17 x i8] c"-128 <= n <= 127\00"
define i32 @exec_next(i32* %0, i8** %1, i32* nocapture writeonly %2) {
%4 = tail call i8* @strtok_r(i32* null, 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 %6, label %7
6: ; preds = %3
store i32 0, i32* %2
br label %21
7: ; preds = %3
store i64 0, i64* @errno
%8 = tail call i64 @strtol(i8* nocapture %4, i32* null, i32 0)
%9 = load i64, i64* @errno
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %7
%12 = tail call i8* @strerror(i64 %9)
%13 = tail call i32 @send_status(i32* %0, i32 400, i8* %12)
br label %21
14: ; preds = %7
%15 = add i64 %8, -128
%16 = icmp ult i64 %15, -256
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @send_status(i32* %0, i32 400, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %21
19: ; preds = %14
%20 = trunc i64 %8 to i32
store i32 %20, i32* %2
br label %21
21: ; preds = %19, %17, %11, %6
%22 = phi i32 [ 0, %6 ], [ -1, %11 ], [ -1, %17 ], [ 0, %19 ]
ret i32 %22
}