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


x86 assembly (clang, -O0):
<getChunkSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
lea    0xea7(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x18(%rbp),%rdi
mov    %rax,%rdx
lea    0xe94(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1189 <getChunkSize+0x59>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1143 <getChunkSize+0x13>
lea    0xe70(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e15(%rip),%rax
mov    (%rax),%rax
mov    0x2e03(%rip),%rcx
cmp    (%rcx),%rax
je     11f0 <getChunkSize+0xc0>
mov    0x2dfb(%rip),%rax
mov    (%rax),%rax
mov    0x2e01(%rip),%rcx
cmp    (%rcx),%rax
jne    11f7 <getChunkSize+0xc7>
movl   $0xffffffff,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getChunkSize>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
movabs $0x400000000,%r12
lea    0xec3(%rip),%r15
movabs $0x100000000,%r13
mov    %rdi,%rbx
nopw   0x0(%rax,%rax,1)
add    %r13,%r12
mov    $0x5,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strncmp@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1150 <getChunkSize+0x30>
sar    $0x20,%r12
add    %r12,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    0x2e4f(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e55(%rip),%rdx
cmp    (%rdx),%rcx
mov    0x2e33(%rip),%rdx
mov    $0xffffffff,%esi
cmove  %esi,%eax
cmp    (%rdx),%rcx
cmove  %esi,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"SIZE \00"
@errno = global i64 0
@EINVAL = global i64 0
@ERANGE = global i64 0
define i32 @getChunkSize(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
br label %5
5: ; preds = %13, %1
%6 = load i8*, i8** %2
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = call i64 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %5
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
store i32 %15, i32* %4
br label %5
16: ; preds = %5
%17 = call i64 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = add nsw i64 %19, %17
%21 = trunc i64 %20 to i32
store i32 %21, i32* %4
%22 = load i8*, i8** %2
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = call i32 @strtol(i8* %25, i32 0, i32 10)
store i32 %26, i32* %3
%27 = load i64, i64* @errno
%28 = load i64, i64* @EINVAL
%29 = icmp eq i64 %27, %28
br i1 %29, label %34, label %30
30: ; preds = %16
%31 = load i64, i64* @errno
%32 = load i64, i64* @ERANGE
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %30, %16
store i32 -1, i32* %3
br label %35
35: ; preds = %34, %30
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [6 x i8] c"SIZE \00"
@errno = global i64 0
@EINVAL = global i64 0
@ERANGE = global i64 0
define i32 @getChunkSize(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ %7, %2 ], [ 0, %1 ]
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = tail call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 5)
%6 = icmp eq i64 %5, 0
%7 = add nuw i64 %3, 1
br i1 %6, label %8, label %2
8: ; preds = %2
%9 = shl i64 %3, 32
%10 = add i64 %9, 21474836480
%11 = ashr exact i64 %10, 32
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = tail call i32 @strtol(i8* %12, i32 0, i32 10)
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINVAL
%16 = icmp eq i64 %14, %15
%17 = load i64, i64* @ERANGE
%18 = icmp eq i64 %14, %17
%19 = select i1 %16, i1 true, i1 %18
%20 = select i1 %19, i32 -1, i32 %13
ret i32 %20
}