#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 */
scalar_t__ EINVAL;
scalar_t__ ERANGE;
scalar_t__ errno;
int strlen(char *);
int strtol(char *, int /*<<< orphan*/, int);
int getChunkPosition(char *buffer) {
  int toRet;
  toRet = strtol(buffer + strlen("POS "), 0, 10);
  if (errno == EINVAL || errno == ERANGE) {
    toRet = -1;
  }
  return toRet;
}


x86 assembly (clang, -O0):
<getChunkPosition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xec5(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x18(%rbp),%rdi
cltq
add    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%rax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
je     118c <getChunkPosition+0x6c>
mov    0x2e5f(%rip),%rax
mov    (%rax),%rax
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%rax
jne    1193 <getChunkPosition+0x73>
movl   $0xffffffff,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getChunkPosition>:
push   %rbx
mov    %rdi,%rbx
lea    0xed5(%rip),%rdi
call   1030 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    0x2e8f(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e95(%rip),%rdx
cmp    (%rdx),%rcx
mov    0x2e73(%rip),%rdx
mov    $0xffffffff,%esi
cmove  %esi,%eax
cmp    (%rdx),%rcx
cmove  %esi,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"POS \00"
@errno = global i64 0
@EINVAL = global i64 0
@ERANGE = global i64 0
define i32 @getChunkPosition(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %4, i64 %6
%8 = call i32 @strtol(i8* %7, i32 0, i32 10)
store i32 %8, i32* %3
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINVAL
%11 = icmp eq i64 %9, %10
br i1 %11, label %16, label %12
12: ; preds = %1
%13 = load i64, i64* @errno
%14 = load i64, i64* @ERANGE
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %12, %1
store i32 -1, i32* %3
br label %17
17: ; preds = %16, %12
%18 = load i32, i32* %3
ret i32 %18
}

LLVM IR (-O2):
@.str = [5 x i8] c"POS \00"
@errno = global i64 0
@EINVAL = global i64 0
@ERANGE = global i64 0
define i32 @getChunkPosition(i8* %0) {
%2 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = tail call i32 @strtol(i8* %4, i32 0, i32 10)
%6 = load i64, i64* @errno
%7 = load i64, i64* @EINVAL
%8 = icmp eq i64 %6, %7
%9 = load i64, i64* @ERANGE
%10 = icmp eq i64 %6, %9
%11 = select i1 %8, i1 true, i1 %10
%12 = select i1 %11, i32 -1, i32 %5
ret i32 %12
}