#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*/ sscanf(char *, char *, unsigned long long *);
int strcspn(char *, char *);
char *strstr(char *, char *);
int read_a_long_long_value_squid(char *buf, char *key, unsigned long long *ret,
                                 int type) {
  int k;
  char *tmp;
  if ((tmp = strstr(buf, key)) != NULL) {
    if (type == 0) {
      tmp = buf;
    }
    k = strcspn(tmp, "0123456789-");
    sscanf(tmp + k, "%lld", ret);
    if (*ret > 2147483647) {
      *ret += 2147483647;
    }
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<read_a_long_long_value_squid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11d0 <read_a_long_long_value_squid+0xa0>
cmpl   $0x0,-0x24(%rbp)
jne    1174 <read_a_long_long_value_squid+0x44>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1030 <strcspn@plt>
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rdx
lea    0xe6f(%rip),%rsi
call   1040 <sscanf@plt>
mov    -0x20(%rbp),%rax
cmpq   $0x7fffffff,(%rax)
jbe    11c4 <read_a_long_long_value_squid+0x94>
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
add    $0x7fffffff,%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11d7 <read_a_long_long_value_squid+0xa7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_a_long_long_value_squid>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rdi,%rbp
call   1050 <strstr@plt>
test   %rax,%rax
je     1195 <read_a_long_long_value_squid+0x65>
mov    %rax,%rbx
test   %r15d,%r15d
cmove  %rbp,%rbx
lea    0xea5(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcspn@plt>
movslq %eax,%rdi
add    %rbx,%rdi
lea    0xe9c(%rip),%rsi
mov    %r14,%rdx
call   1040 <sscanf@plt>
mov    (%r14),%rcx
mov    $0x1,%eax
test   $0xffffffff80000000,%rcx
je     1197 <read_a_long_long_value_squid+0x67>
add    $0x7fffffff,%rcx
mov    %rcx,(%r14)
jmp    1197 <read_a_long_long_value_squid+0x67>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"0123456789-\00"
@.str.1 = [5 x i8] c"%lld\00"
define i32 @read_a_long_long_value_squid(i8* %0, i8* %1, i64* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i64* %2, i64** %8
store i32 %3, i32* %9
%12 = load i8*, i8** %6
%13 = load i8*, i8** %7
%14 = call i8* @strstr(i8* %12, i8* %13)
store i8* %14, i8** %11
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %38
16: ; preds = %4
%17 = load i32, i32* %9
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = load i8*, i8** %6
store i8* %20, i8** %11
br label %21
21: ; preds = %19, %16
%22 = load i8*, i8** %11
%23 = call i32 @strcspn(i8* %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 %23, i32* %10
%24 = load i8*, i8** %11
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i64*, i64** %8
%29 = call i32 @sscanf(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %28)
%30 = load i64*, i64** %8
%31 = load i64, i64* %30
%32 = icmp ugt i64 %31, 2147483647
br i1 %32, label %33, label %37
33: ; preds = %21
%34 = load i64*, i64** %8
%35 = load i64, i64* %34
%36 = add i64 %35, 2147483647
store i64 %36, i64* %34
br label %37
37: ; preds = %33, %21
store i32 1, i32* %5
br label %39
38: ; preds = %4
store i32 0, i32* %5
br label %39
39: ; preds = %38, %37
%40 = load i32, i32* %5
ret i32 %40
}

LLVM IR (-O2):
@.str = [12 x i8] c"0123456789-\00"
@.str.1 = [5 x i8] c"%lld\00"
define i32 @read_a_long_long_value_squid(i8* %0, i8* nocapture %1, i64* %2, i32 %3) {
%5 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %18, label %7
7: ; preds = %4
%8 = icmp eq i32 %3, 0
%9 = select i1 %8, i8* %0, i8* %5
%10 = tail call i32 @strcspn(i8* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = tail call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%14 = load i64, i64* %2
%15 = icmp ugt i64 %14, 2147483647
br i1 %15, label %16, label %18
16: ; preds = %7
%17 = add i64 %14, 2147483647
store i64 %17, i64* %2
br label %18
18: ; preds = %4, %7, %16
%19 = phi i32 [ 1, %16 ], [ 1, %7 ], [ 0, %4 ]
ret i32 %19
}