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


x86 assembly (clang, -O0):
<read_swift_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     11a4 <read_swift_value+0x74>
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    0xe70(%rip),%rsi
call   1040 <sscanf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ab <read_swift_value+0x7b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_swift_value>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
call   1050 <strstr@plt>
test   %rax,%rax
je     1173 <read_swift_value+0x43>
mov    %rax,%rbx
lea    0xeb5(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcspn@plt>
cltq
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
lea    0xe9f(%rip),%rsi
mov    %r14,%rdx
call   1040 <sscanf@plt>
mov    $0x1,%eax
jmp    1175 <read_swift_value+0x45>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c":=\00"
@.str.1 = [5 x i8] c"%lld\00"
define i32 @read_swift_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 %24
14: ; preds = %3
%15 = load i8*, i8** %9
%16 = call i32 @strcspn(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 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)
store i32 1, i32* %4
br label %25
24: ; preds = %3
store i32 0, i32* %4
br label %25
25: ; preds = %24, %14
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
@.str = [3 x i8] c":=\00"
@.str.1 = [5 x i8] c"%lld\00"
define i32 @read_swift_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 %12, label %6
6: ; preds = %3
%7 = tail call i32 @strcspn(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 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)
br label %12
12: ; preds = %3, %6
%13 = phi i32 [ 1, %6 ], [ 0, %3 ]
ret i32 %13
}