#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 */
long INT_MAX;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
long strtol(char const *, char **, int);
const char *parse_syscall(const char *buf, int *number) {
  char *end;
  long x;
  errno = 0;
  x = strtol(buf, &end, 10);
  if (errno) {
    fprintf(stderr, "strtol(%s): %s\n", buf, strerror(errno));
    return NULL;
  } else if (end == buf) {
    fprintf(stderr, "strtol(%s): no digits found\n", buf);
    return NULL;
  } else if (x < 0 || x > INT_MAX) {
    fprintf(stderr, "strtol(%s): bad syscall number: %ld\n", buf, x);
    return NULL;
  }
  if (*end != '\t') {
    fprintf(stderr, "bad input: %s (expected <num>\t<name>)\n", buf);
    return NULL;
  }
  *number = x;
  return ++end;
}


x86 assembly (clang, -O0):
<parse_syscall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e89(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e65(%rip),%rax
cmpq   $0x0,(%rax)
je     11bd <parse_syscall+0x8d>
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    129c <parse_syscall+0x16c>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11f3 <parse_syscall+0xc3>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    129c <parse_syscall+0x16c>
cmpq   $0x0,-0x28(%rbp)
jl     1212 <parse_syscall+0xe2>
mov    -0x28(%rbp),%rax
mov    0x2ddf(%rip),%rcx
cmp    (%rcx),%rax
jle    123e <parse_syscall+0x10e>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    129c <parse_syscall+0x16c>
jmp    1243 <parse_syscall+0x113>
jmp    1248 <parse_syscall+0x118>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
je     1280 <parse_syscall+0x150>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    129c <parse_syscall+0x16c>
mov    -0x28(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_syscall>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2e8c(%rip),%rbp
movq   $0x0,0x0(%rbp)
mov    %rsp,%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    0x0(%rbp),%rdi
test   %rdi,%rdi
je     118b <parse_syscall+0x5b>
mov    0x2e6f(%rip),%rax
mov    (%rax),%ebp
call   1050 <strerror@plt>
lea    0xe89(%rip),%rsi
xor    %r14d,%r14d
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11f8 <parse_syscall+0xc8>
mov    (%rsp),%r14
cmp    %rbx,%r14
je     11b4 <parse_syscall+0x84>
test   %rax,%rax
js     11c6 <parse_syscall+0x96>
mov    0x2e48(%rip),%rcx
cmp    (%rcx),%rax
jg     11c6 <parse_syscall+0x96>
cmpb   $0x9,(%r14)
jne    11db <parse_syscall+0xab>
mov    %eax,(%r15)
add    $0x1,%r14
jmp    11f8 <parse_syscall+0xc8>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
jmp    11eb <parse_syscall+0xbb>
mov    0x2e0b(%rip),%rcx
mov    (%rcx),%edi
lea    0xe57(%rip),%rsi
xor    %r14d,%r14d
jmp    117c <parse_syscall+0x4c>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
xor    %r14d,%r14d
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [16 x i8] c"strtol(%s): %s\0A\00"
@.str.1 = [29 x i8] c"strtol(%s): no digits found\0A\00"
@INT_MAX = global i64 0
@.str.2 = [37 x i8] c"strtol(%s): bad syscall number: %ld\0A\00"
@.str.3 = [39 x i8] c"bad input: %s (expected <num>\09<name>)\0A\00"
define i8* @parse_syscall(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %4
store i32* %1, i32** %5
store i64 0, i64* @errno
%8 = load i8*, i8** %4
%9 = call i64 @strtol(i8* %8, i8** %6, i32 10)
store i64 %9, i64* %7
%10 = load i64, i64* @errno
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %4
%15 = load i64, i64* @errno
%16 = call i8* @strerror(i64 %15)
%17 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %16)
store i8* null, i8** %3
br label %55
18: ; preds = %2
%19 = load i8*, i8** %6
%20 = load i8*, i8** %4
%21 = icmp eq i8* %19, %20
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %4
%25 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %24)
store i8* null, i8** %3
br label %55
26: ; preds = %18
%27 = load i64, i64* %7
%28 = icmp slt i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = load i64, i64* %7
%31 = load i64, i64* @INT_MAX
%32 = icmp sgt i64 %30, %31
br i1 %32, label %33, label %38
33: ; preds = %29, %26
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %4
%36 = load i64, i64* %7
%37 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %35, i64 %36)
store i8* null, i8** %3
br label %55
38: ; preds = %29
br label %39
39: ; preds = %38
br label %40
40: ; preds = %39
%41 = load i8*, i8** %6
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 9
br i1 %44, label %45, label %49
45: ; preds = %40
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %4
%48 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %47)
store i8* null, i8** %3
br label %55
49: ; preds = %40
%50 = load i64, i64* %7
%51 = trunc i64 %50 to i32
%52 = load i32*, i32** %5
store i32 %51, i32* %52
%53 = load i8*, i8** %6
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %6
store i8* %54, i8** %3
br label %55
55: ; preds = %49, %45, %33, %22, %12
%56 = load i8*, i8** %3
ret i8* %56
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [16 x i8] c"strtol(%s): %s\0A\00"
@.str.1 = [29 x i8] c"strtol(%s): no digits found\0A\00"
@INT_MAX = global i64 0
@.str.2 = [37 x i8] c"strtol(%s): bad syscall number: %ld\0A\00"
@.str.3 = [39 x i8] c"bad input: %s (expected <num>\09<name>)\0A\00"
define i8* @parse_syscall(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%5 = call i64 @strtol(i8* %0, i8** %3, i32 10)
%6 = load i64, i64* @errno
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i8* @strerror(i64 %6)
%11 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %10)
br label %35
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = icmp eq i8* %13, %0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %35
18: ; preds = %12
%19 = icmp slt i64 %5, 0
%20 = load i64, i64* @INT_MAX
%21 = icmp sgt i64 %5, %20
%22 = select i1 %19, i1 true, i1 %21
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %0, i64 %5)
br label %35
26: ; preds = %18
%27 = load i8, i8* %13
%28 = icmp eq i8 %27, 9
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %35
32: ; preds = %26
%33 = trunc i64 %5 to i32
store i32 %33, i32* %1
%34 = getelementptr inbounds i8, i8* %13, i64 1
br label %35
35: ; preds = %32, %29, %23, %15, %8
%36 = phi i8* [ null, %8 ], [ null, %15 ], [ null, %23 ], [ null, %29 ], [ %34, %32 ]
ret i8* %36
}