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


x86 assembly (clang, -O0):
<read_swift_store_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11bd <read_swift_store_value+0x8d>
mov    -0x30(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1030 <strcspn@plt>
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rdx
lea    0xe6f(%rip),%rsi
call   1040 <sscanf@plt>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jge    11b1 <read_swift_store_value+0x81>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11c4 <read_swift_store_value+0x94>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_swift_store_value>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
call   1050 <strstr@plt>
test   %rax,%rax
je     1180 <read_swift_store_value+0x50>
mov    %rax,%rbx
lea    0xeb5(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcspn@plt>
cltq
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
lea    0xe9e(%rip),%rsi
mov    %r14,%rdx
call   1040 <sscanf@plt>
mov    $0x1,%eax
cmpq   $0x0,(%r14)
jns    1182 <read_swift_store_value+0x52>
movq   $0x0,(%r14)
jmp    1182 <read_swift_store_value+0x52>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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